public function __construct($args = array()) { if (appthemes_get_search_index_status() || isset($_GET['firstrun'])) { return; } $defaults = array('limit' => 10); $this->args = wp_parse_args($args, $defaults); $this->args['limit'] = apply_filters('appthemes_build_search_index_limit', $this->args['limit']); $this->args['post_type'] = APP_SEARCH_INDEX::get_registered_post_types(); if (empty($this->args['post_type'])) { return; } add_action('init', array($this, 'process'), 101); add_filter('posts_clauses', array($this, 'filter_before'), 10, 2); if (is_admin()) { add_action('admin_notices', array($this, 'progress')); } }
/** * Handles updating search index via ajax */ public function ajax_build_index() { if ('POST' != $_SERVER['REQUEST_METHOD']) { die(json_encode(array('success' => false, 'completed' => false, 'message' => __('Sorry, only post method allowed', APP_TD)))); } if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'build-index')) { die(json_encode(array('success' => false, 'completed' => false, 'message' => __('Sorry, invalid request', APP_TD)))); } if (appthemes_get_search_index_status()) { die(json_encode(array('success' => true, 'completed' => true, 'message' => __('The search index has been built', APP_TD)))); } $speed = isset($_POST['speed']) ? (int) $_POST['speed'] : 100; $index_builder = new APP_Build_Search_Index(array('limit' => $speed)); $index_builder->process(); die(json_encode(array('success' => true, 'completed' => false, 'message' => __('This has already run', APP_TD)))); }
/** * Whether the Search Index is ready to use * * @return void */ function cp_search_index_enabled() { if (!current_theme_supports('app-search-index')) { return false; } return apply_filters('cp_search_index_enabled', appthemes_get_search_index_status()); }