Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update/#1772-Add-settings-to-control-the-maximum-number-of-posts-on-Content-Overview-and-Board-page #1783

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion modules/content-board/content-board.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public function __construct()
'period' => 'weeks'
],

'posts_per_page' => 200,

'post_types' => [
'post' => 'on',
'page' => 'off',
Expand Down Expand Up @@ -939,6 +941,7 @@ public function table_navigation()
$args['form_filter_list'] = $this->form_filter_list;
$args['all_filters'] = $this->filters;
$args['terms_options'] = $this->terms_options;
$args['posts_per_page'] = $this->module->options->posts_per_page;
$args['operator_labels'] = $this->meta_query_operator_label();
$args['post_statuses'] = $this->get_post_statuses();
$args['post_status_options'] = '';
Expand Down Expand Up @@ -1346,7 +1349,7 @@ public function getPostsForPostType($postType, $args = null)
$defaults = [
'post_status' => null,
'author' => null,
'posts_per_page' => (int)apply_filters('PP_Content_Board_max_query', 200),
'posts_per_page' => $this->module->options->posts_per_page,
];

$args = array_merge($defaults, $args);
Expand Down
8 changes: 8 additions & 0 deletions modules/content-board/library/content-board-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ public function update_content_board_form_action() {

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo pp_planner_admin_notice(esc_html__('Filter updated successfully.', 'publishpress'));
} elseif (!empty($_POST['co_form_action']) && !empty($_POST['_nonce']) && $_POST['co_form_action'] == 'settings_form' && wp_verify_nonce(sanitize_key($_POST['_nonce']), 'content_board_settings_form_nonce')) {
// Content Board filter form
$posts_per_page = !empty($_POST['posts_per_page']) ? (int) $_POST['posts_per_page'] : 200;

$publishpress->update_module_option($this->module->name, 'posts_per_page', $posts_per_page);

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo pp_planner_admin_notice(esc_html__('Settings updated successfully.', 'publishpress'));
} elseif (!empty($_POST['co_form_action']) && !empty($_POST['_nonce']) && !empty($_POST['ptype']) && $_POST['co_form_action'] == 'post_form' && wp_verify_nonce(sanitize_key($_POST['_nonce']), 'content_board_post_form_nonce')) {
$postType = sanitize_text_field($_POST['ptype']);
$postTypeObject = get_post_type_object($postType);
Expand Down
27 changes: 27 additions & 0 deletions modules/content-board/library/content-board-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static function table_navigation($args)
$editable_post_types = $args['editable_post_types'];
$user_filters = $args['user_filters'];
$board_filters = $args['board_filters'];
$posts_per_page = $args['posts_per_page'];
?>
<div class="pp-content-board-manage">
<div class="left-items">
Expand Down Expand Up @@ -49,6 +50,32 @@ public static function table_navigation($args)
<div class="item action" id="print_link">
<span class="dashicons dashicons-printer"></span> <?php esc_html_e('Print', 'publishpress'); ?>
</div>
<?php $modal_id++; ?>
<div data-target="#content_board_modal_<?php echo esc_attr($modal_id); ?>" class="co-filter item action active-filter">
<span class="dashicons dashicons-admin-generic"></span>
</div>
<div id="content_board_modal_<?php echo esc_attr($modal_id); ?>" class="content-board-modal" style="display: none;">
<div class="content-board-modal-content">
<span class="close">&times;</span>
<div>
<div class="metadata-item-filter custom-filter">
<div class="filter-title">
<?php esc_html_e('Maximum Post Results', 'publishpress'); ?>
</div>
<div class="filter-content">
<form method="POST">
<input type="hidden" name="co_form_action" value="settings_form"/>
<input type="hidden" name="_nonce" value="<?php echo esc_attr(wp_create_nonce('content_board_settings_form_nonce')); ?>"/>
<input required type="number" step="1" min="1" max="999" id="pp_posts_per_page" name="posts_per_page" value="<?php echo esc_attr($posts_per_page); ?>">
<div class="filter-apply">
<input type="submit" id="filter-submit" class="button button-primary" value="<?php esc_attr_e('Apply Changes', 'publishpress'); ?>">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="right-items">
<?php if (!empty($editable_post_types)) : ?>
Expand Down
13 changes: 12 additions & 1 deletion modules/content-overview/content-overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public function __construct()
'content_overview_filters' => '',
'content_overview_custom_filters' => '',

'posts_per_page' => 200,

'post_types' => [
'post' => 'on',
'page' => 'off',
Expand Down Expand Up @@ -855,6 +857,14 @@ public function update_content_overview_form_action() {

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo pp_planner_admin_notice(esc_html__('Filter updated successfully.', 'publishpress'));
} elseif (!empty($_POST['co_form_action']) && !empty($_POST['_nonce']) && $_POST['co_form_action'] == 'settings_form' && wp_verify_nonce(sanitize_key($_POST['_nonce']), 'content_overview_settings_form_nonce')) {
// Content Board filter form
$posts_per_page = !empty($_POST['posts_per_page']) ? (int) $_POST['posts_per_page'] : 200;

$publishpress->update_module_option($this->module->name, 'posts_per_page', $posts_per_page);

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo pp_planner_admin_notice(esc_html__('Settings updated successfully.', 'publishpress'));
} elseif (!empty($_POST['co_form_action']) && !empty($_POST['_nonce']) && !empty($_POST['ptype']) && $_POST['co_form_action'] == 'post_form' && wp_verify_nonce(sanitize_key($_POST['_nonce']), 'content_overview_post_form_nonce')) {
$postType = sanitize_text_field($_POST['ptype']);
$postTypeObject = get_post_type_object($postType);
Expand Down Expand Up @@ -1229,6 +1239,7 @@ public function table_navigation()
$args['form_filter_list'] = $this->form_filter_list;
$args['all_filters'] = $this->filters;
$args['terms_options'] = $this->terms_options;
$args['posts_per_page'] = $this->module->options->posts_per_page;
$args['operator_labels'] = $this->meta_query_operator_label();
$args['post_statuses'] = $this->get_post_statuses();
$args['post_status_options'] = '';
Expand Down Expand Up @@ -1442,7 +1453,7 @@ public function getPostsForPostType($postType, $args = null)
$defaults = [
'post_status' => null,
'author' => null,
'posts_per_page' => (int)apply_filters('PP_Content_Overview_max_query', 200),
'posts_per_page' => $this->module->options->posts_per_page,
];

$args = array_merge($defaults, $args);
Expand Down
27 changes: 27 additions & 0 deletions modules/content-overview/library/content-overview-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static function table_navigation($args)
$editable_post_types = $args['editable_post_types'];
$user_filters = $args['user_filters'];
$overview_filters = $args['overview_filters'];
$posts_per_page = $args['posts_per_page'];
?>
<div class="pp-content-overview-manage">
<div class="left-items">
Expand Down Expand Up @@ -49,6 +50,32 @@ public static function table_navigation($args)
<div class="item action" id="print_link">
<span class="dashicons dashicons-printer"></span> <?php esc_html_e('Print', 'publishpress'); ?>
</div>
<?php $modal_id++; ?>
<div data-target="#content_overview_modal_<?php echo esc_attr($modal_id); ?>" class="co-filter item action active-filter">
<span class="dashicons dashicons-admin-generic"></span>
</div>
<div id="content_overview_modal_<?php echo esc_attr($modal_id); ?>" class="content-overview-modal" style="display: none;">
<div class="content-overview-modal-content">
<span class="close">&times;</span>
<div>
<div class="metadata-item-filter custom-filter">
<div class="filter-title">
<?php esc_html_e('Maximum Post Results', 'publishpress'); ?>
</div>
<div class="filter-content">
<form method="POST">
<input type="hidden" name="co_form_action" value="settings_form"/>
<input type="hidden" name="_nonce" value="<?php echo esc_attr(wp_create_nonce('content_overview_settings_form_nonce')); ?>"/>
<input required type="number" step="1" min="1" max="999" id="pp_posts_per_page" name="posts_per_page" value="<?php echo esc_attr($posts_per_page); ?>">
<div class="filter-apply">
<input type="submit" id="filter-submit" class="button button-primary" value="<?php esc_attr_e('Apply Changes', 'publishpress'); ?>">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="right-items">
<?php if (!empty($editable_post_types)) : ?>
Expand Down
Loading