文件操作 - module.php
返回文件管理
返回主菜单
删除本文件
文件: /root/Desktop/OLD/plugin-wordpress/bdthemes-element-pack-lite/modules/search/module.php
编辑文件内容
<?php namespace ElementPack\Modules\Search; use ElementPack\Base\Element_Pack_Module_Base; if (!defined('ABSPATH')) exit; // Exit if accessed directly class Module extends Element_Pack_Module_Base { public function __construct() { parent::__construct(); $this->add_actions(); } public function get_name() { return 'search'; } public function get_widgets() { $widgets = [ 'Search', ]; return $widgets; } /** * @param array $term_ids * @return array */ private function mapGroupControlQuery($term_ids = []) { $terms = get_terms( [ 'term_taxonomy_id' => $term_ids, 'hide_empty' => false, ] ); $tax_terms_map = []; foreach ($terms as $term) { $taxonomy = $term->taxonomy; $tax_terms_map[$taxonomy][] = $term->term_id; } return $tax_terms_map; } public function element_pack_ajax_search() { global $post; $result = array('results' => array()); $search_input = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; $settings = $_POST['settings']; // var_dump($settings); // die(); if (strlen($search_input) >= 3) { $query_args = [ 'post_type' => $settings['post_type'], 's' => $search_input, 'posts_per_page' => ($settings['per_page']) ? $settings['per_page'] : 5, 'post_status' => 'publish', // 'author_name' => $settings['author_name'] ]; /** * Set Authors */ $include_users = []; $exclude_users = []; if (!empty($settings['include_author_ids'])) { if (in_array('authors', $settings['include_by'])) { $include_users = wp_parse_id_list($settings['include_author_ids']); } } if (!empty($settings['exclude_author_ids'])) { if (in_array('authors', $settings['exclude_by'])) { $exclude_users = wp_parse_id_list($settings['exclude_author_ids']); $include_users = array_diff($include_users, $exclude_users); } } if (!empty($include_users)) { $query_args['author__in'] = $include_users; } if (!empty($exclude_users)) { $query_args['author__not_in'] = $exclude_users;; } /** * Set Taxonomy */ $include_terms = []; $exclude_terms = []; $terms_query = []; if (!empty($settings['include_term_ids'])) { if (in_array('terms', $settings['include_by'])) { $include_terms = wp_parse_id_list($settings['include_term_ids']); } } if (!empty($settings['exclude_term_ids'])) { if (in_array('terms', $settings['exclude_by'])) { $exclude_terms = wp_parse_id_list($settings['exclude_term_ids']); $include_terms = array_diff($include_terms, $exclude_terms); } } if (!empty($include_terms)) { $tax_terms_map = $this->mapGroupControlQuery($include_terms); foreach ($tax_terms_map as $tax => $terms) { $terms_query[] = [ 'taxonomy' => $tax, 'field' => 'term_id', 'terms' => $terms, 'operator' => 'IN', ]; } } if (!empty($exclude_terms)) { $tax_terms_map = $this->mapGroupControlQuery($exclude_terms); foreach ($tax_terms_map as $tax => $terms) { $terms_query[] = [ 'taxonomy' => $tax, 'field' => 'term_id', 'terms' => $terms, 'operator' => 'NOT IN', ]; } } if (!empty($terms_query)) { $query_args['tax_query'] = $terms_query; $query_args['tax_query']['relation'] = 'AND'; } $query = new \WP_Query($query_args); while ($query->have_posts()) { $query->the_post(); $content = !empty($post->post_excerpt) ? strip_tags(strip_shortcodes($post->post_excerpt)) : strip_tags(strip_shortcodes($post->post_content)); if (strlen($content) > 180) { $content = substr($content, 0, 179) . '...'; } $result['results'][] = array( 'title' => get_the_title(), 'text' => $content, 'url' => get_permalink($post->ID), ); } } die(json_encode($result)); } protected function add_actions() { // TODO AJAX SEARCH add_action('wp_ajax_element_pack_search', [$this, 'element_pack_ajax_search']); add_action('wp_ajax_nopriv_element_pack_search', [$this, 'element_pack_ajax_search']); } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件