Agentic
4 months ago
BlockTemplates
4 weeks ago
EmailImprovements
1 year ago
EmailPreview
4 weeks ago
Emails
1 year ago
ImportExport
1 year ago
Logging
1 year ago
Marketing
2 years ago
Notes
4 weeks ago
Onboarding
5 months ago
Orders
4 weeks ago
ProductForm
2 years ago
ProductReviews
4 weeks ago
RemoteFreeExtensions
4 weeks ago
Schedulers
4 weeks ago
Settings
5 days ago
Suggestions
4 weeks ago
WCPayPromotion
10 months ago
ActivityPanels.php
3 years ago
Analytics.php
4 weeks ago
CategoryLookup.php
4 years ago
Coupons.php
1 year ago
CouponsMovedTrait.php
5 months ago
CustomerEffortScoreTracks.php
7 months ago
Events.php
2 months ago
FeaturePlugin.php
4 months ago
Homescreen.php
1 month ago
Loader.php
4 weeks ago
Marketing.php
1 year ago
Marketplace.php
5 months ago
MobileAppBanner.php
4 years ago
OrderMilestoneEasterEgg.php
4 weeks ago
RemoteInboxNotifications.php
3 years ago
Settings.php
5 days ago
ShippingLabelBanner.php
1 year ago
ShippingLabelBannerDisplayRules.php
1 year ago
SiteHealth.php
3 years ago
Survey.php
4 years ago
SystemStatusReport.php
1 year ago
Translations.php
1 year ago
WCAdminAssets.php
5 days ago
WCAdminSharedSettings.php
1 year ago
WCAdminUser.php
9 months ago
WcPayWelcomePage.php
1 year ago
WCAdminSharedSettings.php
90 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Manages the WC Admin settings that need to be pre-loaded. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Admin; |
| 7 | |
| 8 | use Automattic\WooCommerce\Admin\PageController; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | /** |
| 13 | * \Automattic\WooCommerce\Internal\Admin\WCAdminSharedSettings class. |
| 14 | */ |
| 15 | class WCAdminSharedSettings { |
| 16 | /** |
| 17 | * Settings prefix used for the window.wcSettings object. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | private $settings_prefix = 'admin'; |
| 22 | |
| 23 | /** |
| 24 | * Class instance. |
| 25 | * |
| 26 | * @var WCAdminSharedSettings instance |
| 27 | */ |
| 28 | protected static $instance = null; |
| 29 | |
| 30 | /** |
| 31 | * Hook into WooCommerce Blocks. |
| 32 | */ |
| 33 | protected function __construct() { |
| 34 | if ( did_action( 'woocommerce_blocks_loaded' ) ) { |
| 35 | $this->on_woocommerce_blocks_loaded(); |
| 36 | } else { |
| 37 | add_action( 'woocommerce_blocks_loaded', array( $this, 'on_woocommerce_blocks_loaded' ), 10 ); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get class instance. |
| 43 | * |
| 44 | * @return object Instance. |
| 45 | */ |
| 46 | public static function get_instance() { |
| 47 | if ( null === self::$instance ) { |
| 48 | self::$instance = new self(); |
| 49 | } |
| 50 | return self::$instance; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Adds settings to the Blocks AssetDataRegistry when woocommerce_blocks is loaded. |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 58 | public function on_woocommerce_blocks_loaded() { |
| 59 | // Ensure we only add admin settings on the admin. |
| 60 | if ( ! is_admin() ) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | if ( class_exists( '\Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry' ) ) { |
| 65 | \Automattic\WooCommerce\Blocks\Package::container()->get( \Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class )->add( |
| 66 | $this->settings_prefix, |
| 67 | function () { |
| 68 | /** |
| 69 | * Filters the shared settings that are passed to the client. |
| 70 | * |
| 71 | * @since 6.4.0 |
| 72 | */ |
| 73 | return apply_filters( 'woocommerce_admin_shared_settings', array() ); |
| 74 | } |
| 75 | ); |
| 76 | |
| 77 | add_action( |
| 78 | 'admin_enqueue_scripts', |
| 79 | function () { |
| 80 | if ( ! PageController::is_admin_or_embed_page() ) { |
| 81 | return; |
| 82 | } |
| 83 | // Enqueue deprecation scripts (client/wp-admin-scripts/wcsettings-deprecation/index.js). |
| 84 | WCAdminAssets::register_script( 'wp-admin-scripts', 'wcsettings-deprecation', true ); |
| 85 | } |
| 86 | ); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 |