Файловый менеджер - Редактировать - /home/tuudkjt/globeasy/wp-includes/ID3/Features.zip
Назад
PK ��.]��L�1 �1 Features.phpnu ��� <?php /** * Features loader for features developed in WooCommerce Admin. */ namespace Automattic\WooCommerce\Admin\Features; use Automattic\WooCommerce\Admin\PageController; use Automattic\WooCommerce\Internal\Admin\Loader; use Automattic\WooCommerce\Internal\Admin\WCAdminAssets; use Automattic\WooCommerce\Utilities\FeaturesUtil; /** * Features Class. */ class Features { /** * Class instance. * * @var Loader instance */ protected static $instance = null; /** * Optional features * * @var array */ protected static $optional_features = array( 'analytics' => array( 'default' => 'yes' ), 'remote-inbox-notifications' => array( 'default' => 'yes' ), ); /** * Beta features * * @var array */ protected static $beta_features = array( 'settings', ); /** * Get class instance. */ public static function get_instance() { if ( ! self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Constructor. */ public function __construct() { $this->register_internal_class_aliases(); if ( ! self::should_load_features() ) { return; } // Load feature before WooCommerce update hooks. add_action( 'init', array( __CLASS__, 'load_features' ), 4 ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'maybe_load_beta_features_modal' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_scripts' ), 15 ); add_filter( 'admin_body_class', array( __CLASS__, 'add_admin_body_classes' ) ); add_filter( 'update_option_woocommerce_allow_tracking', array( __CLASS__, 'maybe_disable_features' ), 10, 2 ); } /** * Gets a build configured array of enabled WooCommerce Admin features/sections, but does not respect optionally disabled features. * * @return array Enabled Woocommerce Admin features/sections. */ public static function get_features() { return apply_filters( 'woocommerce_admin_features', array() ); } /** * Gets the optional feature options as an associative array that can be toggled on or off. * * @return array */ public static function get_optional_feature_options() { $features = array(); foreach ( array_keys( self::$optional_features ) as $optional_feature_key ) { $feature_class = self::get_feature_class( $optional_feature_key ); if ( $feature_class ) { $features[ $optional_feature_key ] = $feature_class::TOGGLE_OPTION_NAME; } } return $features; } /** * Returns if a specific wc-admin feature exists in the current environment. * * @param string $feature Feature slug. * @return bool Returns true if the feature exists. */ public static function exists( $feature ) { $features = self::get_features(); return in_array( $feature, $features, true ); } /** * Get the feature class as a string. * * @param string $feature Feature name. * @return string|null */ public static function get_feature_class( $feature ) { $feature = str_replace( '-', '', ucwords( strtolower( $feature ), '-' ) ); $feature_class = 'Automattic\\WooCommerce\\Admin\\Features\\' . $feature; $should_autoload_class = self::should_load_features(); if ( class_exists( $feature_class, $should_autoload_class ) ) { return $feature_class; } // Handle features contained in subdirectory. if ( class_exists( $feature_class . '\\Init', $should_autoload_class ) ) { return $feature_class . '\\Init'; } return null; } /** * Class loader for enabled WooCommerce Admin features/sections. */ public static function load_features() { if ( ! self::should_load_features() ) { return; } $features = self::get_features(); foreach ( $features as $feature ) { $feature_class = self::get_feature_class( $feature ); if ( $feature_class ) { new $feature_class(); } } if ( FeaturesUtil::feature_is_enabled( 'blueprint' ) ) { new \Automattic\WooCommerce\Admin\Features\Blueprint\Init(); } } /** * Gets a build configured array of enabled WooCommerce Admin respecting optionally disabled features. * * @return array Enabled Woocommerce Admin features/sections. */ public static function get_available_features() { $features = self::get_features(); $optional_feature_keys = array_keys( self::$optional_features ); $optional_features_unavailable = array(); /** * Filter allowing WooCommerce Admin optional features to be disabled. * * @param bool $disabled False. */ if ( apply_filters( 'woocommerce_admin_disabled', false ) ) { return array_values( array_diff( $features, $optional_feature_keys ) ); } foreach ( $optional_feature_keys as $optional_feature_key ) { $feature_class = self::get_feature_class( $optional_feature_key ); if ( $feature_class ) { $default = isset( self::$optional_features[ $optional_feature_key ]['default'] ) ? self::$optional_features[ $optional_feature_key ]['default'] : 'no'; // Check if the feature is currently being enabled, if it is continue. /* phpcs:disable WordPress.Security.NonceVerification */ $feature_option = $feature_class::TOGGLE_OPTION_NAME; if ( isset( $_POST[ $feature_option ] ) && '1' === $_POST[ $feature_option ] ) { continue; } if ( 'yes' !== get_option( $feature_class::TOGGLE_OPTION_NAME, $default ) ) { $optional_features_unavailable[] = $optional_feature_key; } } } return array_values( array_diff( $features, $optional_features_unavailable ) ); } /** * Check if a feature is enabled. * * @param string $feature Feature slug. * @return bool */ public static function is_enabled( $feature ) { $available_features = self::get_available_features(); return in_array( $feature, $available_features, true ); } /** * Enable a toggleable optional feature. * * @param string $feature Feature name. * @return bool */ public static function enable( $feature ) { $features = self::get_optional_feature_options(); if ( isset( $features[ $feature ] ) ) { update_option( $features[ $feature ], 'yes' ); return true; } return false; } /** * Disable a toggleable optional feature. * * @param string $feature Feature name. * @return bool */ public static function disable( $feature ) { $features = self::get_optional_feature_options(); if ( isset( $features[ $feature ] ) ) { update_option( $features[ $feature ], 'no' ); return true; } return false; } /** * Disable features when opting out of tracking. * * @param string $old_value Old value. * @param string $value New value. */ public static function maybe_disable_features( $old_value, $value ) { if ( 'yes' === $value ) { return; } foreach ( self::$beta_features as $feature ) { self::disable( $feature ); } } /** * Adds the Features section to the advanced tab of WooCommerce Settings * * @deprecated 7.0 The WooCommerce Admin features are now handled by the WooCommerce features engine (see the FeaturesController class). * * @param array $sections Sections. * @return array */ public static function add_features_section( $sections ) { return $sections; } /** * Adds the Features settings. * * @deprecated 7.0 The WooCommerce Admin features are now handled by the WooCommerce features engine (see the FeaturesController class). * * @param array $settings Settings. * @param string $current_section Current section slug. * @return array */ public static function add_features_settings( $settings, $current_section ) { return $settings; } /** * Conditionally loads the beta features tracking modal. * * @param string $hook Page hook. */ public static function maybe_load_beta_features_modal( $hook ) { if ( 'woocommerce_page_wc-settings' !== $hook || ! isset( $_GET['tab'] ) || 'advanced' !== $_GET['tab'] || // phpcs:ignore CSRF ok. ! isset( $_GET['section'] ) || 'features' !== $_GET['section'] // phpcs:ignore CSRF ok. ) { return; } $tracking_enabled = get_option( 'woocommerce_allow_tracking', 'no' ); if ( empty( self::$beta_features ) ) { return; } if ( 'yes' === $tracking_enabled ) { return; } WCAdminAssets::register_style( 'beta-features-tracking-modal', 'style', array( 'wp-components' ) ); WCAdminAssets::register_script( 'wp-admin-scripts', 'beta-features-tracking-modal', array( 'wp-i18n', 'wp-element', WC_ADMIN_APP ) ); } /** * Loads the required scripts on the correct pages. */ public static function load_scripts() { if ( ! PageController::is_admin_or_embed_page() ) { return; } $features = self::get_features(); $enabled_features = array(); foreach ( $features as $key ) { $enabled_features[ $key ] = self::is_enabled( $key ); } wp_add_inline_script( WC_ADMIN_APP, 'window.wcAdminFeatures = ' . wp_json_encode( $enabled_features, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), 'before' ); } /** * Adds body classes to the main wp-admin wrapper, allowing us to better target elements in specific scenarios. * * @param string $admin_body_class Body class to add. */ public static function add_admin_body_classes( $admin_body_class = '' ) { if ( ! PageController::is_admin_or_embed_page() ) { return $admin_body_class; } $classes = explode( ' ', trim( $admin_body_class ) ); $features = self::get_features(); foreach ( $features as $feature_key ) { $classes[] = sanitize_html_class( 'woocommerce-feature-enabled-' . $feature_key ); } $admin_body_class = implode( ' ', array_unique( $classes ) ); return " $admin_body_class "; } /** * Alias internal features classes to make them backward compatible. * We've moved our feature classes to src-internal as part of merging this * repository with WooCommerce Core to form a monorepo. * See https://wp.me/p90Yrv-2HY for details. */ private function register_internal_class_aliases() { $aliases = array( // new class => original class (this will be aliased). 'Automattic\WooCommerce\Internal\Admin\WCPayPromotion\Init' => 'Automattic\WooCommerce\Admin\Features\WcPayPromotion\Init', 'Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\Init' => 'Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions\Init', 'Automattic\WooCommerce\Internal\Admin\ActivityPanels' => 'Automattic\WooCommerce\Admin\Features\ActivityPanels', 'Automattic\WooCommerce\Internal\Admin\Analytics' => 'Automattic\WooCommerce\Admin\Features\Analytics', 'Automattic\WooCommerce\Internal\Admin\Coupons' => 'Automattic\WooCommerce\Admin\Features\Coupons', 'Automattic\WooCommerce\Internal\Admin\CouponsMovedTrait' => 'Automattic\WooCommerce\Admin\Features\CouponsMovedTrait', 'Automattic\WooCommerce\Internal\Admin\CustomerEffortScoreTracks' => 'Automattic\WooCommerce\Admin\Features\CustomerEffortScoreTracks', 'Automattic\WooCommerce\Internal\Admin\Homescreen' => 'Automattic\WooCommerce\Admin\Features\Homescreen', 'Automattic\WooCommerce\Internal\Admin\Marketing' => 'Automattic\WooCommerce\Admin\Features\Marketing', 'Automattic\WooCommerce\Internal\Admin\MobileAppBanner' => 'Automattic\WooCommerce\Admin\Features\MobileAppBanner', 'Automattic\WooCommerce\Internal\Admin\RemoteInboxNotifications' => 'Automattic\WooCommerce\Admin\Features\RemoteInboxNotifications', 'Automattic\WooCommerce\Internal\Admin\ShippingLabelBanner' => 'Automattic\WooCommerce\Admin\Features\ShippingLabelBanner', 'Automattic\WooCommerce\Internal\Admin\ShippingLabelBannerDisplayRules' => 'Automattic\WooCommerce\Admin\Features\ShippingLabelBannerDisplayRules', 'Automattic\WooCommerce\Internal\Admin\WcPayWelcomePage' => 'Automattic\WooCommerce\Admin\Features\WcPayWelcomePage', ); foreach ( $aliases as $new_class => $orig_class ) { class_alias( $new_class, $orig_class ); } } /** * Check if we're in an admin context where features should be loaded. * * @return boolean */ private static function should_load_features() { $should_load = ( is_admin() || wp_doing_ajax() || wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ) || ( WC()->is_rest_api_request() && ! WC()->is_store_api_request() ) || // Allow features to be loaded in frontend for admin users. This is needed for the use case such as the coming soon footer banner. current_user_can( 'manage_woocommerce' ) ); /** * Filter to determine if admin features should be loaded. * * @since 9.6.0 * @param boolean $should_load Whether admin features should be loaded. It defaults to true when the current request is in an admin context. */ return apply_filters( 'woocommerce_admin_should_load_features', $should_load ); } } PK ��.]'H� E MarketingRecommendations/MarketingRecommendationsDataSourcePoller.phpnu ��� <?php namespace Automattic\WooCommerce\Admin\Features\MarketingRecommendations; use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; use WC_Helper; /** * Specs data source poller class for marketing recommendations. */ class MarketingRecommendationsDataSourcePoller extends DataSourcePoller { /** * Data Source Poller ID. */ const ID = 'marketing_recommendations'; /** * Default data sources array. * * @deprecated since 9.5.0. Use get_data_sources() instead. */ const DATA_SOURCES = array(); /** * Class instance. * * @var MarketingRecommendationsDataSourcePoller instance */ protected static $instance = null; /** * Get class instance. */ public static function get_instance() { if ( ! self::$instance ) { self::$instance = new self( self::ID, self::get_data_sources(), array( 'spec_key' => 'product', ) ); } return self::$instance; } /** * Get data sources. * * @return array */ public static function get_data_sources() { return array( WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/marketing-tab/1.3/recommendations.json', ); } } PK ��.]�*�L L @ MarketingRecommendations/MiscRecommendationsDataSourcePoller.phpnu ��� <?php declare(strict_types=1); namespace Automattic\WooCommerce\Admin\Features\MarketingRecommendations; use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; use WC_Helper; /** * Specs data source poller class for misc recommendations. * * The misc recommendations are fetched from the WooCommerce.com API, the data structure looks like this: * * [ * { * "id": "woocommerce-analytics", * "order_attribution_promotion_percentage": [ * [ "9.7", 100 ], * [ "9.6", 60 ], * [ "9.5", 10 ] * ] * } * ] * * @since 9.5.0 */ class MiscRecommendationsDataSourcePoller extends DataSourcePoller { /** * Data Source Poller ID. */ const ID = 'misc_recommendations'; /** * Class instance. * * @var MiscRecommendationsDataSourcePoller instance */ protected static $instance = null; /** * Get class instance. */ public static function get_instance() { if ( ! self::$instance ) { self::$instance = new self( self::ID, self::get_data_sources(), array( 'transient_expiry' => DAY_IN_SECONDS, ) ); } return self::$instance; } /** * Get data sources. * * @return array */ public static function get_data_sources() { return array( WC_Helper::get_woocommerce_com_base_url() . 'wp-json/wccom/marketing-tab/misc/recommendations.json', ); } } PK ��.]�oy� � ! MarketingRecommendations/Init.phpnu ��� <?php namespace Automattic\WooCommerce\Admin\Features\MarketingRecommendations; use Automattic\WooCommerce\Admin\RemoteSpecs\RemoteSpecsEngine; defined( 'ABSPATH' ) || exit; /** * Marketing Recommendations engine. * This goes through the specs and gets marketing recommendations. */ class Init extends RemoteSpecsEngine { /** * Slug of the category specifying marketing extensions on the WooCommerce.com store. * * @var string */ const MARKETING_EXTENSION_CATEGORY_SLUG = 'marketing'; /** * Slug of the subcategory specifying marketing channels on the WooCommerce.com store. * * @var string */ const MARKETING_CHANNEL_SUBCATEGORY_SLUG = 'sales-channels'; /** * Constructor. */ public function __construct() { add_action( 'woocommerce_updated', array( __CLASS__, 'delete_specs_transient' ) ); } /** * Delete the specs transient. */ public static function delete_specs_transient() { MarketingRecommendationsDataSourcePoller::get_instance()->delete_specs_transient(); MiscRecommendationsDataSourcePoller::get_instance()->delete_specs_transient(); } /** * Get specs or fetch remotely if they don't exist. */ public static function get_specs() { if ( 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) ) { return DefaultMarketingRecommendations::get_all(); } $specs = MarketingRecommendationsDataSourcePoller::get_instance()->get_specs_from_data_sources(); // Fetch specs if they don't yet exist. if ( ! is_array( $specs ) || 0 === count( $specs ) ) { return DefaultMarketingRecommendations::get_all(); } return $specs; } /** * Get misc recommendations specs or fetch remotely if they don't exist. * * @since 9.5.0 */ public static function get_misc_recommendations_specs() { if ( 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) ) { return array(); } $specs = MiscRecommendationsDataSourcePoller::get_instance()->get_specs_from_data_sources(); // Return empty specs if they don't yet exist. if ( ! is_array( $specs ) ) { return array(); } return $specs; } /** * Process specs. * * @param array|null $specs Marketing recommendations spec array. * @return array */ protected static function evaluate_specs( ?array $specs = null ) { $suggestions = array(); $errors = array(); foreach ( $specs as $spec ) { try { $suggestions[] = self::object_to_array( $spec ); } catch ( \Throwable $e ) { $errors[] = $e; } } return array( 'suggestions' => $suggestions, 'errors' => $errors, ); } /** * Load recommended plugins from WooCommerce.com * * @return array */ public static function get_recommended_plugins(): array { $specs = self::get_specs(); $results = self::evaluate_specs( $specs ); $specs_to_return = $results['suggestions']; $specs_to_save = null; if ( empty( $specs_to_return ) ) { // When suggestions is empty, replace it with defaults and save for 3 hours. $specs_to_save = DefaultMarketingRecommendations::get_all(); $specs_to_return = self::evaluate_specs( $specs_to_save )['suggestions']; } elseif ( count( $results['errors'] ) > 0 ) { // When suggestions is not empty but has errors, save it for 3 hours. $specs_to_save = $specs; } if ( $specs_to_save ) { MarketingRecommendationsDataSourcePoller::get_instance()->set_specs_transient( $specs_to_save, 3 * HOUR_IN_SECONDS ); } $errors = $results['errors']; if ( ! empty( $errors ) ) { self::log_errors( $errors ); } return $specs_to_return; } /** * Return only the recommended marketing channels from WooCommerce.com. * * @return array */ public static function get_recommended_marketing_channels(): array { return array_filter( self::get_recommended_plugins(), function ( array $plugin_data ) { return self::is_marketing_channel_plugin( $plugin_data ); } ); } /** * Return all recommended marketing extensions EXCEPT the marketing channels from WooCommerce.com. * * @return array */ public static function get_recommended_marketing_extensions_excluding_channels(): array { return array_filter( self::get_recommended_plugins(), function ( array $plugin_data ) { return self::is_marketing_plugin( $plugin_data ) && ! self::is_marketing_channel_plugin( $plugin_data ); } ); } /** * Load misc recommendations from WooCommerce.com * * @since 9.5.0 * @return array */ public static function get_misc_recommendations(): array { $specs = self::get_misc_recommendations_specs(); $results = self::evaluate_specs( $specs ); $specs_to_return = $results['suggestions']; $specs_to_save = null; if ( empty( $specs_to_return ) ) { // When misc_recommendations is empty, replace it with defaults and save for 3 hours. $specs_to_save = array(); } elseif ( count( $results['errors'] ) > 0 ) { // When misc_recommendations is not empty but has errors, save it for 3 hours. $specs_to_save = $specs; } if ( $specs_to_save ) { MiscRecommendationsDataSourcePoller::get_instance()->set_specs_transient( $specs_to_save, 3 * HOUR_IN_SECONDS ); } $errors = $results['errors']; if ( ! empty( $errors ) ) { self::log_errors( $errors ); } return $specs_to_return; } /** * Returns whether a plugin is a marketing extension. * * @param array $plugin_data The plugin properties returned by the API. * * @return bool */ protected static function is_marketing_plugin( array $plugin_data ): bool { $categories = $plugin_data['categories'] ?? array(); return in_array( self::MARKETING_EXTENSION_CATEGORY_SLUG, $categories, true ); } /** * Returns whether a plugin is a marketing channel. * * @param array $plugin_data The plugin properties returned by the API. * * @return bool */ protected static function is_marketing_channel_plugin( array $plugin_data ): bool { if ( ! self::is_marketing_plugin( $plugin_data ) ) { return false; } $subcategories = $plugin_data['subcategories'] ?? array(); foreach ( $subcategories as $subcategory ) { if ( isset( $subcategory['slug'] ) && self::MARKETING_CHANNEL_SUBCATEGORY_SLUG === $subcategory['slug'] ) { return true; } } return false; } /** * Convert an object to an array. * This is used to convert the specs to an array so that they can be returned by the API. * * @param mixed $obj Object to convert. * @param array &$visited Reference to an array keeping track of all seen objects to detect circular references. * @return array */ public static function object_to_array( $obj, &$visited = array() ) { if ( is_object( $obj ) ) { if ( in_array( $obj, $visited, true ) ) { // Circular reference detected. return null; } $visited[] = $obj; $obj = (array) $obj; } if ( is_array( $obj ) ) { $new = array(); foreach ( $obj as $key => $val ) { $new[ $key ] = self::object_to_array( $val, $visited ); } } else { $new = $obj; } return $new; } } PK ��.]-y;�A �A <