Skip to content

Commit 8b3a522

Browse files
authored
Merge branch 'develop' into filip/wp-cli
2 parents 594cef0 + bf23df6 commit 8b3a522

5 files changed

Lines changed: 53 additions & 46 deletions

File tree

assets/js/widgets/suggested-tasks.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,34 @@ const prplSuggestedTasksWidget = {
4444
per_page: prplSuggestedTask.maxItemsPerCategory[ category ],
4545
} );
4646

47-
// Inject pending celebration tasks.
48-
celebrationPromises.push(
49-
prplSuggestedTask
50-
.injectItemsFromCategory( {
51-
category,
52-
status: [ 'pending' ],
53-
per_page: 100,
54-
} )
55-
.then( ( data ) => {
56-
// If there were pending tasks.
57-
if ( data.length ) {
58-
// Set post status to trash.
59-
data.forEach( ( task ) => {
60-
const post =
61-
new wp.api.models.Prpl_recommendations( {
62-
id: task.id,
63-
} );
64-
// Destroy the post, without the force parameter.
65-
post.destroy( { url: post.url() } );
66-
} );
67-
}
68-
} )
69-
);
47+
// We trigger celebration only on Progress Planner dashboard page.
48+
if ( ! prplSuggestedTask.delayCelebration ) {
49+
// Inject pending celebration tasks.
50+
celebrationPromises.push(
51+
prplSuggestedTask
52+
.injectItemsFromCategory( {
53+
category,
54+
status: [ 'pending' ],
55+
per_page: 100,
56+
} )
57+
.then( ( data ) => {
58+
// If there were pending tasks.
59+
if ( data.length ) {
60+
// Set post status to trash.
61+
data.forEach( ( task ) => {
62+
const post =
63+
new wp.api.models.Prpl_recommendations(
64+
{
65+
id: task.id,
66+
}
67+
);
68+
// Destroy the post, without the force parameter.
69+
post.destroy( { url: post.url() } );
70+
} );
71+
}
72+
} )
73+
);
74+
}
7075
}
7176

7277
// Trigger celebration once, for all categories.

classes/admin/class-enqueue.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ public function localize_script( $handle, $localize_data = [] ) {
219219
if ( isset( $max_items_per_category['user'] ) ) {
220220
$max_items_per_category['user'] = 100;
221221
}
222+
223+
// Celebrate only on the Progress Planner Dashboard page.
224+
$delay_celebration = true;
225+
if ( \progress_planner()->is_on_progress_planner_dashboard_page() ) {
226+
// should_show_upgrade_popover() also checks if we're on the Progress Planner Dashboard page - but let's be explicit since that method might change in the future.
227+
$delay_celebration = \progress_planner()->get_plugin_upgrade_tasks()->should_show_upgrade_popover();
228+
}
229+
222230
$localize_data = [
223231
'name' => 'prplSuggestedTask',
224232
'data' => [
@@ -228,6 +236,7 @@ public function localize_script( $handle, $localize_data = [] ) {
228236
'snoozeIcon' => constant( 'PROGRESS_PLANNER_URL' ) . '/assets/images/icon_snooze.svg',
229237
],
230238
'maxItemsPerCategory' => apply_filters( 'progress_planner_suggested_tasks_max_items_per_category', $max_items_per_category ),
239+
'delayCelebration' => $delay_celebration,
231240
],
232241
];
233242
break;

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,6 @@ public function get_score() {
4949
* @return void
5050
*/
5151
public function enqueue_scripts() {
52-
// Celebrate only on the Progress Planner Dashboard page.
53-
$delay_celebration = false;
54-
if ( \progress_planner()->is_on_progress_planner_dashboard_page() ) {
55-
// should_show_upgrade_popover() also checks if we're on the Progress Planner Dashboard page - but let's be explicit since that method might change in the future.
56-
$delay_celebration = \progress_planner()->get_plugin_upgrade_tasks()->should_show_upgrade_popover();
57-
}
58-
59-
// Enqueue the script.
60-
\progress_planner()->get_admin__enqueue()->enqueue_script(
61-
'widgets/suggested-tasks',
62-
[
63-
'name' => 'prplSuggestedTasks',
64-
'data' => [
65-
'ajaxUrl' => \admin_url( 'admin-ajax.php' ),
66-
'nonce' => \wp_create_nonce( 'progress_planner' ),
67-
'tasks' => [], // This is set in the JS file.
68-
'delayCelebration' => $delay_celebration,
69-
],
70-
]
71-
);
72-
7352
// Enqueue the badge scroller script.
7453
\progress_planner()->get_admin__enqueue()->enqueue_script(
7554
'widgets/suggested-tasks-badge-scroller',

classes/class-suggested-tasks-db.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ public function add( $data ) {
3636
return 0;
3737
}
3838

39+
// Set lock transient.
40+
$transient_key = 'prpl_task_lock_' . $data['task_id'];
41+
42+
// Check if the task is already being processed.
43+
if ( \get_transient( $transient_key ) ) {
44+
return 0;
45+
}
46+
47+
// Set lock transient.
48+
\set_transient( $transient_key, true, 5 );
49+
3950
// Check if we have an existing task with the same title.
4051
$posts = $this->get_tasks_by(
4152
[
@@ -53,6 +64,7 @@ public function add( $data ) {
5364

5465
// If we have an existing task, skip.
5566
if ( ! empty( $posts ) ) {
67+
\delete_transient( $transient_key );
5668
return $posts[0]->ID;
5769
}
5870

@@ -137,6 +149,8 @@ public function add( $data ) {
137149
\update_post_meta( $post_id, "prpl_$key", $value );
138150
}
139151

152+
\delete_transient( $transient_key );
153+
140154
return $post_id;
141155
}
142156

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function should_add_task() {
285285
continue;
286286
}
287287

288-
$task_id = $this->get_task_id( [ 'post_id' => $post->ID ] );
288+
$task_id = $this->get_task_id( [ 'target_post_id' => $post->ID ] );
289289

290290
// Don't add the task if it was completed.
291291
if ( true === \progress_planner()->get_suggested_tasks()->was_task_completed( $task_id ) ) {
@@ -320,7 +320,7 @@ public function get_tasks_to_inject() {
320320
}
321321

322322
$task_to_inject[] = [
323-
'task_id' => $this->get_task_id( [ 'post_id' => $task_data['target_post_id'] ] ),
323+
'task_id' => $this->get_task_id( [ 'target_post_id' => $task_data['target_post_id'] ] ),
324324
'provider_id' => $this->get_provider_id(),
325325
'category' => $this->get_provider_category(),
326326
'target_post_id' => $task_data['target_post_id'],

0 commit comments

Comments
 (0)