Skip to content

Commit 8ea0fbf

Browse files
authored
Merge branch 'develop' into ari/new-task-publish-draft-content
2 parents 4f8738c + b8d51e0 commit 8ea0fbf

20 files changed

Lines changed: 3951 additions & 4051 deletions

classes/class-page-types.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,14 @@ public function update_option_page_on_front( $page_id ) {
383383
*
384384
* Runs on post_updated hook.
385385
*
386-
* @param int $post_id The post ID.
387-
* @param \WP_Post $post The post object.
386+
* @param int $post_id The post ID.
387+
* @param \WP_Post|null $post The post object.
388388
*
389389
* @return void
390390
*/
391391
public function post_updated( $post_id, $post ) {
392392
// Check if the post is set as a homepage.
393-
if ( 'page' !== $post->post_type || 'publish' !== $post->post_status ) {
393+
if ( ! $post || 'page' !== $post->post_type || 'publish' !== $post->post_status ) {
394394
return;
395395
}
396396

classes/class-plugin-migrations.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ function ( $file ) {
8585
);
8686
\sort( $updates );
8787

88+
// Remove "class-update" from the updates.
89+
$updates = \array_filter(
90+
$updates,
91+
function ( $update ) {
92+
return $update !== 'class-update';
93+
}
94+
);
95+
8896
// Run the upgrades.
8997
foreach ( $updates as $version_int ) {
9098
$upgrade_class = 'Progress_Planner\Update\Update_' . $version_int;

classes/class-suggested-tasks.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ public function get_tasks_in_rest_format( array $args = [] ) {
479479

480480
// Get the tasks for each category.
481481
foreach ( $max_items_per_category as $category_slug => $max_items ) {
482-
483482
// Skip excluded providers.
484483
if ( ! empty( $args['exclude_provider'] ) && \in_array( $category_slug, $args['exclude_provider'], true ) ) {
485484
continue;

classes/class-todo.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public function maybe_change_first_item_points_on_monday() {
7676
* @return void
7777
*/
7878
public function handle_creating_user_task( $post, $request, $creating ) {
79-
8079
if ( ! $creating || ! \has_term( 'user', 'prpl_recommendations_provider', $post->ID ) ) {
8180
return;
8281
}

classes/rest/class-tasks.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function validate_token( $token ) {
7777
* @return \WP_REST_Response The REST response object containing the recommendations.
7878
*/
7979
public function get_tasks() {
80-
8180
// Collection of task objects.
8281
$tasks = \progress_planner()->get_suggested_tasks_db()->get_tasks_by( [ 'post_status' => [ 'publish', 'trash', 'draft', 'future', 'pending' ] ] );
8382
$tasks_to_return = [];

classes/suggested-tasks/class-tasks-manager.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

classes/suggested-tasks/data-collector/class-post-author.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public function init() {
3434
/**
3535
* Update the cache when the post author changes.
3636
*
37-
* @param int $post_id The post ID.
38-
* @param \WP_Post $post_after The post object following the update.
39-
* @param \WP_Post $post_before The post object before the update.
37+
* @param int $post_id The post ID.
38+
* @param \WP_Post|null $post_after The post object following the update.
39+
* @param \WP_Post $post_before The post object before the update.
4040
*
4141
* @return void
4242
*/
4343
public function update_post_author_on_change( $post_id, $post_after, $post_before ) {
44-
if ( $post_after->post_author !== $post_before->post_author ) {
44+
if ( $post_after && $post_after->post_author !== $post_before->post_author ) {
4545
$this->update_cache();
4646
}
4747
}

classes/suggested-tasks/providers/class-email-sending.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class Email_Sending extends Tasks {
109109
* @return void
110110
*/
111111
public function init() {
112-
113112
// Enqueue the scripts.
114113
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
115114

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public function evaluate_task( $task_id ) {
443443
*
444444
* @return bool true means that the task condition is satisfied, meaning that we don't need to add the task or task was completed.
445445
*/
446-
abstract protected function should_add_task();
446+
abstract public function should_add_task();
447447

448448
/**
449449
* Alias for should_add_task(), for better readability when using in the evaluate_task() method.

classes/update/class-update-111.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @package Progress_Planner
1616
*/
17-
class Update_111 {
17+
class Update_111 extends Update {
1818

1919
const VERSION = '1.1.1';
2020

0 commit comments

Comments
 (0)