*/ class Admin_Live_Search_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; private $screen; private $screen_id; private $cpt_status; private $is_list_page; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; add_action( 'admin_menu', 'admin_live_search_menu' ); function admin_live_search_menu() { add_options_page( 'Options', 'Admin Live Search', 'manage_options', 'admin-live-search.php', 'Admin_Live_Search_Admin::admin_live_search_help' ); } add_filter( 'plugin_action_links_' . ADMIN_LIVE_SEARCH_BASE, 'Admin_Live_Search_Admin::admin_live_search_links' ); $this->is_list_page = false; add_action( 'current_screen', array( $this, 'setup_screen' ) ); add_action( 'check_ajax_referer', array( $this, 'setup_screen' ) ); add_action( 'admin_head', array( $this, 'add_screen_js' ) ); add_filter( 'query_vars', array( $this, 'register_query_vars' ) ); $this->cpt_status = (get_option('admin_live_search_cpt_status',false) == 1); add_action( 'admin_notices', array( $this, 'admin_notices' ) ); } public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/admin-live-search-admin.css', array(), $this->version, 'all' ); } public function enqueue_scripts() { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/admin-live-search-admin.js', array( 'jquery' ), $this->version, false ); } public function add_screen_js(){ echo ''; ?> id ) ? $screen->id : ''; } if ( ! empty( $_REQUEST['screen'] ) ) { // WPCS: input var ok. $screen_id = als_clean( wp_unslash( $_REQUEST['screen'] ) ); // WPCS: input var ok, sanitization ok. } $this->screen_id = $screen_id; $this->screen = $this->screen; $this->is_list_page = false; if ( $this->screen_id == 'edit-post') $this->is_list_page = true; if ( $this->screen_id == 'edit-page') $this->is_list_page = true; if ( substr($this->screen_id,0,5) == 'edit-' && isset($_REQUEST['post_type'])) $this->is_list_page = true; // Ensure the table handler is only loaded once. Prevents multiple loads if a plugin calls check_ajax_referer many times. remove_action( 'current_screen', array( $this, 'setup_screen' ) ); remove_action( 'check_ajax_referer', array( $this, 'setup_screen' ) ); } public function admin_live_search() { $_url = esc_url($_REQUEST['url']); $_base = get_site_url(); // extra security check if ( $_base != substr($_url,0,strlen($_base)) ) { wp_die(); } $_admin_live_search_filter = intval( $_REQUEST['admin_live_search_filter']); $_keyword = sanitize_text_field($_REQUEST['keyword']); $_params = sanitize_text_field($_REQUEST['fields']); $_url_get = $_GET; parse_str($_params, $_REQUEST); parse_str($_params, $_GET); parse_str($_params, $params); // fix because of punctuation and special chars $_REQUEST['s'] = $_keyword; global $post_type, $post_type_object; ob_start(); if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) $typenow = $_REQUEST['post_type']; else $typenow = ''; if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) $taxnow = $_REQUEST['taxonomy']; else $taxnow = ''; $pagenow = 'edit.php'; $GLOBALS['hook_suffix'] = $typenow; do_action( 'admin_init' ); do_action( 'setup_screen' ); $_screen = set_current_screen(); do_action( "load-{$pagenow}" ); $post_type = $typenow; $post_type_object = get_post_type_object( $post_type ); if ( ! $post_type_object ) wp_die( __( 'Invalid post type.' ) ); if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) { wp_die( '

' . __( 'You need a higher level of permission.' ) . '

' . '

' . __( 'Sorry, you are not allowed to edit posts in this post type.' ) . '

', 403 ); } // $wp_list_table = _get_list_table('WP_Posts_List_Table', array( 'screen' => $this->screen_id )); if ( isset( $this->screen_id ) ) $this->screen_id = convert_to_screen( $this->screen_id ); elseif ( isset( $GLOBALS['hook_suffix'] ) ) $this->screen_id = get_current_screen(); else $this->screen_id = null; $wp_list_table = new Admin_Live_Search_Posts_List_Table( array( 'screen' => $this->screen_id , 'admin_live_search_filter' => $_admin_live_search_filter , 'request' => $_url_get) ); $pagenum = $wp_list_table->get_pagenum(); if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { printf( ' ' . __( 'Search results for “%s”' ) . ' (via '. 'Admin Live Search' . ')' . '', sanitize_text_field($_REQUEST['s']) ); } $wp_list_table->prepare_items(); $wp_list_table->views(); $wp_list_table->display(); if ( $wp_list_table->has_items() ) $wp_list_table->inline_edit(); ?>

Admin Live Search


'; ?> '; ?> '; ?>
'; ?> '; ?>

' . __( 'Enable Admin Live Search for Custom Post Types', 'admin-live-search' ).'
'; ?>


'; ?> '; ?> ' . esc_attr__( 'Contact Support', 'admin-live-search' ) . '' . '
'; ?>

' . esc_attr__( 'Contact Support', 'admin-live-search' ) . '' .'
'; ?>

libberry ) '; ?> graingert )'; ?>

'; ?> '; ?> ★★★★★', 'wordpress.org' ),__( 'Add your [icon] on [wporg] to spread the love.', 'admin-live-search' ) ) .'
'; ?> '. __('Donate') .'
'; ?>
'; ?>


%s',add_query_arg(['page' => 'admin-live-search.php',],admin_url('options-general.php') ), __("Settings")),]); } public function admin_live_search_set_cpt_status() { if ( $_GET['admin_live_search_cpt_status_chkbox'] == 1 ) { update_option('admin_live_search_cpt_status', 1); } else { update_option('admin_live_search_cpt_status', 0); } wp_die(); } public function admin_notices(){ $show_cpt_notice = false; if (isset($_REQUEST['post_type'])) { if ( $_REQUEST['post_type'] != 'page' && $_REQUEST['post_type'] != 'post' ) $show_cpt_notice = true; } if ( $this->is_list_page && $show_cpt_notice && get_option('admin_live_search_cpt_status') != 1 ) { ?>

Admin Live Search '. __( 'Why?', 'admin-live-search' ) . ''; ?>