Skip to content

Commit bf2d64f

Browse files
committed
Merge branch 'develop' into filip/onboarding-tweaks
2 parents ec28df7 + 8a219fa commit bf2d64f

6 files changed

Lines changed: 53 additions & 21 deletions

File tree

assets/js/recommendations/interactive-task.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,25 @@ const prplInteractiveTaskFormListener = {
118118
.finally( () => {
119119
// Hide loading state.
120120
prplInteractiveTaskFormListener.hideLoading( formElement );
121-
122-
// Remove the form listener once the callback is executed.
123-
formElement.removeEventListener(
124-
'submit',
125-
formSubmitHandler
126-
);
127121
} );
128122
};
129123

130124
// Add a form listener to the form.
131125
formElement.addEventListener( 'submit', formSubmitHandler );
126+
127+
// Remove the form listener when the popover is closed.
128+
document.getElementById( popoverId ).addEventListener(
129+
'toggle',
130+
( toggleEvent ) => {
131+
if ( toggleEvent.newState === 'closed' ) {
132+
formElement.removeEventListener(
133+
'submit',
134+
formSubmitHandler
135+
);
136+
}
137+
},
138+
{ once: true }
139+
);
132140
},
133141

134142
settings: ( {

classes/actions/class-content-scan.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,18 @@ public function update_stats() {
5959
return;
6060
}
6161

62+
// Bail if content helpers are not available (can happen during plugin updates).
63+
$content_helpers = \progress_planner()->get_activities__content_helpers();
64+
if ( null === $content_helpers ) {
65+
return;
66+
}
67+
6268
// Get posts.
6369
$posts = \get_posts(
6470
[
6571
'posts_per_page' => static::SCAN_POSTS_PER_PAGE,
6672
'paged' => $current_page,
67-
'post_type' => \progress_planner()->get_activities__content_helpers()->get_post_types_names(),
73+
'post_type' => $content_helpers->get_post_types_names(),
6874
'post_status' => 'publish',
6975
]
7076
);
@@ -88,9 +94,15 @@ public function update_stats() {
8894
* @return int
8995
*/
9096
public function get_total_pages() {
97+
// Bail if content helpers are not available (can happen during plugin updates).
98+
$content_helpers = \progress_planner()->get_activities__content_helpers();
99+
if ( null === $content_helpers ) {
100+
return 0;
101+
}
102+
91103
// Get the total number of posts.
92104
$total_posts_count = 0;
93-
foreach ( \progress_planner()->get_activities__content_helpers()->get_post_types_names() as $post_type ) {
105+
foreach ( $content_helpers->get_post_types_names() as $post_type ) {
94106
$total_posts_count += \wp_count_posts( $post_type )->publish;
95107
}
96108
// Calculate the total pages to scan.

classes/actions/class-content.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ public function delete_post( $post_id ) {
157157
* @return bool
158158
*/
159159
private function should_skip_saving( $post ) {
160+
// Bail if content helpers are not available (can happen during plugin updates).
161+
$content_helpers = \progress_planner()->get_activities__content_helpers();
162+
if ( null === $content_helpers ) {
163+
return true;
164+
}
165+
160166
// Bail if the post is not included in the post-types we're tracking.
161167
if ( ! \in_array(
162168
$post->post_type,
163-
\progress_planner()->get_activities__content_helpers()->get_post_types_names(),
169+
$content_helpers->get_post_types_names(),
164170
true
165171
) ) {
166172
return true;

classes/actions/class-maintenance.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public function on_switch_theme() {
128128
* @return void
129129
*/
130130
protected function create_maintenance_activity( $type ) {
131+
// Bail if the class doesn't exist (can happen during plugin updates).
132+
if ( ! \class_exists( Activities_Maintenance::class ) ) {
133+
return;
134+
}
135+
131136
$activity = new Activities_Maintenance();
132137
$activity->type = $type;
133138
$activity->save();

classes/class-base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @method \Progress_Planner\UI\Popover get_ui__popover()
5252
* @method \Progress_Planner\Admin\Widgets\Content_Activity get_admin__widgets__content_activity()
5353
* @method \Progress_Planner\UI\Chart get_ui__chart()
54-
* @method \Progress_Planner\Activities\Content_Helpers get_activities__content_helpers()
54+
* @method \Progress_Planner\Activities\Content_Helpers|null get_activities__content_helpers()
5555
* @method \Progress_Planner\Admin\Widgets\Challenge get_admin__widgets__challenge()
5656
* @method \Progress_Planner\Admin\Widgets\Activity_Scores get_admin__widgets__activity_scores()
5757
* @method \Progress_Planner\Utils\Date get_utils__date()

classes/suggested-tasks/providers/class-set-valuable-post-types.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22
/**
3-
* Add tasks for settings saved.
3+
* Add tasks for set valuable post types.
44
*
55
* @package Progress_Planner
66
*/
77

88
namespace Progress_Planner\Suggested_Tasks\Providers;
99

1010
/**
11-
* Add tasks for settings saved.
11+
* Add tasks for set valuable post types.
1212
*/
1313
class Set_Valuable_Post_Types extends Tasks_Interactive {
1414

@@ -119,30 +119,31 @@ protected function get_title() {
119119

120120
/**
121121
* Check if the task should be added.
122-
* We add tasks only to users who have have completed "Fill the settings page" task
123-
* and have upgraded from v1.2 or have 'include_post_types' option empty.
122+
* We add tasks only to users who have upgraded from v1.2 or have 'include_post_types' option empty.
124123
* Reason being that this option was migrated,
125124
* but it could be missed, and post type selection should be revisited.
126125
*
127126
* @return bool
128127
*/
129128
public function should_add_task() {
130-
$saved_posts = \progress_planner()->get_suggested_tasks_db()->get_tasks_by( [ 'provider_id' => 'settings-saved' ] );
131-
if ( empty( $saved_posts ) ) {
129+
$activity = \progress_planner()->get_activities__query()->query_activities(
130+
[
131+
'category' => 'suggested_task',
132+
'data_id' => static::PROVIDER_ID,
133+
]
134+
);
135+
if ( ! empty( $activity ) ) {
132136
return false;
133137
}
134138

135-
// Is the task trashed?
136-
$post_trashed = 'trash' === $saved_posts[0]->post_status;
137-
138139
// Upgraded from <= 1.2?
139140
$upgraded = (bool) \get_option( 'progress_planner_set_valuable_post_types', false );
140141

141142
// Include post types option empty?
142143
$include_post_types = \progress_planner()->get_settings()->get( 'include_post_types', [] );
143144

144-
// Add the task only to users who have completed the "Settings saved" task and have upgraded from v1.2 or have 'include_post_types' option empty.
145-
return $post_trashed && ( true === $upgraded || empty( $include_post_types ) );
145+
// Add the task only to users who have upgraded from v1.2 or have 'include_post_types' option empty.
146+
return ( true === $upgraded || empty( $include_post_types ) );
146147
}
147148

148149
/**

0 commit comments

Comments
 (0)