Skip to content

Commit c53a43e

Browse files
ilicfilipclaude
andauthored
Show 3 suggested tasks on WP Dashboard, 5 elsewhere (#756)
Add get_per_page() helper to Suggested_Tasks widget that returns PER_PAGE_DASHBOARD (3) on the WP Dashboard screen and PER_PAGE_DEFAULT (5) on all other screens. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4c7e25f commit c53a43e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

classes/admin/class-enqueue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function localize_script( $handle, $localize_data = [] ) {
227227

228228
// Check if user wants to see all recommendations.
229229
$show_all_recommendations = isset( $_GET['prpl_show_all_recommendations'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
230-
$tasks_per_page = $show_all_recommendations ? -1 : \Progress_Planner\Admin\Widgets\Suggested_Tasks::PER_PAGE_DEFAULT;
230+
$tasks_per_page = $show_all_recommendations ? -1 : \Progress_Planner\Admin\Widgets\Suggested_Tasks::get_per_page();
231231

232232
// Get tasks from task providers (limited to 5 by default, or unlimited if showing all).
233233
$tasks = \progress_planner()->get_suggested_tasks()->get_tasks_in_rest_format(
@@ -269,7 +269,7 @@ public function localize_script( $handle, $localize_data = [] ) {
269269
],
270270
'delayCelebration' => $delay_celebration,
271271
'tasksPerPage' => $tasks_per_page,
272-
'perPageDefault' => \Progress_Planner\Admin\Widgets\Suggested_Tasks::PER_PAGE_DEFAULT,
272+
'perPageDefault' => \Progress_Planner\Admin\Widgets\Suggested_Tasks::get_per_page(),
273273
],
274274
];
275275
break;

classes/admin/widgets/class-suggested-tasks.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ final class Suggested_Tasks extends Widget {
1919
*/
2020
public const PER_PAGE_DEFAULT = 5;
2121

22+
/**
23+
* Number of tasks to show per page on the WP Dashboard.
24+
*
25+
* @var int
26+
*/
27+
public const PER_PAGE_DASHBOARD = 3;
28+
29+
/**
30+
* Get the number of tasks to show per page based on the current screen.
31+
*
32+
* @return int
33+
*/
34+
public static function get_per_page() {
35+
$screen = \get_current_screen();
36+
if ( $screen && 'dashboard' === $screen->id ) {
37+
return self::PER_PAGE_DASHBOARD;
38+
}
39+
return self::PER_PAGE_DEFAULT;
40+
}
41+
2242
/**
2343
* The widget ID.
2444
*

0 commit comments

Comments
 (0)