@@ -86,6 +86,9 @@ public function __construct() {
8686
8787 // Add the cleanup action.
8888 \add_action ( 'admin_init ' , [ $ this , 'cleanup_pending_tasks ' ] );
89+
90+ // Handle tasks when snoozed period is over.
91+ \add_action ( 'transition_post_status ' , [ $ this , 'handle_task_unsnooze ' ], 10 , 3 );
8992 }
9093
9194 /**
@@ -289,4 +292,37 @@ public function cleanup_pending_tasks() {
289292
290293 \progress_planner ()->get_utils__cache ()->set ( 'cleanup_pending_tasks ' , true , DAY_IN_SECONDS );
291294 }
295+
296+ /**
297+ * Handle task unsnooze.
298+ *
299+ * @param string $new_status The new status.
300+ * @param string $old_status The old status.
301+ * @param \WP_Post $post The post.
302+ *
303+ * @return void
304+ */
305+ public function handle_task_unsnooze ( $ new_status , $ old_status , $ post ) {
306+ // Early exit if it's not task for which snooze period is over.
307+ if ( 'future ' !== $ old_status || 'publish ' !== $ new_status || 'prpl_recommendations ' !== get_post_type ( $ post ) ) {
308+ return ;
309+ }
310+
311+ $ task = \progress_planner ()->get_suggested_tasks_db ()->get_post ( $ post ->ID );
312+ if ( ! $ task ) {
313+ return ;
314+ }
315+
316+ $ task_provider = $ this ->get_task_provider ( $ task ->get_provider_id () );
317+
318+ // Delete tasks which don't have a task provider or repetitive tasks which were created in the previous week.
319+ if ( ! $ task_provider || ( $ task_provider ->is_repetitive () && ( ! $ task ->date || \gmdate ( 'YW ' ) !== (string ) $ task ->date ) ) ) {
320+ \progress_planner ()->get_suggested_tasks_db ()->delete_recommendation ( $ task ->ID );
321+ }
322+
323+ // Delete the task if it is not relevant anymore.
324+ if ( $ task_provider instanceof \Progress_Planner \Suggested_Tasks \Providers \Tasks && ! $ task_provider ->should_add_task () ) {
325+ \progress_planner ()->get_suggested_tasks_db ()->delete_recommendation ( $ task ->ID );
326+ }
327+ }
292328}
0 commit comments