Skip to content

Commit ef11369

Browse files
committed
Use the post-excerpt to differentiate golden tasks
1 parent 22d509e commit ef11369

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

classes/class-suggested-tasks.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function register_post_type() {
281281
'show_in_admin_bar' => \apply_filters( 'progress_planner_tasks_show_ui', false ),
282282
'show_in_rest' => true,
283283
'rest_controller_class' => \Progress_Planner\Rest\Recommendations_Controller::class,
284-
'supports' => [ 'title', 'editor', 'author', 'custom-fields', 'page-attributes' ],
284+
'supports' => [ 'title', 'excerpt', 'editor', 'author', 'custom-fields', 'page-attributes' ],
285285
'rewrite' => false,
286286
'menu_icon' => 'dashicons-admin-tools',
287287
'menu_position' => 5,
@@ -509,7 +509,15 @@ public function get_tasks_in_rest_format( array $args = [] ) {
509509
}
510510
}
511511

512-
return $tasks;
512+
/**
513+
* Allow other classes to modify the tasks in REST format.
514+
*
515+
* @param array $tasks The tasks.
516+
* @param array $args The arguments.
517+
*
518+
* @return array
519+
*/
520+
return \apply_filters( 'progress_planner_suggested_tasks_in_rest_format', $tasks, $args );
513521
}
514522

515523
/**

classes/class-todo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function maybe_change_first_item_points_on_monday() {
5757
foreach ( $pending_items as $task ) {
5858
\progress_planner()->get_suggested_tasks_db()->update_recommendation(
5959
$task->ID,
60-
[ 'points' => $task->ID === $pending_items[0]->ID ? 1 : 0 ]
60+
[ 'post_excerpt' => $task->ID === $pending_items[0]->ID ? 'GOLDEN' : '' ]
6161
);
6262
}
6363

classes/suggested-tasks/providers/class-user.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class User extends Tasks {
4747
*/
4848
protected const PROVIDER_ID = 'user';
4949

50+
/**
51+
* Constructor.
52+
*/
53+
public function __construct() {
54+
\add_filter( 'progress_planner_suggested_tasks_in_rest_format', [ $this, 'modify_task_details_for_user_tasks_rest_format' ], 10, 2 );
55+
}
56+
5057
/**
5158
* Check if the task should be added.
5259
*
@@ -94,4 +101,29 @@ public function add_task_actions( $data = [], $actions = [] ) {
94101

95102
return $actions;
96103
}
104+
105+
/**
106+
* Modify the task details for user tasks in REST format.
107+
*
108+
* @param array $tasks The tasks.
109+
* @param array $args The arguments.
110+
*
111+
* @return array
112+
*/
113+
public function modify_task_details_for_user_tasks_rest_format( $tasks, $args ) {
114+
static $modified_tasks = [];
115+
if ( ! isset( $args['include_provider'] ) || ! \in_array( 'user', $args['include_provider'], true ) ) {
116+
return $tasks;
117+
}
118+
foreach ( $tasks['user'] as $key => $task ) {
119+
if ( \in_array( $task['id'], $modified_tasks, true ) ) {
120+
continue;
121+
}
122+
123+
$task['prpl_points'] = ( isset( $task['excerpt']['rendered'] ) && \str_contains( $task['excerpt']['rendered'], 'GOLDEN' ) ) ? 1 : 0;
124+
$tasks['user'][ $key ] = $task;
125+
$modified_tasks[] = $task['id'];
126+
}
127+
return $tasks;
128+
}
97129
}

0 commit comments

Comments
 (0)