'als-settings' ), admin_url( 'admin.php' ) ) ); } add_action( 'admin_init', 'als_admin_init' ); /** * Registers js and css that is used on the admin page * And localises our js with user options for ajax and live search **/ function als_frontend_scripts() { // load typeahead and our main script wp_register_script( 'typeahead_bundle', plugins_url( '/js/typeahead.bundle.js' , __FILE__ ), array( 'jquery' ), null, true); wp_register_script( 'als_functions', plugins_url( '/js/functions.js' , __FILE__ ), array( 'typeahead_bundle' ), null, true); // Pass variables to our js file, e.g url etc $params = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'home_url' => home_url(), 'nextNonce' =>wp_create_nonce('myajax-next-nonce'), 'als_search_behavior' => get_option('als_search_behavior', 'live'), ); // localize and enqueue the script with all of the variable inserted wp_localize_script( 'als_functions', 'als', $params ); wp_enqueue_script( 'als_functions' ); //Load our theme stylesheet wp_enqueue_style( 'als_style', plugins_url( '/styles/style.css', __FILE__)); } add_action( 'wp_enqueue_scripts', 'als_frontend_scripts' ); function als_admin_scripts() { wp_enqueue_style( 'wpe_bootstrap', plugins_url( '/styles/bootstrap.css', __FILE__)); } add_action( 'admin_enqueue_scripts', 'als_admin_scripts'); /** * Runs before the WP_Query class fetches posts * First we check if its the main query of a search page * Then fetch the posts containing the query * And pass their ids to WP_Query * * @param $query the query that is currently being accessed **/ function als_pre_get_posts($query){ if(!is_admin() && $query->is_main_query() && $query->is_search() ) { $search_term = apply_filters('als_search_string', sanitize_text_field($_GET['s'])); $results = als_search($search_term); $post_types = array_unique(als_index_post_types()); //We found results if($results) { $query->set('s', ''); $query->set('post__in', $results); } $args = array('author__in'=>array('sanitize'=>'als_is_array', 'value'=>apply_filters('als_author_in', array(), $search_term)), 'author__not_in'=>array('sanitize'=>'als_is_array', 'value'=>apply_filters('als_author_not_in', array(), $search_term)), 'author_name'=>array('sanitize'=>'als_is_string', 'value'=>apply_filters('als_author_name', '', $search_term)), 'cat'=>array('sanitize'=>'als_is_string', 'value'=>apply_filters('als_cat', '', $search_term)), 'category_name'=>array('sanitize'=>'als_is_string', 'value'=>apply_filters('als_category_name', '', $search_term)), 'category__in'=>array('sanitize'=>'als_is_array', 'value'=>apply_filters('als_category_in', array(), $search_term)), 'category__not_in'=>array('sanitize'=>'als_is_array', 'value'=>apply_filters('als_category_not_in', array(), $search_term)), 'tag'=>array('sanitize'=>'als_is_string', 'value'=>apply_filters('als_tag', '', $search_term)), 'tag__in'=>array('sanitize'=>'als_is_array', 'value'=>apply_filters('als_tag_in', array(), $search_term)), 'tag__not_in'=>array('sanitize'=>'als_is_array', 'value'=>apply_filters('als_tag_not_in', array(), $search_term)), 'post_type'=>array('sanitize'=>'als_is_array', 'value'=> apply_filters('als_wp_query_post_types', $post_types, $search_term)), 'date_query'=>array('sanitize'=>'als_is_array', 'value'=>apply_filters('als_date_query', array(), $search_term)), 'posts_per_page'=>array('sanitize'=>'als_is_string', 'value'=>apply_filters('als_posts_per_page', get_option('als_posts_per_page', 10), $search_term)) ); foreach($args as $arg=>$data){ if(!call_user_func($data['sanitize'], $data['value'])){ continue; } $query->set($arg, $data['value']); } $query->set('orderby', get_option('als_rank_by', 'post__in')); //author, title, type, date, rand, post_in, comment_count } } add_action( 'pre_get_posts', 'als_pre_get_posts', 10000 ); function als_remove_menus() { remove_submenu_page( 'index.php', 'als-welcome-screen-about' ); } add_action( 'admin_head', 'als_remove_menus' ); /** * Fires when post_content is being rendered * * @since 2.3.3 */ function als_custom_snippet( $content ) { //Are we allowed to snippetify this content if( !als_use_custom_snippets() ) return $content; global $post; return als_content_to_snippet( $post->post_content, $_GET['s'] ); $content = do_shortcode( $post->post_content ); $s = $_GET['s']; } add_filter( 'the_excerpt', 'als_custom_snippet', 20 ); add_filter( 'the_content', 'als_custom_snippet', 20 );