parsers
1 month ago
admin.php
7 months ago
core.php
1 month ago
engine.php
1 month ago
init.php
7 months ago
parsers.php
10 months ago
rest.php
1 month ago
support.php
1 month ago
ui.php
3 years ago
admin.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_WPMC_Admin extends MeowKit_WPMC_Admin { |
| 4 | |
| 5 | private $core = null; |
| 6 | |
| 7 | public function __construct( $core ) { |
| 8 | $this->core = $core; |
| 9 | parent::__construct( WPMC_PREFIX, WPMC_ENTRY, WPMC_DOMAIN, class_exists( 'MeowPro_WPMC_Core' ) ); |
| 10 | add_action( 'admin_menu', array( $this, 'app_menu' ) ); |
| 11 | |
| 12 | // Load the scripts only if they are needed by the current screen |
| 13 | $page = isset( $_GET["page"] ) ? sanitize_text_field( $_GET["page"] ) : null; |
| 14 | $is_wpmc_screen = in_array( $page, [ 'wpmc_dashboard', 'wpmc_settings' ] ); |
| 15 | $is_meowapps_dashboard = $page === 'meowapps-main-menu'; |
| 16 | if ( $is_meowapps_dashboard || $is_wpmc_screen ) { |
| 17 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | function admin_enqueue_scripts() { |
| 22 | |
| 23 | // Load the scripts |
| 24 | $physical_file = WPMC_PATH . '/app/index.js'; |
| 25 | $cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : WPMC_VERSION; |
| 26 | wp_register_script( 'wpmc_media_cleaner-vendor', WPMC_URL . 'app/vendor.js', |
| 27 | ['wp-element', 'wp-i18n'], $cache_buster |
| 28 | ); |
| 29 | wp_register_script( 'wpmc_media_cleaner', WPMC_URL . 'app/index.js', |
| 30 | ['wpmc_media_cleaner-vendor', 'wp-i18n'], $cache_buster |
| 31 | ); |
| 32 | if ( function_exists( 'wp_set_script_translations' ) ) { |
| 33 | wp_set_script_translations( 'wpmc_media_cleaner', 'media-cleaner' ); |
| 34 | } |
| 35 | wp_enqueue_script('wpmc_media_cleaner' ); |
| 36 | |
| 37 | // Load the fonts |
| 38 | wp_register_style( 'meow-neko-ui-lato-font', '//fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap'); |
| 39 | wp_enqueue_style( 'meow-neko-ui-lato-font' ); |
| 40 | |
| 41 | // Options |
| 42 | $options = array_merge( $this->core->get_all_options(), [ |
| 43 | 'incompatible_plugins' => Meow_WPMC_Support::get_issues(), |
| 44 | 'native_plugins' => Meow_WPMC_Support::get_natives(), |
| 45 | ] ); |
| 46 | |
| 47 | // Localize and options |
| 48 | wp_localize_script( 'wpmc_media_cleaner', 'wpmc_media_cleaner', [ |
| 49 | 'api_url' => rest_url( 'media-cleaner/v1' ), |
| 50 | 'rest_url' => rest_url(), |
| 51 | 'plugin_url' => WPMC_URL, |
| 52 | 'prefix' => WPMC_PREFIX, |
| 53 | 'domain' => WPMC_DOMAIN, |
| 54 | 'is_pro' => class_exists( 'MeowPro_WPMC_Core' ), |
| 55 | 'is_registered' => !!$this->is_registered(), |
| 56 | 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
| 57 | 'options' => $options |
| 58 | ] ); |
| 59 | } |
| 60 | |
| 61 | function app_menu() { |
| 62 | if ( !$this->core->can_access_settings() ) { |
| 63 | return; |
| 64 | } |
| 65 | add_submenu_page( 'meowapps-main-menu', 'Media Cleaner', 'Media Cleaner', 'read', 'wpmc_settings', |
| 66 | array( $this, 'admin_settings' ) |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | public function admin_settings() { |
| 71 | if ( !$this->core->can_access_settings() ) { |
| 72 | return; |
| 73 | } |
| 74 | echo '<div id="wpmc-admin-settings"></div>'; |
| 75 | } |
| 76 | |
| 77 | function is_pro_user() { |
| 78 | return class_exists( 'MeowPro_WPMC_Core' ) && !!$this->is_registered(); |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | ?> |
| 84 |