plugin_path( 'admin/includes/data.php' ); add_action( 'init', function() { $this->data = new Jet_Smart_Filters_Admin_Data(); }, 999 ); //Init Setting Pages add_action( 'admin_menu', array( $this, 'register_settings_page' ), 99 ); require jet_smart_filters()->plugin_path( 'admin/setting-pages/setting-pages.php' ); new Jet_Smart_Filters_Admin_Setting_Pages(); // Indexer $this->is_indexer_enabled = filter_var( jet_smart_filters()->settings->get( 'use_indexed_filters' ), FILTER_VALIDATE_BOOLEAN ); if ( $this->is_indexer_enabled ) { add_action( 'restrict_manage_posts', array( $this, 'add_index_filters_button' ) ); } add_filter( 'jet-smart-filters/post-type/args', array( $this, 'set_post_type_args' ) ); add_action( 'admin_init', array( $this, 'init_meta' ), 99999 ); add_filter( 'jet-smart-filters/admin/filter-types', array( $this, 'add_placeholder_types' ) ); add_filter( 'jet-smart-filters/post-type/options-data-sources', array( $this, 'add_placeholder_sources' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) ); add_action( 'wp_ajax_jet_smart_filters_admin', array( $this, 'filters_admin_action' ) ); add_action( 'wp_ajax_nopriv_jet_smart_filters_admin', array( $this, 'filters_admin_action' ) ); add_action( 'add_meta_boxes_' . jet_smart_filters()->post_type->slug(), array( $this, 'disable_metaboxes' ), 9999 ); add_filter( 'post_row_actions', array( $this, 'remove_view_action' ), 10, 2 ); // Admin mode switcher button add_action( 'restrict_manage_posts', array( $this, 'add_admin_mode_switcher_button' ) ); } public function set_post_type_args( $args ) { $args = array( 'labels' => array( 'name' => esc_html__( 'Smart Filters', 'jet-smart-filters' ), 'singular_name' => esc_html__( 'Filter', 'jet-smart-filters' ), 'add_new' => esc_html__( 'Add New', 'jet-smart-filters' ), 'add_new_item' => esc_html__( 'Add New Filter', 'jet-smart-filters' ), 'edit_item' => esc_html__( 'Edit Filter', 'jet-smart-filters' ), 'new_item' => esc_html__( 'Add New Item', 'jet-smart-filters' ), 'view_item' => esc_html__( 'View Filter', 'jet-smart-filters' ), 'search_items' => esc_html__( 'Search Filter', 'jet-smart-filters' ), 'not_found' => esc_html__( 'No Filters Found', 'jet-smart-filters' ), 'not_found_in_trash' => esc_html__( 'No Filters Found In Trash', 'jet-smart-filters' ), 'menu_name' => esc_html__( 'Smart Filters', 'jet-smart-filters' ), ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'menu_position' => 101, 'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode(''), 'show_in_nav_menus' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, 'query_var' => false, 'can_export' => true, 'rewrite' => false, 'capability_type' => 'post', 'supports' => array( 'title' ), ); return $args; } /** * Initialize filters meta */ public function init_meta() { new Cherry_X_Post_Meta( array( 'id' => 'filter-labels', 'title' => __( 'Filter Labels', 'jet-smart-filters' ), 'page' => array( jet_smart_filters()->post_type->slug() ), 'context' => 'normal', 'priority' => 'high', 'callback_args' => false, 'builder_cb' => array( $this, 'get_builder' ), 'fields' => apply_filters( 'jet-smart-filters/post-type/meta-fields-labels', $this->data->settings_data['labels'] ) ) ); new Cherry_X_Post_Meta( array( 'id' => 'filter-settings', 'title' => __( 'Filter Settings', 'jet-smart-filters' ), 'page' => array( jet_smart_filters()->post_type->slug() ), 'context' => 'normal', 'priority' => 'high', 'callback_args' => false, 'builder_cb' => array( $this, 'get_builder' ), 'fields' => apply_filters( 'jet-smart-filters/post-type/meta-fields-settings', $this->data->settings_data['settings'] ), ) ); new Cherry_X_Post_Meta( array( 'id' => 'query-settings', 'title' => 'Query Settings', 'page' => array( jet_smart_filters()->post_type->slug() ), 'context' => 'normal', 'priority' => 'high', 'callback_args' => false, 'builder_cb' => array( $this, 'get_builder' ), 'fields' => apply_filters( 'jet-smart-filters/post-type/meta-fields-query', $this->data->settings_data['query'] ) ) ); $filter_date_formats = jet_smart_filters()->utils->get_file_html( 'admin/templates/info-blocks/date-formats.php' ); new Cherry_X_Post_Meta( array( 'id' => 'filter-date-formats', 'title' => __( 'Date Formats', 'jet-smart-filters' ), 'page' => array( jet_smart_filters()->post_type->slug() ), 'context' => 'normal', 'priority' => 'high', 'callback_args' => false, 'builder_cb' => array( $this, 'get_builder' ), 'fields' => array( 'license' => array( 'type' => 'html', 'class' => 'cx-component', 'html' => $filter_date_formats, ), ), ) ); $filter_notes = jet_smart_filters()->utils->get_file_html( 'admin/admin-classic/templates/notes.php' ); new Cherry_X_Post_Meta( array( 'id' => 'filter-notes', 'title' => __( 'Notes', 'jet-smart-filters' ), 'page' => array( jet_smart_filters()->post_type->slug() ), 'context' => 'normal', 'priority' => 'high', 'callback_args' => false, 'builder_cb' => array( $this, 'get_builder' ), 'fields' => array( 'license' => array( 'type' => 'html', 'class' => 'cx-component', 'html' => $filter_notes, ), ), ) ); } /** * Add placeholders for options lists */ public function add_placeholder_types( $options ) { return array( 0 => __( 'Select filter type...', 'jet-smart-filters' ) ) + $options; } public function add_placeholder_sources( $options ) { return array_merge( array( '' => __( 'Select data source...', 'jet-smart-filters' ) ), $options ); } /** * Admin enqueue assets */ public function admin_enqueue_assets() { $screen = get_current_screen(); if ( jet_smart_filters()->post_type->slug() !== $screen->id && 'edit-' . jet_smart_filters()->post_type->slug() !== $screen->id ) { return; } wp_enqueue_script( 'jet-smart-filters', jet_smart_filters()->plugin_url( 'admin/admin-classic/assets/js/jsf-admin-classic.js' ), array( 'jquery' ), jet_smart_filters()->get_version(), true ); wp_enqueue_style( 'jet-smart-filters-admin', jet_smart_filters()->plugin_url( 'admin/admin-classic/assets/css/admin-classic.css' ), array(), jet_smart_filters()->get_version() ); // localized data $post_id = isset( $_GET['post'] ) ? $_GET['post'] : false; $data_exclude_include = array(); $data_color_image = array(); if ( ! $post_id && isset( $_REQUEST['post_ID'] ) ) { $post_id = $_REQUEST['post_ID']; } if ( !empty( $post_id ) ){ $data_exclude_include = get_post_meta( $_REQUEST['post'], '_data_exclude_include', true ); $data_color_image = get_post_meta( $_REQUEST['post'], '_source_color_image_input', true ); } wp_localize_script( 'jet-smart-filters', 'JetSmartFiltersAdminData', array( 'urls' => array( 'admin' => get_admin_url(), 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'endpoints' => jet_smart_filters()->rest_api->get_endpoints_urls(), ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'dataExcludeInclude' => $data_exclude_include, 'dataColorImage' => $data_color_image, ) ); } /** * Admin action in AJAX request */ public function filters_admin_action() { $tax = ! empty( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false; $post_type = ! empty( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false; $hide_empty = isset( $_REQUEST['hide_empty'] ) ? filter_var( $_REQUEST['hide_empty'], FILTER_VALIDATE_BOOLEAN ) : true; $posts_list = ''; $terms_list = ''; if ( $tax ) { $args = array( 'taxonomy' => $tax, 'hide_empty' => $hide_empty ); $terms = get_terms( $args ); $terms = wp_list_pluck( $terms, 'name', 'term_id' ); foreach ( $terms as $terms_id => $term_name ) { $terms_list .= ''; } } if ( $post_type ) { $args = array( 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => - 1, ); $posts = get_posts( $args ); if ( ! empty( $posts ) ) { $posts = wp_list_pluck( $posts, 'post_title', 'ID' ); } foreach ( $posts as $post_id => $post_title ) { $posts_list .= ''; } } wp_send_json( array( 'terms' => $terms_list, 'posts' => $posts_list, ) ); } /** * Register add/edit page */ public function register_settings_page() { add_submenu_page( 'edit.php?post_type=jet-smart-filters', esc_html__( 'Settings', 'jet-dashboard' ), esc_html__( 'Settings', 'jet-dashboard' ), 'manage_options', add_query_arg( array( 'page' => 'jet-dashboard-settings-page', 'subpage' => 'jet-smart-filters-general-settings' ), admin_url( 'admin.php' ) ) ); } /** * Add admin mode switcher button in manage post panel */ public function add_admin_mode_switcher_button( $post_type ) { if ( 'jet-smart-filters' !== $post_type ) { return; } printf( '', esc_html__( 'Switch to New View', 'jet-smart-filters' ), esc_html__( 'Switching...', 'jet-smart-filters' ) ); } /** * Add index filter button in manage post panel */ public function add_index_filters_button( $post_type ) { if ( 'jet-smart-filters' !== $post_type ) { return; } printf( '', esc_html__( 'Index Filters', 'jet-smart-filters' ), esc_html__( 'Indexing...', 'jet-smart-filters' ) ); } /** * Return UI builder instance */ public function get_builder() { $data = jet_smart_filters()->framework->get_included_module_data( 'cherry-x-interface-builder.php' ); return new CX_Interface_Builder( array( 'path' => $data['path'], 'url' => $data['url'], ) ); } /** * Disable metaboxes from Jet Templates */ public function disable_metaboxes() { global $wp_meta_boxes; unset( $wp_meta_boxes[jet_smart_filters()->post_type->slug()]['side']['core']['pageparentdiv'] ); } /** * Actions posts */ public function remove_view_action( $actions, $post ) { if ( jet_smart_filters()->post_type->slug() === $post->post_type ) { unset( $actions['view'] ); } return $actions; } } }