Skip to content

Commit

Permalink
Merge pull request #638 from publishpress/feature/#510_Add_filter_sea…
Browse files Browse the repository at this point in the history
…rch_and_pagination_to_Publish_Series_screen

 feature/#510_Add_filter_search_and_pagination_to_Publish_Series_screen
  • Loading branch information
olatechpro committed Sep 22, 2022
2 parents eae21f4 + 61705d7 commit bcddf60
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 42 deletions.
32 changes: 16 additions & 16 deletions addons/grouping/legacy-includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
add_action('edited_'.ppseries_get_series_slug().'', 'wp_update_series_group', 1, 2);
add_action('delete_'.ppseries_get_series_slug().'', 'wp_delete_series_group', 1, 2);

//render series group template
//render Series Category template
add_filter('template_include','pp_series_group_template');

add_action('pp_series_advanced_tab_top', 'series_grouping_delete_output');
Expand Down Expand Up @@ -125,7 +125,7 @@ function upgrade_orgseries_grouping_from_one_five() {
//if ( !taxonomy_exists('series_group') )
//orgseries_grouping_taxonomy();

//let's get all the existing series groups in the old category system
//let's get all the existing Series Categories in the old category system
$args = array(
'hide_empty' => false,
'fields' => 'ids',
Expand Down Expand Up @@ -214,16 +214,16 @@ function orgseries_grouping_taxonomy() {
'assign_terms' => 'manage_series'
);
$labels = array(
'name' => _x('Manage Series Groups', 'taxonomy general name', 'organize-series'),
'singular_name' => _x('Series Group', 'taxonomy singular name', 'organize-series'),
'search_items' => __('Search Series Groups', 'organize-series'),
'popular_items' => __('Popular Series Groups', 'organize-series'),
'all_items' => __('All Series Groups', 'organize-series'),
'edit_item' => __('Edit Series Group', 'organize-series'),
'update_item' => __('Update Series Group', 'organize-series'),
'add_new_item' => __('Add New Series Group', 'organize-series'),
'new_item_name' => __('New Series Group', 'organize-series'),
'menu_name' => __('Series Groups', 'organize-series')
'name' => _x('Manage Series Categories', 'taxonomy general name', 'organize-series'),
'singular_name' => _x('Series Category', 'taxonomy singular name', 'organize-series'),
'search_items' => __('Search Series Categories', 'organize-series'),
'popular_items' => __('Popular Series Categories', 'organize-series'),
'all_items' => __('All Series Categories', 'organize-series'),
'edit_item' => __('Edit Series Category', 'organize-series'),
'update_item' => __('Update Series Category', 'organize-series'),
'add_new_item' => __('Add New Series Category', 'organize-series'),
'new_item_name' => __('New Series Category', 'organize-series'),
'menu_name' => __('Series Categories', 'organize-series')
);
$args = array(
'update_count_callback' => 'update_series_group_count',
Expand Down Expand Up @@ -273,7 +273,7 @@ function orgseries_grouping_import_existing_series() {
}

function orgseries_groups_admin_menu() {
add_submenu_page( 'edit.php', 'Manage Series Groups', 'Series Groups', 'manage_series', 'edit-tags.php?taxonomy=series_group');
add_submenu_page( 'edit.php', 'Manage Series Categories', 'Series Categories', 'manage_series', 'edit-tags.php?taxonomy=series_group');
}

function orgseries_group_add_queryvars($qvs) {
Expand Down Expand Up @@ -329,7 +329,7 @@ function orgseries_manage_grouping_columns() {
}

function orgseries_grouping_settings_setup() {
//add_settings_field('series_grouping_delete_settings','Series Grouping Addon Settings','series_grouping_delete_output', 'orgseries_options_page','series_uninstall_settings');
//add_settings_field('series_grouping_delete_settings','Series Categories Addon Settings','series_grouping_delete_output', 'orgseries_options_page','series_uninstall_settings');
register_setting('orgseries_options', 'org_series_options');
add_filter('orgseries_options', 'series_grouping_options_validate', 10, 2);
}
Expand All @@ -347,13 +347,13 @@ function series_grouping_delete_output() {
?>
<tr valign="top">
<th scope="row"><label for="kill_grouping_on_delete">
<?php _e('Series Grouping Feature', 'organize-series'); ?>
<?php _e('Series Categories Feature', 'organize-series'); ?>
</label>
</th>
<td>
<label>
<input name="<?php echo $org_name; ?>[kill_grouping_on_delete]" id="kill_grouping_on_delete" type="checkbox" value="1" <?php checked('1', $k_on_delete); ?> />
<span class="description"><?php _e('Delete all "Series Grouping" data from the database when deleting the plugin.', 'organize-series'); ?></span>
<span class="description"><?php _e('Delete all "Series Categories" data from the database when deleting the plugin.', 'organize-series'); ?></span>
</label>
</td>
</tr>
Expand Down
4 changes: 0 additions & 4 deletions addons/publisher/css/series_im_sort_articles.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.pp-series-publisher-wrap .tablenav.top {
display: none;
}

.pp-series-publisher-wrap .inner-sidebar #side-sortables {
width: 300px;
}
Expand Down
150 changes: 129 additions & 21 deletions addons/publisher/series-publish-post-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ public function get_table_data(){
$series_posts = [];

if ($series_id) {
$per_page = $this->get_items_per_page('pp_series_publisher_per_page', 20);
$current_page = $this->get_pagenum();

$arg = array(
'post_status' => ['future', 'draft', 'pending'],
'posts_per_page' => -1,
'no_found_rows' => true,
'paged' => $current_page,
'posts_per_page' => $per_page,
'tax_query' => array(
'relation' => 'AND',
array(
Expand All @@ -91,13 +94,130 @@ public function get_table_data(){
)
),
);

/**
* Handle category filter
*/
if ((!empty($_REQUEST['cat'])) && $category = sanitize_text_field($_REQUEST['cat'])) {
$arg['tax_query'][] = [
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array($category)
];
}

/**
* Handle search
*/
if ((!empty($_REQUEST['s'])) && $search = sanitize_text_field($_REQUEST['s'])) {
$arg['s'] = $search;
}

$series_query = new WP_Query($arg);
$series_posts = $series_query->posts;

return ['posts'=> $series_query->posts, 'counts'=> $series_query->found_posts];
}

return $series_posts;
}

/**
* Returns the count of records in the database.
*
* @return null|string
*/
public static function record_count()
{
return $this->get_table_data()['counts'];
}


/**
* Add custom filter to tablenav
*
* @param string $which
*/
protected function extra_tablenav( $which ) {

if ( 'top' === $which ) {

$taxonomies = get_all_taxopress_public_taxonomies();
$selected_category = (!empty($_REQUEST['cat'])) ? sanitize_text_field($_REQUEST['cat']) : '';
?>
<div class="alignleft actions">
<?php
wp_dropdown_categories(
array(
'show_option_all' => __( 'All Categories', 'organize-series' ),
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'hide_if_empty' => true,
'selected' => $selected_category,
'hierarchical' => true,
'name' => 'cat',
'taxonomy' => 'category',
'value_field' => 'slug',
)
);

submit_button( __( 'Filter', 'organize-series' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
?>
</div>
<?php
}
}

/**
* Displays the search box.
*
* @param string $text The 'submit' button label.
* @param string $input_id ID attribute value for the search input field.
*
*
*/
public function search_box($text, $input_id)
{
if (!isset($_REQUEST['s']) && !$this->has_items()) {
return;
}

$input_id = $input_id . '-search-input';

if (!empty($_REQUEST['orderby'])) {
echo '<input type="hidden" name="orderby" value="' . esc_attr(sanitize_text_field($_REQUEST['orderby'])) . '" />';
}
if (!empty($_REQUEST['order'])) {
echo '<input type="hidden" name="order" value="' . esc_attr(sanitize_text_field($_REQUEST['order'])) . '" />';
}
if (!empty($_REQUEST['page'])) {
echo '<input type="hidden" name="page" value="' . esc_attr(sanitize_text_field($_REQUEST['page'])) . '" />';
}
if (!empty($_REQUEST['action'])) {
echo '<input type="hidden" name="action" value="' . esc_attr(sanitize_text_field($_REQUEST['action'])) . '" />';
}
if (!empty($_REQUEST['series_ID'])) {
echo '<input type="hidden" name="series_ID" value="' . esc_attr(sanitize_text_field($_REQUEST['series_ID'])) . '" />';
}
if (!empty($_REQUEST['cat'])) {
echo '<input type="hidden" name="cat" value="' . esc_attr(sanitize_text_field($_REQUEST['cat'])) . '" />';
}

if (!empty($_REQUEST['s'])) {
echo '<input type="hidden" name="s" value="' . esc_attr(sanitize_text_field($_REQUEST['s'])) . '" />';
}

echo '<input type="hidden" name="action" value="list" />';
?>
<p class="search-box">
<label class="screen-reader-text" for="<?php echo esc_attr($input_id); ?>"><?php echo esc_html($text); ?>:</label>
<input type="search" id="<?php echo esc_attr($input_id); ?>" name="s"
value="<?php _admin_search_query(); ?>"/>
<?php submit_button($text, '', '', false, ['id' => 'taxopress-log-search-submit']); ?>
</p>
<?php
}

/**
* Generates and display row actions links for the list table.
*
Expand Down Expand Up @@ -294,42 +414,30 @@ protected function get_bulk_actions()
*/
public function prepare_items()
{

/**
* First, lets decide how many records per page to show
*/
$per_page = $this->get_items_per_page(str_replace('-', '_', $this->screen->id . '_per_page'), 999);

$per_page = $this->get_items_per_page('pp_series_publisher_per_page', 20);

/**
* Fetch the data
*/
$data = $this->get_table_data();

/**
* Pagination.
*/
$results = $this->get_table_data();
$data = $results['posts'];
$total_items = $results['counts'];
$current_page = $this->get_pagenum();
$total_items = count($data);


/**
* The WP_List_Table class does not handle pagination for us, so we need
* to ensure that the data is trimmed to only the current page. We can use
* array_slice() to
*/
$data = array_slice($data, (($current_page - 1) * $per_page), $per_page);

/**
* Now we can add the data to the items property, where it can be used by the rest of the class.
*/
$this->items = $data;

/**
* We also have to register our pagination options & calculations.
*/
$this->set_pagination_args([
'total_items' => $total_items, //calculate the total number of items
'per_page' => $per_page, //determine how many items to show on a page
'per_page' => $per_page, //determine how many items to show on a page
'total_pages' => ceil($total_items / $per_page) //calculate the total number of pages
]);
}
Expand Down
24 changes: 23 additions & 1 deletion addons/publisher/series_issue_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,15 @@ public function series_issue_manager_scripts()
public function screen_option()
{
if(isset($_GET['action']) && $_GET['action'] === 'list'){
$option = 'per_page';
$args = [
'label' => esc_html__('Number of items per page', 'organize-series'),
'default' => 20,
'option' => 'pp_series_publisher_per_page'
];
include_once 'series-publish-post-table.php';
$this->series_publish_table = new PPS_Publisher_Post_Publish_Table();

add_screen_option($option, $args);
}
if(isset($_GET['action']) && ($_GET['action'] === 'part' || $_GET['action'] === 'order')){
include_once 'series-part-post-table.php';
Expand Down Expand Up @@ -616,10 +622,26 @@ public function ppseries_publisher_publish_output($series_ID)
<h1><?php esc_html_e('Publishing Series:', 'organize-series'); ?>
<?php echo esc_html($series->name); ?>
</h1>
<?php
if (isset($_REQUEST['s']) && $search = esc_attr(sanitize_text_field(wp_unslash($_REQUEST['s'])))) {
/* translators: %s: search keywords */
printf(' <span class="subtitle">' . esc_html__('Search results for &#8220;%s&#8221;',
'organize-series') . '</span>', esc_html($search));
}
?>
<div id="poststuff">

<div id="post-body" class="metabox-holder columns-2">

<div id="post-body-content" style="position: relative;">

<hr class="wp-header-end">
<div id="ajax-response"></div>
<form class="search-form wp-clearfix series-publisher-search" method="get">
<?php $this->series_publish_table->search_box(esc_html__('Search', 'organize-series'), 'search'); ?>
</form>
<div class="clear"></div>

<form action="<?php echo esc_url(add_query_arg('', '')); ?>" method="post">
<?php

Expand Down

0 comments on commit bcddf60

Please sign in to comment.