parsers
5 years ago
admin.php
5 years ago
core.php
5 years ago
engine.php
5 years ago
init.php
5 years ago
parsers.php
5 years ago
rest.php
5 years ago
support.php
5 years ago
ui.php
5 years ago
admin.php
116 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_WPMC_Admin extends MeowCommon_Admin { |
| 4 | |
| 5 | public function __construct() { |
| 6 | parent::__construct( WPMC_PREFIX, WPMC_ENTRY, WPMC_DOMAIN, class_exists( 'MeowPro_WPMC_Core' ) ); |
| 7 | add_action( 'admin_menu', array( $this, 'app_menu' ) ); |
| 8 | add_filter( 'pre_update_option', array( $this, 'pre_update_option' ), 10, 3 ); |
| 9 | |
| 10 | // Load the scripts only if they are needed by the current screen |
| 11 | $page = isset( $_GET["page"] ) ? $_GET["page"] : null; |
| 12 | $is_wpmc_screen = in_array( $page, [ 'wpmc_dashboard', 'wpmc_settings' ] ); |
| 13 | $is_meowapps_dashboard = $page === 'meowapps-main-menu'; |
| 14 | if ( $is_meowapps_dashboard || $is_wpmc_screen ) { |
| 15 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | function admin_enqueue_scripts() { |
| 20 | |
| 21 | // Load the scripts |
| 22 | $physical_file = WPMC_PATH . '/app/index.js'; |
| 23 | $cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : WPMC_VERSION; |
| 24 | wp_register_script( 'wpmc_media_cleaner-vendor', WPMC_URL . 'app/vendor.js', |
| 25 | ['wp-element', 'wp-i18n'], $cache_buster |
| 26 | ); |
| 27 | wp_register_script( 'wpmc_media_cleaner', WPMC_URL . 'app/index.js', |
| 28 | ['wpmc_media_cleaner-vendor', 'wp-i18n'], $cache_buster |
| 29 | ); |
| 30 | wp_set_script_translations( 'wpmc_media_cleaner', 'media-file-renamer' ); |
| 31 | wp_enqueue_script('wpmc_media_cleaner' ); |
| 32 | |
| 33 | // Load the fonts |
| 34 | wp_register_style( 'meow-neko-ui-lato-font', '//fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap'); |
| 35 | wp_enqueue_style( 'meow-neko-ui-lato-font' ); |
| 36 | |
| 37 | // Localize and options |
| 38 | wp_localize_script( 'wpmc_media_cleaner', 'wpmc_media_cleaner', array_merge( [ |
| 39 | 'api_url' => site_url('/wp-json/media-cleaner/v1/'), |
| 40 | 'rest_url' => site_url('/wp-json/'), |
| 41 | 'plugin_url' => WPMC_URL, |
| 42 | 'prefix' => WPMC_PREFIX, |
| 43 | 'domain' => WPMC_DOMAIN, |
| 44 | 'is_pro' => class_exists( 'MeowPro_WPMC_Core' ), |
| 45 | 'is_registered' => !!$this->is_registered(), |
| 46 | ], $this->get_all_options() ) ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Filters and performs validation for certain options |
| 51 | * @param mixed $value Option value |
| 52 | * @param string $option Option name |
| 53 | * @param mixed $old_value The current value of the option |
| 54 | * @return mixed The actual value to be stored |
| 55 | */ |
| 56 | function pre_update_option( $value, $option, $old_value ) { |
| 57 | if ( strpos( $option, 'wpmc_' ) !== 0 ) return $value; // Never touch extraneous options |
| 58 | $validated = $this->validate_option( $option, $value ); |
| 59 | if ( $validated instanceof WP_Error ) { |
| 60 | // TODO: Show warning for invalid option value |
| 61 | return $old_value; |
| 62 | } |
| 63 | return $validated; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Validates certain option values |
| 68 | * @param string $option Option name |
| 69 | * @param mixed $value Option value |
| 70 | * @return mixed|WP_Error Validated value if no problem |
| 71 | */ |
| 72 | function validate_option( $option, $value ) { |
| 73 | switch ( $option ) { |
| 74 | case 'wpmc_dirs_filter': |
| 75 | case 'wpmc_files_filter': |
| 76 | if ( $value && @preg_match( $value, '' ) === false ) return new WP_Error( 'invalid_option', __( "Invalid Regular-Expression", 'media-cleaner' ) ); |
| 77 | break; |
| 78 | } |
| 79 | return $value; |
| 80 | } |
| 81 | |
| 82 | function app_menu() { |
| 83 | add_submenu_page( 'meowapps-main-menu', 'Cleaner', 'Cleaner', 'manage_options', 'wpmc_settings', |
| 84 | array( $this, 'admin_settings' ) |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | public function admin_settings() { |
| 89 | echo '<div id="wpmc-admin-settings"></div>'; |
| 90 | } |
| 91 | |
| 92 | function get_all_options() { |
| 93 | return [ |
| 94 | 'wpmc_method' => get_option( 'wpmc_method', 'media' ), |
| 95 | 'wpmc_content' => get_option( 'wpmc_content', true ), |
| 96 | 'wpmc_media_library' => get_option( 'wpmc_media_library'), |
| 97 | 'wpmc_live_content' => get_option( 'wpmc_live_content', false ), |
| 98 | 'wpmc_debuglogs' => get_option( 'wpmc_debuglogs', false ), |
| 99 | 'wpmc_images_only' => get_option( 'wpmc_images_only' ), |
| 100 | 'wpmc_thumbnails_only' => get_option( 'wpmc_thumbnails_only' ), |
| 101 | 'wpmc_dirs_filter' => get_option( 'wpmc_dirs_filter', '' ), |
| 102 | 'wpmc_files_filter' => get_option( 'wpmc_files_filter', '' ), |
| 103 | 'wpmc_hide_thumbnails' => get_option( 'wpmc_hide_thumbnails' ), |
| 104 | 'wpmc_hide_warning' => get_option( 'wpmc_hide_warning' ), |
| 105 | 'wpmc_medias_buffer' => get_option( 'wpmc_medias_buffer', 100 ), |
| 106 | 'wpmc_posts_buffer' => get_option( 'wpmc_posts_buffer', 5 ), |
| 107 | 'wpmc_analysis_buffer' => get_option( 'wpmc_analysis_buffer', 100 ), |
| 108 | 'wpmc_delay' => get_option( 'wpmc_delay', 100 ), |
| 109 | 'wpmc_shortcodes_disabled' => get_option( 'wpmc_shortcodes_disabled' ), |
| 110 | ]; |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | |
| 115 | ?> |
| 116 |