Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions assets/js/recommendations/interactive-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,25 @@ const prplInteractiveTaskFormListener = {
.finally( () => {
// Hide loading state.
prplInteractiveTaskFormListener.hideLoading( formElement );

// Remove the form listener once the callback is executed.
formElement.removeEventListener(
'submit',
formSubmitHandler
);
} );
};

// Add a form listener to the form.
formElement.addEventListener( 'submit', formSubmitHandler );

// Remove the form listener when the popover is closed.
document.getElementById( popoverId ).addEventListener(
'toggle',
( toggleEvent ) => {
if ( toggleEvent.newState === 'closed' ) {
formElement.removeEventListener(
'submit',
formSubmitHandler
);
}
},
{ once: true }
);
},

settings: ( {
Expand Down
23 changes: 12 additions & 11 deletions classes/suggested-tasks/providers/class-set-valuable-post-types.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* Add tasks for settings saved.
* Add tasks for set valuable post types.
*
* @package Progress_Planner
*/

namespace Progress_Planner\Suggested_Tasks\Providers;

/**
* Add tasks for settings saved.
* Add tasks for set valuable post types.
*/
class Set_Valuable_Post_Types extends Tasks_Interactive {

Expand Down Expand Up @@ -119,30 +119,31 @@ protected function get_title() {

/**
* Check if the task should be added.
* We add tasks only to users who have have completed "Fill the settings page" task
* and have upgraded from v1.2 or have 'include_post_types' option empty.
* We add tasks only to users who have upgraded from v1.2 or have 'include_post_types' option empty.
* Reason being that this option was migrated,
* but it could be missed, and post type selection should be revisited.
*
* @return bool
*/
public function should_add_task() {
$saved_posts = \progress_planner()->get_suggested_tasks_db()->get_tasks_by( [ 'provider_id' => 'settings-saved' ] );
if ( empty( $saved_posts ) ) {
$activity = \progress_planner()->get_activities__query()->query_activities(
[
'category' => 'suggested_task',
'data_id' => static::PROVIDER_ID,
]
);
if ( ! empty( $activity ) ) {
return false;
}

// Is the task trashed?
$post_trashed = 'trash' === $saved_posts[0]->post_status;

// Upgraded from <= 1.2?
$upgraded = (bool) \get_option( 'progress_planner_set_valuable_post_types', false );

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

// 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.
return $post_trashed && ( true === $upgraded || empty( $include_post_types ) );
// Add the task only to users who have upgraded from v1.2 or have 'include_post_types' option empty.
return ( true === $upgraded || empty( $include_post_types ) );
}

/**
Expand Down
Loading