Skip to content

Commit 10a255c

Browse files
authored
Merge pull request #636 from ProgressPlanner/filip/v19/show-all-tasks
Add 'Show all recommendations' button
2 parents aa322f9 + 1093b2a commit 10a255c

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
= 1.9.0 =
22

3+
Enhancements:
4+
5+
* Add "Show all Recommendations" button to the "Ravi's Recommendations" widget
6+
37
Bugs we fixed:
48

59
* Fix missing content and streak badges after they are all completed.

assets/css/page-widgets/suggested-tasks.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
}
2020
}
2121

22+
&:not(:has(.prpl-suggested-tasks-loading)):has(.prpl-suggested-tasks-list li) {
23+
24+
.prpl-show-all-tasks {
25+
display: block;
26+
}
27+
}
28+
29+
.prpl-show-all-tasks {
30+
display: none;
31+
}
32+
2233
&:has(.prpl-suggested-tasks-list li) {
2334

2435
.prpl-widget-title {

classes/class-suggested-tasks.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public function __construct() {
6868
\add_filter( 'rest_prepare_prpl_recommendations', [ $this, 'rest_prepare_recommendation' ], 10, 2 );
6969

7070
\add_filter( 'wp_trash_post_days', [ $this, 'change_trashed_posts_lifetime' ], 10, 2 );
71+
72+
// Add filter to modify the maximum number of suggested tasks to display.
73+
\add_filter( 'progress_planner_suggested_tasks_max_items_per_category', [ $this, 'check_show_all_recommendations' ] );
7174
}
7275

7376
/**
@@ -542,4 +545,23 @@ public function get_max_items_per_category() {
542545

543546
return \apply_filters( 'progress_planner_suggested_tasks_max_items_per_category', $max_items_per_category );
544547
}
548+
549+
/**
550+
* Modify the maximum number of suggested tasks to display.
551+
*
552+
* @param array $max_items_per_category Array of maximum items per category.
553+
* @return array Modified array of maximum items per category.
554+
*/
555+
public function check_show_all_recommendations( $max_items_per_category ) {
556+
return (
557+
isset( $_GET['prpl_show_all_recommendations'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
558+
&& \current_user_can( 'manage_options' ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
559+
)
560+
? \array_map(
561+
function () {
562+
return 99;
563+
},
564+
$max_items_per_category
565+
) : $max_items_per_category;
566+
}
545567
}

views/page-widgets/suggested-tasks.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@
3838
<p class="prpl-suggested-tasks-loading">
3939
<?php \esc_html_e( 'Loading tasks...', 'progress-planner' ); ?>
4040
</p>
41+
<?php
42+
// Check if the request URI contains the parameter 'prpl_show_all_recommendations'.
43+
$prpl_request_uri = isset( $_SERVER['REQUEST_URI'] ) ? \sanitize_text_field( \wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
44+
?>
45+
<p class="prpl-show-all-tasks">
46+
<?php if ( false === strpos( $prpl_request_uri, 'prpl_show_all_recommendations' ) ) : ?>
47+
<a href="<?php echo \esc_url( \add_query_arg( 'prpl_show_all_recommendations', '', \admin_url( 'admin.php?page=progress-planner&prpl_show_all_recommendations' ) ) ); ?>">
48+
<?php \esc_html_e( 'Show all Recommendations', 'progress-planner' ); ?>
49+
</a>
50+
<?php else : ?>
51+
<a href="<?php echo \esc_url( \remove_query_arg( 'prpl_show_all_recommendations', \admin_url( 'admin.php?page=progress-planner' ) ) ); ?>">
52+
<?php \esc_html_e( 'Show fewer Recommendations', 'progress-planner' ); ?>
53+
</a>
54+
<?php endif; ?>
55+
</p>
4156
<p class="prpl-no-suggested-tasks">
4257
<?php \esc_html_e( 'You have completed all recommended tasks.', 'progress-planner' ); ?>
4358
<br>

0 commit comments

Comments
 (0)