*/ public static function scope_keys(): array { return array( self::SCOPE_ORDERS, self::SCOPE_PRODUCTS, self::SCOPE_ATTRIBUTION, self::SCOPE_COUPONS, self::SCOPE_CUSTOM_QUERIES ); } /** * Current scopes. All are on by default, except custom queries. * * @return array */ public static function scopes(): array { $stored = get_option( self::OPTION, array() ); $stored = is_array( $stored ) && isset( $stored['scopes'] ) && is_array( $stored['scopes'] ) ? $stored['scopes'] : array(); $scopes = array(); foreach ( self::scope_keys() as $key ) { $scopes[ $key ] = array_key_exists( $key, $stored ) ? (bool) $stored[ $key ] : ! in_array( $key, self::OFF_BY_DEFAULT, true ); } return $scopes; } /** * Saves scopes. Unknown keys are ignored. * * @param array $scopes New values keyed by scope. * @return array The saved scopes. */ public static function update_scopes( array $scopes ): array { $current = self::scopes(); foreach ( self::scope_keys() as $key ) { if ( array_key_exists( $key, $scopes ) ) { $current[ $key ] = (bool) $scopes[ $key ]; } } update_option( self::OPTION, array( 'scopes' => $current ), false ); return $current; } }