Init.php
54 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Order Detail Redesign feature loader. |
| 4 | * |
| 5 | * @package WooCommerce |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | |
| 10 | namespace Automattic\WooCommerce\Internal\Features\OrderDetailRedesign; |
| 11 | |
| 12 | /** |
| 13 | * Loads support for the redesigned WooCommerce order detail page. |
| 14 | * |
| 15 | * Manually instantiated from `Features::load_features()` when the |
| 16 | * `order-detail-redesign` feature flag is enabled (see |
| 17 | * `client/admin/config/core.json`). Lives in the `Internal` namespace |
| 18 | * because the feature class is not part of the public API surface. |
| 19 | * |
| 20 | * @since 10.9.0 |
| 21 | */ |
| 22 | class Init { |
| 23 | |
| 24 | const FEATURE_ID = 'order-detail-redesign'; |
| 25 | |
| 26 | /** |
| 27 | * Constructor. |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | if ( ! is_admin() ) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | add_filter( 'admin_body_class', array( $this, 'handle_admin_body_class' ) ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Adds the feature body class to every admin page while the feature is enabled. |
| 39 | * |
| 40 | * Screen-level scoping is handled by the CSS selectors, which chain this |
| 41 | * class with the WP-provided page classes (`.woocommerce_page_wc-orders`, |
| 42 | * `.post-type-shop_order`) and qualifiers like `:has(#poststuff)` so the |
| 43 | * styles only apply on the actual order edit/new screens. |
| 44 | * |
| 45 | * @internal |
| 46 | * |
| 47 | * @param string $classes Existing space-separated body classes. |
| 48 | * @return string |
| 49 | */ |
| 50 | public function handle_admin_body_class( string $classes ): string { |
| 51 | return $classes . ' woocommerce-feature-enabled-' . self::FEATURE_ID; |
| 52 | } |
| 53 | } |
| 54 |