Templates
4 weeks ago
AdminManager.php
10 months ago
ListTable.php
10 months ago
MenusController.php
10 months ago
NotificationCreatePage.php
10 months ago
NotificationEditPage.php
4 weeks ago
NotificationsPage.php
4 weeks ago
SettingsController.php
10 months ago
AdminManager.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Internal\StockNotifications\Admin; |
| 6 | |
| 7 | use Automattic\WooCommerce\Internal\StockNotifications\Admin\MenusController; |
| 8 | use Automattic\WooCommerce\Internal\StockNotifications\Admin\SettingsController; |
| 9 | use Automattic\Jetpack\Constants; |
| 10 | |
| 11 | /** |
| 12 | * Admin controller for Customer Stock Notifications. |
| 13 | */ |
| 14 | class AdminManager { |
| 15 | |
| 16 | /** |
| 17 | * Initialize admin components. |
| 18 | * |
| 19 | * @internal |
| 20 | * |
| 21 | * @return void |
| 22 | */ |
| 23 | final public function __construct() { |
| 24 | |
| 25 | // Enqueue scripts. |
| 26 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_resources' ), 11 ); |
| 27 | |
| 28 | $container = wc_get_container(); |
| 29 | $container->get( MenusController::class ); |
| 30 | $container->get( SettingsController::class ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Admin scripts. |
| 35 | * |
| 36 | * @return void |
| 37 | */ |
| 38 | public static function admin_resources() { |
| 39 | |
| 40 | $screen = get_current_screen(); |
| 41 | $screen_id = $screen ? $screen->id : ''; |
| 42 | $suffix = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min'; |
| 43 | $version = Constants::get_constant( 'WC_VERSION' ); |
| 44 | |
| 45 | wp_register_script( 'wc-admin-customer-stock-notifications', WC()->plugin_url() . '/assets/js/admin/wc-customer-stock-notifications' . $suffix . '.js', array( 'jquery' ), $version, true ); |
| 46 | |
| 47 | $params = array( |
| 48 | 'i18n_wc_delete_notification_warning' => __( 'Delete this notification permanently?', 'woocommerce' ), |
| 49 | 'i18n_wc_bulk_delete_notifications_warning' => __( 'Delete the selected notifications permanently?', 'woocommerce' ), |
| 50 | ); |
| 51 | |
| 52 | /* |
| 53 | * Enqueue specific styles & scripts. |
| 54 | */ |
| 55 | if ( |
| 56 | ! in_array( |
| 57 | $screen_id, |
| 58 | array( 'woocommerce_page_wc-customer-stock-notifications', 'woocommerce_page_wc-settings' ), |
| 59 | true |
| 60 | ) |
| 61 | ) { |
| 62 | return; |
| 63 | } |
| 64 | //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 65 | if ( 'woocommerce_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'customer_stock_notifications' !== $_GET['section'] ) { |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | wp_enqueue_script( 'wc-admin-customer-stock-notifications' ); |
| 70 | wp_localize_script( 'wc-admin-customer-stock-notifications', 'wc_admin_customer_stock_notifications_params', $params ); |
| 71 | } |
| 72 | } |
| 73 |