init(); } /** * Prevent plugin activation if Modula Pro is not installed and activated * * @since 1.0.1 */ public function plugin_activation(){ if(!class_exists('Modula_PRO')){ deactivate_plugins( plugin_basename( MODULA_ADVANCED_SHORTCODES_FILE ) ); wp_die(__('Please install and activate Modula Pro before using Modula Advanced Shortcodes add-on.','modula-albums')); } } /** * Loads the plugin textdomain for translation. * * @since 1.0.0 */ public function load_plugin_textdomain() { load_plugin_textdomain( $this->plugin_slug, false, MODULA_ADVANCED_SHORTCODES_PATH . '/languages/' ); } /** * Loads the plugin into WordPress. * * @since 1.0.0 */ public function init() { // Load admin only components. if ( is_admin() ) { add_action( 'modula_pro_updater', array( $this, 'addon_updater' ), 15, 2 ); $this->require_admin(); } } public function addon_updater( $license_key, $store_url ) { if ( class_exists( 'Modula_Pro_Base_Updater' ) ) { $modula_addon_updater = new Modula_Pro_Base_Updater( $store_url, MODULA_ADVANCED_SHORTCODES_FILE, array( 'version' => MODULA_ADVANCED_SHORTCODES_VERSION, // current version number 'license' => $license_key, // license key (used get_option above to retrieve from DB) 'item_id' => 3555, // ID of the product 'author' => 'MachoThemes', // author of this plugin 'beta' => false, ) ); } } /** * Loads all admin related files into scope. * * @since 1.0.0 */ public function require_admin() { require_once MODULA_ADVANCED_SHORTCODES_PATH . 'includes/admin/class-modula-advanced-shortcodes-settings.php'; } /** * Returns the singleton instance of the class. * * @since 1.0.0 * * @return object The Advanced_Shortcodes object. */ public static function get_instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Modula_Advanced_Shortcodes ) ) { self::$instance = new Modula_Advanced_Shortcodes(); } return self::$instance; } /** * Enqueue Modula global filters script */ public function global_filters(){ wp_register_script('modula-global-filters',MODULA_ADVANCED_SHORTCODES_URL.'assets/js/global-filters.min.js',array('modula'),MODULA_ADVANCED_SHORTCODES_VERSION,true); // comment the enqueue for the moment // wp_enqueue_script('modula-global-filters'); } /** * Shortcode for displaying all galleries or galleries based on gallery_id request */ public function modula_all_galleries() { $output = ''; $gallery_link = get_option( 'mas_gallery_link' ); if(!$gallery_link){ $gallery_link = 'gallery_id'; } if ( isset( $_REQUEST[$gallery_link] ) ) { $gallery_id = intval($_REQUEST[$gallery_link]); $gallery_args = array( 'post_type' => 'modula-gallery', 'post__in' => array( $gallery_id ), 'order' => 'DESC' ); $galleries = new WP_Query( $gallery_args ); echo ($galleries->found_posts == 0) ? __('No galleries found matching id','modula-advanced-shortcodes').' '.esc_html($gallery_id).'' : ""; } else { $gallery_args = array( 'post_type' => 'modula-gallery', 'posts_per_page' => - 1, 'orderby' => 'menu_order', 'order' => 'DESC' ); $galleries = new WP_Query( $gallery_args ); } if ( $galleries->have_posts() ) { while ( $galleries->have_posts() ) { $galleries->the_post(); $id = get_the_ID(); if ( ! is_admin() ) { $output.= do_shortcode( '[modula id="' . esc_attr($id) . '"]' ); } } wp_reset_postdata(); } return $output; } /** * Shortcode to output only the filters */ public function modula_output_filters($atts) { $gallery_link = get_option('mas_gallery_link'); $shortcode_atts = shortcode_atts(array( 'gallery_id' => false, ), $atts); $filters_array = array(); $gallery_args = array( 'post_type' => 'modula-gallery', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'DESC', ); $gallery_id = (isset($_REQUEST[$gallery_link])) ? $_REQUEST[$gallery_link] : $shortcode_atts['gallery_id']; // Check to see if $gallery_id is not false if ($gallery_id) { $gallery_args['post__in'] = array($gallery_id); } $galleries = new WP_Query($gallery_args); if ($galleries->have_posts()) { while ($galleries->have_posts()) { $galleries->the_post(); $modula_settings = get_post_meta(get_the_ID(), 'modula-settings', true); $filters = $modula_settings['filters']; if ($filters) { foreach ($filters as $filter) { if (!in_array($filter, $filters_array)) { $filters_array[] = $filter; } } } } wp_reset_postdata(); } $html = '