Пример #1
0
 * touch. 
 */
add_filter('posts_search', function ($search, $query) {
    global $wpdb;
    if (!isset($query->query_vars['search_terms'])) {
        return $search;
    }
    if (isset($query->query_vars['suppress_filters']) && true == $query->query_vars['suppress_filters']) {
        return $search;
    }
    $episodesTable = \Podlove\Model\Episode::table_name();
    $search = '';
    $searchand = '';
    $n = !empty($query->query_vars['exact']) ? '' : '%';
    foreach ((array) $query->query_vars['search_terms'] as $term) {
        $term = esc_sql(\Podlove\esc_like($term));
        $search .= "\n\t\t\t{$searchand}\n\t\t\t(\n\t\t\t\t({$wpdb->posts}.post_title LIKE '{$n}{$term}{$n}')\n\t\t\t\tOR\n\t\t\t\t({$wpdb->posts}.post_content LIKE '{$n}{$term}{$n}')\n\t\t\t\tOR\n\t\t\t\t({$episodesTable}.subtitle LIKE '{$n}{$term}{$n}')\n\t\t\t\tOR\n\t\t\t\t({$episodesTable}.summary LIKE '{$n}{$term}{$n}')\n\t\t\t\tOR\n\t\t\t\t({$episodesTable}.chapters LIKE '{$n}{$term}{$n}')\n\t\t\t)";
        $searchand = ' AND ';
    }
    if (!empty($search)) {
        $search = " AND ({$search}) ";
        if (!is_user_logged_in()) {
            $search .= " AND ({$wpdb->posts}.post_password = '') ";
        }
    }
    return $search;
}, 10, 2);
// join into episode table in WordPress searches so we can access episode fields
add_filter('posts_join', function ($join, $query) {
    global $wpdb;
    if ($query->is_feed()) {
 public function prepare_items()
 {
     global $wpdb;
     // number of items per page
     $per_page = get_user_meta(get_current_user_id(), 'podlove_contributors_per_page', true);
     if (empty($per_page)) {
         $per_page = 10;
     }
     // define column headers
     $this->_column_headers = $this->get_column_info();
     // look for order options
     if (isset($_GET['orderby'])) {
         $orderby = 'ORDER BY ' . esc_sql($_GET['orderby']);
     } else {
         $orderby = 'ORDER BY contributioncount';
     }
     // look how to sort
     if (filter_input(INPUT_GET, 'order') === 'ASC') {
         $order = 'ASC';
     } else {
         $order = 'DESC';
     }
     // retrieve data
     if (!isset($_POST['s']) || empty($_POST['s'])) {
         $data = \Podlove\Modules\Contributors\Model\Contributor::all($orderby . ' ' . $order);
     } else {
         $search = \Podlove\esc_like($_POST['s']);
         $search = '%' . $search . '%';
         $search_columns = ['slug', 'gender', 'organisation', 'slug', 'department', 'jobtitle', 'privateemail', 'realname', 'publicname', 'guid'];
         $search_columns = apply_filters('podlove_contributor_list_table_search_db_columns', $search_columns);
         $like_searches = implode(' OR ', array_map(function ($column) use($search) {
             return '`' . $column . '` LIKE \'' . $search . '\'';
         }, $search_columns));
         $data = \Podlove\Modules\Contributors\Model\Contributor::all('WHERE ' . $like_searches . ' ' . $orderby . ' ' . $order);
     }
     // get current page
     $current_page = $this->get_pagenum();
     // get total items
     $total_items = count($data);
     // extrage page for current page only
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     // add items to table
     $this->items = $data;
     // register pagination options & calculations
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
     // Search box
     $this->search_form();
 }
Пример #3
0
 public static function table_exists()
 {
     global $wpdb;
     $sql = $wpdb->prepare("SHOW TABLES LIKE %s", \Podlove\esc_like(self::table_name()));
     return $wpdb->get_var($sql) !== null;
 }