parsers
4 years ago
admin.php
4 years ago
core.php
3 years ago
engine.php
4 years ago
init.php
4 years ago
parsers.php
5 years ago
rest.php
3 years ago
support.php
4 years ago
ui.php
3 years ago
admin.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_WPMC_Admin extends MeowCommon_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 | // Localize and options |
| 42 | wp_localize_script( 'wpmc_media_cleaner', 'wpmc_media_cleaner', array_merge( [ |
| 43 | 'api_url' => rest_url( 'media-cleaner/v1' ), |
| 44 | 'rest_url' => rest_url(), |
| 45 | 'plugin_url' => WPMC_URL, |
| 46 | 'prefix' => WPMC_PREFIX, |
| 47 | 'domain' => WPMC_DOMAIN, |
| 48 | 'is_pro' => class_exists( 'MeowPro_WPMC_Core' ), |
| 49 | 'is_registered' => !!$this->is_registered(), |
| 50 | 'rest_nonce' => wp_create_nonce( 'wp_rest' ) |
| 51 | ], $this->get_all_options() ) ); |
| 52 | } |
| 53 | |
| 54 | function app_menu() { |
| 55 | if ( !$this->core->can_access_settings() ) { |
| 56 | return; |
| 57 | } |
| 58 | add_submenu_page( 'meowapps-main-menu', 'Media Cleaner', 'Media Cleaner', 'read', 'wpmc_settings', |
| 59 | array( $this, 'admin_settings' ) |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | public function admin_settings() { |
| 64 | if ( !$this->core->can_access_settings() ) { |
| 65 | return; |
| 66 | } |
| 67 | echo '<div id="wpmc-admin-settings"></div>'; |
| 68 | } |
| 69 | |
| 70 | function list_options() { |
| 71 | return array( |
| 72 | 'wpmc_method' => 'media', |
| 73 | 'wpmc_content' => true, |
| 74 | 'wpmc_filesystem_content' => false, |
| 75 | 'wpmc_media_library' => true, |
| 76 | 'wpmc_live_content' => false, |
| 77 | 'wpmc_debuglogs' => false, |
| 78 | 'wpmc_images_only' => false, |
| 79 | 'wpmc_attach_is_use' => false, |
| 80 | 'wpmc_thumbnails_only' => false, |
| 81 | 'wpmc_dirs_filter' => '', |
| 82 | 'wpmc_files_filter' => '', |
| 83 | 'wpmc_hide_thumbnails' => false, |
| 84 | 'wpmc_hide_warning' => false, |
| 85 | 'wpmc_medias_buffer' => 100, |
| 86 | 'wpmc_posts_buffer' => 5, |
| 87 | 'wpmc_analysis_buffer' => 100, |
| 88 | 'wpmc_file_op_buffer' => 20, |
| 89 | 'wpmc_delay' => 100, |
| 90 | 'wpmc_shortcodes_disabled' => false, |
| 91 | 'wpmc_posts_per_page' => 10, |
| 92 | 'wpmc_clean_uninstall' => false, |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | function get_all_options() { |
| 97 | $options = $this->list_options(); |
| 98 | $current_options = array(); |
| 99 | foreach ( $options as $option => $default ) { |
| 100 | $current_options[$option] = get_option( $option, $default ); |
| 101 | } |
| 102 | return $current_options; |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | |
| 107 | ?> |
| 108 |