AdminAssets.php
| 1 | <?php |
| 2 | |
| 3 | namespace WPParsidate\Admin; |
| 4 | |
| 5 | defined( 'ABSPATH' ) || exit; |
| 6 | |
| 7 | use WPParsidate\Helper\{Assets, Nonce}; |
| 8 | |
| 9 | class AdminAssets { |
| 10 | public function __construct() { |
| 11 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueueScripts' ) ); |
| 12 | } |
| 13 | |
| 14 | public function enqueueScripts(): void { |
| 15 | $pluginVersion = Assets::getVersion(); |
| 16 | $debugName = WP_PARSI_DEBUG_MODE ? '' : '.min'; |
| 17 | |
| 18 | wp_enqueue_script( WP_PARSI_KEY_SLUG . '-plugin-admin', |
| 19 | Assets::url( 'js-admin/plugin-admin' . $debugName . '.js' ), [], $pluginVersion, [ 'in_footer' => true ] ); |
| 20 | |
| 21 | wp_localize_script( WP_PARSI_KEY_SLUG . '-plugin-admin', WP_PARSI_KEY_CAP . 'Admin', |
| 22 | array( |
| 23 | 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 24 | 'ajaxNonce' => Nonce::create(), |
| 25 | ) ); |
| 26 | |
| 27 | if ( ! AdminPages::isSettingPage() ) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | //wp_enqueue_media(); |
| 32 | //wp_enqueue_style( 'wp-color-picker' ); |
| 33 | //wp_enqueue_script( 'wp-color-picker' ); |
| 34 | |
| 35 | wp_enqueue_style( WP_PARSI_KEY_SLUG . '-plugin', |
| 36 | Assets::url( 'css-admin/plugin' . $debugName . '.css' ), false, $pluginVersion ); |
| 37 | |
| 38 | wp_enqueue_script( WP_PARSI_KEY_SLUG . '-plugin', |
| 39 | Assets::url( 'js-admin/plugin' . $debugName . '.js' ), |
| 40 | [ |
| 41 | 'jquery', |
| 42 | 'jquery-ui-sortable', |
| 43 | ], $pluginVersion, [ 'in_footer' => true ] ); |
| 44 | |
| 45 | wp_localize_script( WP_PARSI_KEY_SLUG . '-plugin', WP_PARSI_KEY_CAP, |
| 46 | array( |
| 47 | 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 48 | 'ajaxNonce' => Nonce::create(), |
| 49 | 'pageRefreshedAfter' => apply_filters( 'wp_parsidate_settings_page_refreshed_after', 0 ), |
| 50 | 'pageRefreshUrl' => apply_filters( 'wp_parsidate_settings_page_refresh_url', null ), |
| 51 | 'removeText' => esc_html__( 'Remove', 'wp-parsidate' ), |
| 52 | 'dtuConfirmDelete' => esc_html__( 'Are you sure you want to delete this item(s)?', 'wp-parsidate' ), |
| 53 | 'copyText' => esc_html__( 'Click to copy this text.', 'wp-parsidate' ), |
| 54 | ) ); |
| 55 | } |
| 56 | |
| 57 | public static function imageUrl( $path ): string { |
| 58 | return WP_PARSI_URL . 'assets/images/' . $path; |
| 59 | } |
| 60 | } |
| 61 |