@@ -235,6 +235,16 @@ public function suggested_task_action() {
235235 \wp_send_json_error ( [ 'message ' => \esc_html__ ( 'Task not found. ' , 'progress-planner ' ) ] );
236236 }
237237
238+ $ provider = \progress_planner ()->get_suggested_tasks ()->get_tasks_manager ()->get_task_provider ( $ task ->get_provider_id () );
239+
240+ if ( ! $ provider ) {
241+ \wp_send_json_error ( [ 'message ' => \esc_html__ ( 'Provider not found. ' , 'progress-planner ' ) ] );
242+ }
243+
244+ if ( ! $ provider ->capability_required () ) {
245+ \wp_send_json_error ( [ 'message ' => \esc_html__ ( 'You do not have permission to complete this task. ' , 'progress-planner ' ) ] );
246+ }
247+
238248 $ updated = false ;
239249
240250 switch ( $ action ) {
@@ -281,7 +291,7 @@ public function register_post_type() {
281291 'show_in_admin_bar ' => \apply_filters ( 'progress_planner_tasks_show_ui ' , false ),
282292 'show_in_rest ' => true ,
283293 'rest_controller_class ' => \Progress_Planner \Rest \Recommendations_Controller::class,
284- 'supports ' => [ 'title ' , 'editor ' , 'author ' , 'custom-fields ' , 'page-attributes ' ],
294+ 'supports ' => [ 'title ' , 'excerpt ' , ' editor ' , 'author ' , 'custom-fields ' , 'page-attributes ' ],
285295 'rewrite ' => false ,
286296 'menu_icon ' => 'dashicons-admin-tools ' ,
287297 'menu_position ' => 5 ,
@@ -291,11 +301,6 @@ public function register_post_type() {
291301 );
292302
293303 $ rest_meta_fields = [
294- 'prpl_points ' => [
295- 'type ' => 'number ' ,
296- 'single ' => true ,
297- 'show_in_rest ' => true ,
298- ],
299304 'prpl_task_id ' => [
300305 'type ' => 'string ' ,
301306 'single ' => true ,
@@ -442,13 +447,14 @@ public function rest_prepare_recommendation( $response, $post ) {
442447
443448 // This has to be the last item to be added because actions use data from previous items.
444449 $ response ->data ['prpl_task_actions ' ] = $ provider ->get_task_actions ( $ response ->data );
450+ $ response ->data ['prpl_points ' ] = $ provider ->get_points ();
445451
446452 /*
447453 * Check if task was completed before - for example, comments were disabled and then re-enabled, and remove points if so.
448454 * Those are tasks which are completed by toggling an option, so non repetitive & not user tasks.
449455 */
450456 if ( ! \has_term ( 'user ' , 'prpl_recommendations_provider ' , $ post ->ID ) && ! $ provider ->is_repetitive () && $ provider ->task_has_activity ( $ response ->data ['meta ' ]['prpl_task_id ' ] ) ) {
451- $ response ->data ['meta ' ][ ' prpl_points ' ] = 0 ;
457+ $ response ->data ['prpl_points ' ] = 0 ;
452458 }
453459 }
454460
@@ -513,7 +519,15 @@ public function get_tasks_in_rest_format( array $args = [] ) {
513519 }
514520 }
515521
516- return $ tasks ;
522+ /**
523+ * Allow other classes to modify the tasks in REST format.
524+ *
525+ * @param array $tasks The tasks.
526+ * @param array $args The arguments.
527+ *
528+ * @return array
529+ */
530+ return \apply_filters ( 'progress_planner_suggested_tasks_in_rest_format ' , $ tasks , $ args );
517531 }
518532
519533 /**
0 commit comments