'slug', 'plural' => 'slugs' )); $this->displayed_post_statuses = (isset($permalink_manager_options['screen-options']['post_statuses'])) ? "'" . implode("', '", $permalink_manager_options['screen-options']['post_statuses']) . "'" : "'no-post-status'"; $this->displayed_post_types = ($active_subsection && $active_subsection == 'all') ? "'" . implode("', '", $permalink_manager_options['screen-options']['post_types']) . "'" : "'{$active_subsection}'"; } /** * Get the HTML output with the WP_List_Table */ public function display_admin_section() { global $wpdb; $output = "
"; return $output; } function get_table_classes() { return array( 'widefat', 'striped', $this->_args['plural'] ); } /** * Override the parent columns method. Defines the columns to use in your listing table */ public function get_columns() { return apply_filters('permalink_manager_uri_editor_columns', array( 'item_title' => __('Post title', 'permalink-manager'), 'item_uri' => __('Full URI & Permalink', 'permalink-manager') )); } /** * Hidden columns */ public function get_hidden_columns() { return array(); } /** * Sortable columns */ public function get_sortable_columns() { return array( 'item_title' => array('post_title', false) ); } /** * Data inside the columns */ public function column_default($item, $column_name) { global $permalink_manager_options; $uri = Permalink_Manager_URI_Functions_Post::get_post_uri($item['ID'], true); $uri = (!empty($permalink_manager_options['general']['decode_uris'])) ? urldecode($uri) : $uri; $field_args_base = array('type' => 'text', 'value' => $uri, 'without_label' => true, 'input_class' => 'custom_uri', 'extra_atts' => "data-element-id=\"{$item['ID']}\""); $permalink = get_permalink($item['ID']); $post_statuses_array = get_post_statuses(); $post_statuses_array['inherit'] = __('Inherit (Attachment)', 'permalink-manager'); $output = apply_filters('permalink_manager_uri_editor_column_content', '', $column_name, get_post($item['ID'])); if(!empty($output)) { return $output; } switch( $column_name ) { case 'item_uri': // Get auto-update settings $auto_update_val = get_post_meta($item['ID'], "auto_update_uri", true); $auto_update_uri = (!empty($auto_update_val)) ? $auto_update_val : $permalink_manager_options["general"]["auto_update_uris"]; if($auto_update_uri) { $field_args_base['readonly'] = true; $field_args_base['append_content'] = sprintf('%s %s
', '', __('The above permalink will be automatically updated and is locked for editing.', 'permalink-manager')); } $output = '"; $output .= ""; $output .= Permalink_Manager_Admin_Functions::generate_option_field('s', array('value' => $search_query, 'type' => 'search')); $output .= get_submit_button($text, 'button', false, false, array('id' => 'search-submit', 'name' => 'search-submit')); $output .= "
"; return $output; } /** * Prepare the items for the table to process */ public function prepare_items() { global $wpdb, $permalink_manager_options; $columns = $this->get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $current_page = $this->get_pagenum(); // Get query variables $per_page = $permalink_manager_options['screen-options']['per_page']; // SQL query parameters $order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? sanitize_sql_orderby($_REQUEST['order']) : 'desc'; $orderby = (isset($_REQUEST['orderby'])) ? sanitize_sql_orderby($_REQUEST['orderby']) : 'ID'; $offset = ($current_page - 1) * $per_page; $search_query = (!empty($_REQUEST['s'])) ? esc_sql($_REQUEST['s']) : ""; // Extra filters $extra_filters = $attachment_support = ''; if(!empty($_GET['month'])) { $month = date("n", strtotime($_GET['month'])); $year = date("Y", strtotime($_GET['month'])); $extra_filters .= "AND month(post_date) = {$month} AND year(post_date) = {$year}"; } // Support for attachments if(strpos($this->displayed_post_types, 'attachment') !== false) { $attachment_support = " OR (post_type = 'attachment')"; } // Grab posts from database $sql_parts['start'] = "SELECT * FROM {$wpdb->posts} "; if($search_query) { $sql_parts['where'] = "WHERE (LOWER(post_title) LIKE LOWER('%{$search_query}%') "; // Search in array with custom URIs $found = Permalink_Manager_Helper_Functions::search_uri($search_query, 'posts'); if($found) { $sql_parts['where'] .= sprintf("OR ID IN (%s)", implode(',', (array) $found)); } $sql_parts['where'] .= " ) AND ((post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types)) {$attachment_support}) {$extra_filters} "; } else { $sql_parts['where'] = "WHERE ((post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types)) {$attachment_support}) {$extra_filters} "; } // Do not display excluded posts in Bulk URI Editor $excluded_posts = (array) apply_filters('permalink_manager_excluded_post_ids', array()); if(!empty($excluded_posts)) { $sql_parts['where'] .= sprintf("AND ID NOT IN ('%s') ", implode("', '", $excluded_posts)); } $sql_parts['end'] = "ORDER BY {$orderby} {$order}"; // Prepare the SQL query $sql_query = implode("", $sql_parts); // Count items $count_query = str_replace('SELECT *', 'SELECT COUNT(*)', $sql_query); $total_items = $wpdb->get_var($count_query); // Pagination support $sql_query .= sprintf(" LIMIT %d, %d", $offset, $per_page); // Get items $sql_query = apply_filters('permalink_manager_filter_uri_editor_query', $sql_query, $this, $sql_parts, $is_taxonomy = false); $all_items = $wpdb->get_results($sql_query, ARRAY_A); // Debug SQL query if(isset($_REQUEST['debug_editor_sql'])) { $debug_txt = ""; wp_die($debug_txt); } $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => $per_page )); $this->_column_headers = array($columns, $hidden, $sortable); $this->items = $all_items; } }