| @@ -1,52 +1,22 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class Meow_MGL_Run { |
| 4 | - private $isEnqueued = false; | |
| 5 | - private $core; | |
| 6 | - private $atts; | |
| 7 | 4 | |
| 8 | 5 | public function __construct( $core ) { |
| 9 | - $this->core = $core; | |
| 10 | - | |
| 11 | - $override_disabled = get_option( 'mgl_options', [] )[ 'gallery_shortcode_override_disabled' ] ?? false; | |
| 12 | - if ( !$override_disabled ) { add_shortcode( 'gallery', array( $core, 'gallery' ) ); } | |
| 6 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); | |
| 7 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); | |
| 8 | + add_shortcode( 'gallery', array( $core, 'gallery' ) ); | |
| 13 | 9 | add_shortcode( 'meow-gallery', array( $core, 'gallery' ) ); |
| 14 | - | |
| 15 | - if ( is_admin() ) { | |
| 16 | - add_action( 'init', array( $this, 'enqueue_scripts' ) ); | |
| 17 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); | |
| 18 | - } else { | |
| 19 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ), 10 ); | |
| 20 | - | |
| 21 | - add_action( 'mgl_gallery_created', array( $this, 'enqueue_scripts' ), 10, 0 ); | |
| 22 | - add_action( 'mgl_collection_created', array( $this, 'enqueue_scripts' ), 10, 0 ); | |
| 23 | - } | |
| 24 | - | |
| 25 | 10 | // Yoast: Some people really want this, but it needs to be reviewed as Yoast changed its API |
| 26 | 11 | //add_filter( 'wpseo_sitemap_urlimages', array( $this, 'wpseo_siteimap' ), 10, 2 ); |
| 27 | 12 | } |
| 28 | 13 | |
| 29 | - function enqueue_styles() { | |
| 30 | - // Cache buster for CSS | |
| 31 | - $css_file = MGL_PATH . '/app/style.min.css'; | |
| 32 | - $css_cache_buster = file_exists( $css_file ) ? filemtime( $css_file ) : MGL_VERSION; | |
| 33 | - wp_enqueue_style( 'mgl-css', plugins_url( '/app/style.min.css', __DIR__ ), null, $css_cache_buster ); | |
| 34 | - } | |
| 35 | - | |
| 36 | 14 | function enqueue_scripts() { |
| 37 | - // Only need to load the scripts once. | |
| 38 | - if ( $this->isEnqueued ) { | |
| 39 | - return; | |
| 40 | - } | |
| 41 | - $this->isEnqueued = true; | |
| 42 | - | |
| 43 | - // Load the JS for Meow Gallery | |
| 44 | 15 | $physical_file = MGL_PATH . '/app/galleries.js'; |
| 45 | 16 | $cache_buster = file_exists( $physical_file ) ? filemtime( $physical_file ) : MGL_VERSION; |
| 46 | - wp_enqueue_script( 'mgl-js', plugins_url( '/app/galleries.js', __DIR__ ), array(), $cache_buster, true ); | |
| 17 | + wp_enqueue_script( 'mgl-js', plugins_url( '/app/galleries.js', __DIR__ ), array( 'jquery' ), $cache_buster, false ); | |
| 47 | 18 | |
| 48 | - | |
| 49 | 19 | // TODO: This should be moved in a getter (since it is also used by tiles.php) |
| 50 | 20 | $density = []; |
| 51 | 21 | if ( isset( $this->atts['density'] ) ) { |
| 52 | 22 | $density['desktop'] = $this->atts['density']; |
| @@ -53,23 +23,20 @@ | ||
| 53 | 23 | $density['tablet'] = $this->atts['density']; |
| 54 | 24 | $density['mobile'] = $this->atts['density']; |
| 55 | 25 | } |
| 56 | 26 | else { |
| 57 | - $density['desktop'] = $this->core->get_option( 'tiles_density', 'high' ); | |
| 58 | - $density['tablet'] = $this->core->get_option( 'tiles_density_tablet', 'medium' ); | |
| 59 | - $density['mobile'] = $this->core->get_option( 'tiles_density_mobile', 'low' ); | |
| 27 | + $density['desktop'] = get_option( 'mgl_tiles_density', 'high' ); | |
| 28 | + $density['tablet'] = get_option( 'mgl_tiles_density_tablet', 'medium' ); | |
| 29 | + $density['mobile'] = get_option( 'mgl_tiles_density_mobile', 'low' ); | |
| 60 | 30 | } |
| 61 | 31 | |
| 62 | 32 | wp_localize_script('mgl-js', 'mgl_settings', |
| 63 | 33 | array( |
| 64 | - 'infinite_buffer' => $this->core->get_option( 'infinite_buffer', 0 ), | |
| 65 | - 'disable_right_click' => !$this->core->get_option( 'right_click', false ), | |
| 66 | - 'tiles' => array( 'density' => $density ), | |
| 67 | - 'api_url' => get_rest_url( null, '/meow-gallery/v1/' ), | |
| 68 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 69 | - 'options' => $this->core->get_all_options(), | |
| 34 | + 'disable_right_click' => !get_option( 'mgl_right_click', false ), | |
| 35 | + 'tiles' => array( 'density' => $density ) | |
| 70 | 36 | ) |
| 71 | 37 | ); |
| 38 | + wp_enqueue_style( 'mgl-css', plugins_url( '/app/style.min.css', __DIR__ ), null, $cache_buster ); | |
| 72 | 39 | } |
| 73 | 40 | |
| 74 | 41 | /* |
| 75 | 42 | For Yoast SEO |