| @@ -1,27 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -class Meow_MGL_Admin extends MeowKit_MGL_Admin { | |
| 3 | +class Meow_MGL_Admin extends MeowCommon_Admin { | |
| 4 | 4 | |
| 5 | - private $core; | |
| 6 | - | |
| 7 | - public function __construct($core) { | |
| 5 | + public function __construct() { | |
| 8 | 6 | parent::__construct( MGL_PREFIX, MGL_ENTRY, MGL_DOMAIN, class_exists( 'MeowPro_MGL_Core' ) ); |
| 9 | - $this->core = $core; | |
| 10 | 7 | add_action( 'admin_menu', array( $this, 'app_menu' ) ); |
| 11 | 8 | $blocks_enabled = function_exists( 'register_block_type' ); |
| 12 | 9 | if ( $blocks_enabled ) { |
| 13 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); | |
| 10 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); | |
| 14 | 11 | } |
| 15 | - $options = $this->core->get_all_options(); | |
| 16 | - if ( ( $options['captions'] ?? 'notset' ) === 'notset' ) { | |
| 17 | - // MEOMO: mgl_captions_enabled option is used only here. Also, it deletes soon after being used. | |
| 18 | - // So we keep this option what it is (not migrated to the mgl_options). | |
| 12 | + if ( get_option( 'mgl_captions', 'notset' ) === 'notset' ) { | |
| 19 | 13 | $captions_enabled = get_option( 'mgl_captions_enabled' ); |
| 20 | - $this->core->update_options( array_merge( | |
| 21 | - $options, | |
| 22 | - [ 'captions' => $captions_enabled ? 'hover-only' : false ] | |
| 23 | - ) ); | |
| 14 | + update_option( 'mgl_captions', $captions_enabled ? 'hover-only' : false ); | |
| 24 | 15 | delete_option( 'mgl_captions_enabled' ); |
| 25 | 16 | } |
| 26 | 17 | } |
| 27 | 18 | |
| @@ -28,14 +19,43 @@ | ||
| 28 | 19 | public function mgl_settings() { |
| 29 | 20 | echo '<div id="mgl-admin-settings"></div>'; |
| 30 | 21 | } |
| 31 | 22 | |
| 32 | - // The scripts and styles are all handled by Meow_MGL_Run; the block only needs to point at | |
| 33 | - // the admin bundle it registers. | |
| 34 | - function register_block() { | |
| 35 | - register_block_type( 'meow-gallery/gallery', array( | |
| 36 | - 'editor_script' => Meow_MGL_Run::ADMIN_SCRIPT_HANDLE, | |
| 37 | - ) ); | |
| 23 | + function enqueue_scripts() { | |
| 24 | + | |
| 25 | + // Javascript for gallery | |
| 26 | + $physical_file = MGL_PATH . '/app/galleries.js'; | |
| 27 | + $cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : MGL_VERSION; | |
| 28 | + wp_register_script( 'mgl-gallery-js', plugins_url( '/app/galleries.js', __DIR__ ), | |
| 29 | + array( 'jquery' ), $cache_buster, false ); | |
| 30 | + | |
| 31 | + // Load the "admin" scripts | |
| 32 | + $physical_file = MGL_PATH . '/app/admin.js'; | |
| 33 | + $cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : MGL_VERSION; | |
| 34 | + wp_register_script( 'mgl-admin-js', MGL_URL . '/app/admin.js', | |
| 35 | + array( 'mgl-gallery-js', 'wp-editor', 'wp-i18n', 'wp-element' ), $cache_buster ); | |
| 36 | + register_block_type( 'meow-gallery/gallery', array( 'editor_script' => 'mgl-admin-js' )); | |
| 37 | + | |
| 38 | + // Load the fonts | |
| 39 | + wp_register_style( 'meow-neko-ui-lato-font', '//fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap'); | |
| 40 | + wp_enqueue_style( 'meow-neko-ui-lato-font' ); | |
| 41 | + | |
| 42 | + // Localize and options | |
| 43 | + global $wplr; | |
| 44 | + wp_localize_script( 'mgl-admin-js', 'mgl_meow_gallery', array_merge( [ | |
| 45 | + //'api_nonce' => wp_create_nonce( 'mfrh_media_file_renamer' ), | |
| 46 | + 'api_url' => get_rest_url( null, '/meow-gallery/v1/' ), | |
| 47 | + 'rest_url' => get_rest_url(), | |
| 48 | + 'plugin_url' => MGL_URL, | |
| 49 | + 'prefix' => MGL_PREFIX, | |
| 50 | + 'domain' => MGL_DOMAIN, | |
| 51 | + 'is_pro' => class_exists( 'MeowPro_MGL_Core' ), | |
| 52 | + 'is_registered' => !!$this->is_registered(), | |
| 53 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 54 | + 'wplr_collections' => $wplr ? $wplr->read_collections_recursively() : [], | |
| 55 | + ] ) ); | |
| 56 | + | |
| 57 | + wp_enqueue_script( 'mgl-admin-js' ); | |
| 38 | 58 | } |
| 39 | 59 | |
| 40 | 60 | function app_menu() { |
| 41 | 61 | add_submenu_page( 'meowapps-main-menu', __( 'Gallery', MGL_DOMAIN ), __( 'Gallery', MGL_DOMAIN ), |