Skip to content
Draft
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
187 changes: 186 additions & 1 deletion assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,190 @@ const PrplLessonItemsHTML = () => {
);
};

/**
* Render the Remind Me button section.
*
* @return {Element} Element to render.
*/
const PrplRemindMeSection = () => {
const [ selectedDate, setSelectedDate ] = useState( '' );

// Callback function for the Remind Me button
const handleRemindMeClick = () => {
// Validate that a date is selected
if ( ! selectedDate ) {
wp.data
.dispatch( 'core/notices' )
.createErrorNotice(
prplL10n( 'remindMeToReviewContentError' ),
{
type: 'snackbar',
isDismissible: true,
}
);
return;
}

// Get the current post ID
const postId = wp.data.select( 'core/editor' ).getCurrentPostId();

// Get the current post title
const postTitle = wp.data
.select( 'core/editor' )
.getEditedPostAttribute( 'title' );

// Show loading state
wp.data
.dispatch( 'core/notices' )
.createInfoNotice( prplL10n( 'remindMeToReviewContentSetting' ), {
type: 'snackbar',
isDismissible: true,
} );

// Make AJAX request to set reminder
const formData = new FormData();
formData.append( 'action', 'progress_planner_set_reminder' );
formData.append( 'post_id', postId );
formData.append( 'post_title', postTitle );
formData.append( 'reminder_date', selectedDate );
formData.append( 'nonce', progressPlannerEditor.nonce );

fetch( progressPlannerEditor.ajaxUrl, {
method: 'POST',
credentials: 'same-origin',
body: formData,
} )
.then( ( response ) => response.json() )
.then( ( responseData ) => {
if ( responseData.success ) {
// Show success notification
wp.data
.dispatch( 'core/notices' )
.createSuccessNotice(
responseData.data.message ||
prplL10n( 'remindMeToReviewContentSuccess' ) +
postTitle,
{
type: 'snackbar',
isDismissible: true,
}
);
// Clear the selected date after successful reminder set
setSelectedDate( '' );
} else {
// Show error notification
wp.data
.dispatch( 'core/notices' )
.createErrorNotice(
responseData.data.message ||
prplL10n( 'remindMeToReviewContentError' ),
{
type: 'snackbar',
isDismissible: true,
}
);
}
} )
.catch( ( error ) => {
console.error( 'Error setting reminder:', error );
// Show error notification
wp.data
.dispatch( 'core/notices' )
.createErrorNotice(
prplL10n( 'remindMeToReviewContentError' ),
{
type: 'snackbar',
isDismissible: true,
}
);
} );
};

// Get minimum date (today)
const today = new Date().toISOString().split( 'T' )[ 0 ];

return el(
PanelBody,
{
key: 'progress-planner-sidebar-remind-me-section',
title: prplL10n( 'remindMeToReviewContent' ),
initialOpen: true,
},
el(
'div',
{
style: {
padding: '10px 0',
},
},
// Date picker
el(
'div',
{
style: {
marginBottom: '15px',
},
},
el(
'label',
{
style: {
display: 'block',
marginBottom: '5px',
fontWeight: 'bold',
color: '#38296D',
},
},
prplL10n( 'remindMeToReviewContentDate' )
),
el( 'input', {
type: 'date',
value: selectedDate,
min: today,
onChange: ( event ) =>
setSelectedDate( event.target.value ),
style: {
width: '100%',
padding: '8px 12px',
border: '1px solid #ddd',
borderRadius: '4px',
fontSize: '14px',
color: '#38296D',
},
} )
),
el(
Button,
{
key: 'progress-planner-sidebar-remind-me-button',
onClick: handleRemindMeClick,
variant: 'secondary',
disabled: ! selectedDate,
style: {
width: '100%',
margin: '15px 0',
color: selectedDate ? '#38296D' : '#999',
boxShadow: selectedDate
? 'inset 0 0 0 1px #38296D'
: 'inset 0 0 0 1px #ddd',
whiteSpace: 'normal',
height: 'auto',
minHeight: '60px',
padding: '10px 15px',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center',
lineHeight: '1.4',
},
},
prplL10n( 'remindMeToReviewContent' )
)
)
);
};

/**
* Render the Progress Planner sidebar.
* This sidebar will display the lessons and videos for the current page.
Expand Down Expand Up @@ -294,7 +478,8 @@ const PrplProgressPlannerSidebar = () =>
},
},
PrplRenderPageTypeSelector(),
PrplLessonItemsHTML()
PrplLessonItemsHTML(),
PrplRemindMeSection()
)
)
);
Expand Down
2 changes: 2 additions & 0 deletions classes/admin/class-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function enqueue_editor_script() {
'lessons' => \progress_planner()->get_lessons()->get_items(),
'pageTypes' => $page_types,
'defaultPageType' => $prpl_preselected_page_type,
'ajaxUrl' => \admin_url( 'admin-ajax.php' ),
'nonce' => \wp_create_nonce( 'progress_planner' ),
],
]
);
Expand Down
117 changes: 76 additions & 41 deletions classes/admin/class-enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ public function localize_script( $handle, $localize_data = [] ) {
[
'post_status' => [ 'publish', 'trash' ],
'include_provider' => [ 'user' ],
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'relation' => 'OR',
[
'key' => 'prpl_available_at',
'compare' => 'NOT EXISTS',
],
[
'key' => 'prpl_available_at',
'value' => \time(),
'compare' => '<',
],
],
]
);

Expand Down Expand Up @@ -358,57 +370,80 @@ private function get_badge_urls() {
public function get_localized_strings() {
// Strings alphabetically ordered.
return [
'badge' => \esc_html__( 'Badge', 'progress-planner' ),
'checklistProgressDescription' => \sprintf(
'activated' => \esc_html__( 'Activated', 'progress-planner' ),
/* translators: %s: The plugin name. */
'activatePlugin' => \esc_html__( 'Activate plugin "%s"', 'progress-planner' ),
'activating' => \esc_html__( 'Activating...', 'progress-planner' ),
'badge' => \esc_html__( 'Badge', 'progress-planner' ),
'checklistProgressDescription' => \sprintf(
/* translators: %s: the checkmark icon. */
\esc_html__( 'Check off all required elements %s in the element checks below', 'progress-planner' ),
'<span style="background-color:#14b8a6;padding:0.35em;margin:0 0.25em;border-radius:50%;display:inline-block;"></span>'
),
'close' => \esc_html__( 'Close', 'progress-planner' ),
'doneBtnText' => \esc_html__( 'Finish', 'progress-planner' ),
'info' => \esc_html__( 'Info', 'progress-planner' ),
'markAsComplete' => \esc_html__( 'Mark as completed', 'progress-planner' ),
'nextBtnText' => \esc_html__( 'Next &rarr;', 'progress-planner' ),
'prevBtnText' => \esc_html__( '&larr; Previous', 'progress-planner' ),
'pageType' => \esc_html__( 'Page type', 'progress-planner' ),
'progressPlannerSidebar' => \esc_html__( 'Progress Planner Sidebar', 'progress-planner' ),
'progressText' => \sprintf(
'close' => \esc_html__( 'Close', 'progress-planner' ),
'delete' => \esc_html__( 'Delete', 'progress-planner' ),
'disabledRRCheckboxTooltip' => \esc_html__( 'Don\'t worry! This task will be checked off automatically when you\'ve completed it.', 'progress-planner' ),
'doneBtnText' => \esc_html__( 'Finish', 'progress-planner' ),
/* translators: %d: The number of points. */
'fixThisIssue' => \esc_html__( 'Fix this issue for %d points', 'progress-planner' ),
'howLong' => \esc_html__( 'How long?', 'progress-planner' ),
'info' => \esc_html__( 'Info', 'progress-planner' ),
'installed' => \esc_html__( 'Installed', 'progress-planner' ),
'installing' => \esc_html__( 'Installing...', 'progress-planner' ),
/* translators: %s: The plugin name. */
'installPlugin' => \esc_html__( 'Install and activate the "%s" plugin', 'progress-planner' ),
'loadingTasks' => \esc_html__( 'Loading tasks...', 'progress-planner' ),
'markAsComplete' => \esc_html__( 'Mark as completed', 'progress-planner' ),
'moveDown' => \esc_html__( 'Move down', 'progress-planner' ),
'moveUp' => \esc_html__( 'Move up', 'progress-planner' ),
'nextBtnText' => \esc_html__( 'Next &rarr;', 'progress-planner' ),
'opensInNewWindow' => \esc_html__( 'Opens in new window', 'progress-planner' ),
'pageType' => \esc_html__( 'Page type', 'progress-planner' ),
'prevBtnText' => \esc_html__( '&larr; Previous', 'progress-planner' ),
'progressPlannerSidebar' => \esc_html__( 'Progress Planner Sidebar', 'progress-planner' ),
'progressText' => \sprintf(
/* translators: %1$s: The current step number. %2$s: The total number of steps. */
\esc_html__( 'Step %1$s of %2$s', 'progress-planner' ),
'{{current}}',
'{{total}}'
),
'saving' => \esc_html__( 'Saving...', 'progress-planner' ),
'snooze' => \esc_html__( 'Snooze', 'progress-planner' ),
'subscribed' => \esc_html__( 'Subscribed...', 'progress-planner' ),
'subscribing' => \esc_html__( 'Subscribing...', 'progress-planner' ),
'remindMeToReviewContent' => \esc_html__( 'Remind me to review content', 'progress-planner' ),
'remindMeToReviewContentDate' => \esc_html__( 'Reminder date', 'progress-planner' ),
'remindMeToReviewContentError' => \esc_html__( 'Failed to set reminder. Please try again.', 'progress-planner' ),
'remindMeToReviewContentSetting' => \esc_html__( 'Setting reminder...', 'progress-planner' ),
'remindMeToReviewContentSuccess' => \esc_html__( 'Reminder set for:', 'progress-planner' ),
'saving' => \esc_html__( 'Saving...', 'progress-planner' ),
'showAllRecommendations' => \esc_html__( 'Show all recommendations', 'progress-planner' ),
'showFewerRecommendations' => \esc_html__( 'Show fewer recommendations', 'progress-planner' ),
'snooze' => \esc_html__( 'Snooze', 'progress-planner' ),
'snoozeDurationForever' => \esc_html__( 'forever', 'progress-planner' ),
'snoozeDurationOneMonth' => \esc_html__( '1 month', 'progress-planner' ),
'snoozeDurationOneWeek' => \esc_html__( '1 week', 'progress-planner' ),
'snoozeDurationOneYear' => \esc_html__( '1 year', 'progress-planner' ),
'snoozeDurationSixMonths' => \esc_html__( '6 months', 'progress-planner' ),
'snoozeDurationThreeMonths' => \esc_html__( '3 months', 'progress-planner' ),
'snoozeThisTask' => \esc_html__( 'Snooze this task?', 'progress-planner' ),
'somethingWentWrong' => \esc_html__( 'Something went wrong.', 'progress-planner' ),
'subscribed' => \esc_html__( 'Subscribed...', 'progress-planner' ),
'subscribing' => \esc_html__( 'Subscribing...', 'progress-planner' ),
'taskAddedSuccessfully' => \esc_html__( 'Task added successfully', 'progress-planner' ),
/* translators: %s: The task content. */
'taskDelete' => \esc_html__( "Delete task '%s'", 'progress-planner' ),
'delete' => \esc_html__( 'Delete', 'progress-planner' ),
'video' => \esc_html__( 'Video', 'progress-planner' ),
'watchVideo' => \esc_html__( 'Watch video', 'progress-planner' ),
'disabledRRCheckboxTooltip' => \esc_html__( 'Don\'t worry! This task will be checked off automatically when you\'ve completed it.', 'progress-planner' ),
'opensInNewWindow' => \esc_html__( 'Opens in new window', 'progress-planner' ),
'whyIsThisImportant' => \esc_html__( 'Why is this important?', 'progress-planner' ),
/* translators: %s: The plugin name. */
'installPlugin' => \esc_html__( 'Install and activate the "%s" plugin', 'progress-planner' ),
/* translators: %s: The plugin name. */
'activatePlugin' => \esc_html__( 'Activate plugin "%s"', 'progress-planner' ),
'installing' => \esc_html__( 'Installing...', 'progress-planner' ),
'installed' => \esc_html__( 'Installed', 'progress-planner' ),
'activating' => \esc_html__( 'Activating...', 'progress-planner' ),
'activated' => \esc_html__( 'Activated', 'progress-planner' ),
'somethingWentWrong' => \esc_html__( 'Something went wrong.', 'progress-planner' ),
'showAllRecommendations' => \esc_html__( 'Show all recommendations', 'progress-planner' ),
'showFewerRecommendations' => \esc_html__( 'Show fewer recommendations', 'progress-planner' ),
'loadingTasks' => \esc_html__( 'Loading tasks...', 'progress-planner' ),
'taskAddedSuccessfully' => \esc_html__( 'Task added successfully', 'progress-planner' ),
'tasksDeleted' => \esc_html__( 'Completed tasks deleted', 'progress-planner' ),
'taskDeleted' => \esc_html__( 'Completed task deleted', 'progress-planner' ),
'moveUp' => \esc_html__( 'Move up', 'progress-planner' ),
'moveDown' => \esc_html__( 'Move down', 'progress-planner' ),
/* translators: %d: The number of points. */
'fixThisIssue' => \esc_html__( 'Fix this issue for %d points', 'progress-planner' ),
'taskCompleted' => \esc_html__( "Task '%s' completed and moved to the bottom", 'progress-planner' ),
/* translators: %s: The task content. */
'taskDelete' => \esc_html__( "Delete task '%s'", 'progress-planner' ),
'taskDeleted' => \esc_html__( 'Completed task deleted', 'progress-planner' ),
'taskMovedDown' => \esc_html__( 'Task moved down', 'progress-planner' ),
'taskMovedUp' => \esc_html__( 'Task moved up', 'progress-planner' ),
/* translators: %s: The task content. */
'taskMoveDown' => \esc_html__( "Move task '%s' down", 'progress-planner' ),
/* translators: %s: The task content. */
'taskMoveUp' => \esc_html__( "Move task '%s' up", 'progress-planner' ),
/* translators: %s: The task content. */
'taskNotCompleted' => \esc_html__( "Task '%s' marked as not completed and moved to the top", 'progress-planner' ),
'tasksDeleted' => \esc_html__( 'Completed tasks deleted', 'progress-planner' ),
'video' => \esc_html__( 'Video', 'progress-planner' ),
'watchVideo' => \esc_html__( 'Watch video', 'progress-planner' ),
'whyIsThisImportant' => \esc_html__( 'Why is this important?', 'progress-planner' ),
];
}

Expand Down
4 changes: 4 additions & 0 deletions classes/class-suggested-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ public function get_tasks_in_rest_format( array $args = [] ) {
'posts_per_page' => $args['posts_per_page'],
];

if ( ! empty( $args['meta_query'] ) ) {
$query_args['meta_query'] = $args['meta_query']; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
}

// Add provider filters if specified.
if ( ! empty( $args['exclude_provider'] ) ) {
// Note: Database filtering doesn't support exclude_provider directly,
Expand Down
Loading
Loading