Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1fdbfe8
check remote api status
ilicfilip Apr 14, 2025
dbd2e8e
use variable
ilicfilip Apr 14, 2025
55daa18
add "Save settings" task only if there are pages
ilicfilip Apr 14, 2025
ea824ac
Settings_Saved::is_task_completed
ilicfilip Apr 14, 2025
5da4aa5
adjust note
ilicfilip Apr 15, 2025
aa31bc0
adjust the note
ilicfilip Apr 15, 2025
be7ed5f
Merge branch 'develop' into filip/check-api-status
ilicfilip Apr 15, 2025
d3fde58
Merge branch 'develop' into filip/check-api-status
ilicfilip Apr 17, 2025
7ba7cea
Merge branch 'develop' into filip/check-api-status
ilicfilip Apr 22, 2025
4c769f1
Merge branch 'develop' into filip/check-api-status
ilicfilip Apr 23, 2025
cadb2be
Merge branch 'develop' into filip/check-api-status
ilicfilip May 13, 2025
2b83c29
Merge branch 'develop' into filip/check-api-status
ilicfilip Jun 4, 2025
3eeba26
Merge branch 'develop' into filip/check-api-status
ilicfilip Jun 30, 2025
32b178c
Merge branch 'develop' into filip/check-api-status
ilicfilip Jul 17, 2025
da9da58
Merge branch 'develop' into filip/check-api-status
ilicfilip Jul 23, 2025
85810a1
Merge branch 'develop' into filip/check-api-status
ilicfilip Jul 23, 2025
be5f0f1
Merge branch 'develop' into filip/check-api-status
aristath Jul 28, 2025
177a980
Merge branch 'develop' into filip/check-api-status
ilicfilip Jul 28, 2025
72686b9
Merge branch 'develop' into filip/check-api-status
ilicfilip Aug 19, 2025
eb28386
Merge branch 'develop' into filip/check-api-status
ilicfilip Oct 15, 2025
7562fb4
Merge branch 'develop' into filip/check-api-status
ilicfilip Oct 23, 2025
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
66 changes: 66 additions & 0 deletions assets/css/settings-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,69 @@
}
}
}

.prpl-api-status-wrapper {
display: flex;
flex-direction: column;
gap: 1rem;

.prpl-api-status-controls {
display: flex;
align-items: center;
gap: 0.5rem;
}

.prpl-api-status-response-wrapper {
display: flex;
align-items: center;
gap: 0.5rem;

svg {
width: 1rem;
height: 1rem;
}

.prpl-api-status-icon-ok,
.prpl-api-status-icon-error,
.prpl-api-status-icon-spinner,
.prpl-api-status-text {
display: none;
}

&.prpl-api-status-checking {

.prpl-api-status-icon-spinner {
display: inline-block;
}
}

&.prpl-api-status-ok {

.prpl-api-status-icon-spinner {
display: none;
}

.prpl-api-status-icon-ok,
.prpl-api-status-text {
display: inline-block;
}
}

&.prpl-api-status-error {

.prpl-api-status-icon-spinner {
display: none;
}

.prpl-api-status-icon-error,
.prpl-api-status-text {
display: inline-block;
}
}
}

input {
width: 20rem;
max-width: calc(100% - 2rem);
}
}
3 changes: 3 additions & 0 deletions assets/images/icon_server.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion assets/js/ajax-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ const progressPlannerAjaxRequest = ( { url, data } ) => {
http.open( 'POST', url, true );
http.onreadystatechange = () => {
let response;

try {
response = JSON.parse( http.response );
} catch ( e ) {
if ( http.readyState === 4 && http.status !== 200 ) {
console.warn( http, e );
return http.response;
// Reject the promise with the response.
reject( response );
}
}

Expand Down
109 changes: 107 additions & 2 deletions assets/js/settings-page.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* global alert, prplDocumentReady */
/* global alert, prplDocumentReady, progressPlannerSettingsPage, progressPlannerAjaxRequest, prplL10n */
/*
* Settings Page
*
* A script to handle the settings page.
*
* Dependencies: progress-planner/document-ready, wp-util
* Dependencies: progress-planner/document-ready, wp-util, progress-planner/ajax-request, progress-planner/l10n
*/
const prplTogglePageSelectorSettingVisibility = function ( page, value ) {
const itemRadiosWrapperEl = document.querySelector(
Expand Down Expand Up @@ -92,3 +92,108 @@ prplDocumentReady( function () {
.getElementById( 'prpl-settings' )
.addEventListener( 'submit', prplFormSubmit );
} );

/**
* API Status Manager
* Handles the display and state of the API status check
*/
class APIStatusManager {
/**
* @param {string} wrapperSelector - The selector for the status wrapper element
*/
constructor( wrapperSelector ) {
this.wrapper = document.querySelector( wrapperSelector );
}

/**
* Update the status text content
* @param {string} text - The text to display
*/
updateStatusText( text ) {
const textElement = this.wrapper?.querySelector(
'.prpl-api-status-text'
);
if ( textElement ) {
textElement.textContent = text;
}
}

/**
* Update the status classes
* @param {string} status - The status class to add ('ok', 'error', 'checking')
*/
updateStatusClasses( status ) {
if ( ! this.wrapper ) {
return;
}

this.wrapper.classList.remove(
'prpl-api-status-ok',
'prpl-api-status-error',
'prpl-api-status-checking'
);
this.wrapper.classList.add( `prpl-api-status-${ status }` );
}

/**
* Handle API response
* @param {Object} response - The API response
*/
handleResponse( response ) {
if ( response.status === 'ok' && response.nonce ) {
this.updateStatusText( prplL10n( 'remoteAPIStatusOk' ) );
this.updateStatusClasses( 'ok' );
} else {
this.updateStatusText(
response?.message || prplL10n( 'remoteAPIStatusError' )
);
this.updateStatusClasses( 'error' );
}
}

/**
* Handle API error
* @param {Error} error - The error object
*/
handleError( error ) {
this.updateStatusText(
error?.message || prplL10n( 'remoteAPIStatusError' )
);
this.updateStatusClasses( 'error' );
}

/**
* Check the API status
*/
checkStatus() {
if ( ! this.wrapper ) {
return;
}

this.updateStatusClasses( 'checking' );

progressPlannerAjaxRequest( {
url: progressPlannerSettingsPage.onboardNonceURL,
data: {
site: progressPlannerSettingsPage.siteUrl,
},
} )
.then( ( response ) => this.handleResponse( response ) )
.catch( ( error ) => this.handleError( error ) );
}
}

// Add click handler for API status check button
prplDocumentReady( () => {
// Initialize the API status manager
const apiStatusManager = new APIStatusManager(
'.prpl-api-status-response-wrapper'
);

const statusButton = document.getElementById( 'prpl-setting-api-status' );
if ( statusButton ) {
statusButton.addEventListener( 'click', () =>
apiStatusManager.checkStatus()
);
}
} );
2 changes: 2 additions & 0 deletions classes/admin/class-enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ public function get_localized_strings() {
'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' ),
'remoteAPIStatusOk' => \esc_html__( 'API is accessible', 'progress-planner' ),
'remoteAPIStatusError' => \esc_html__( 'API is not accessible', '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. */
Expand Down
5 changes: 4 additions & 1 deletion classes/admin/class-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@
[
'name' => 'progressPlannerSettingsPage',
'data' => [
'siteUrl' => \get_site_url(),
'siteUrl' => \get_site_url(),
'onboardNonceURL' => \progress_planner()->get_utils__onboard()->get_remote_nonce_url(),

Check failure on line 215 in classes/admin/class-page.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Call to an undefined method Progress_Planner\Utils\Onboard::get_remote_nonce_url().
'onboardAPIUrl' => \progress_planner()->get_utils__onboard()->get_remote_url(),
'ajaxUrl' => \admin_url( 'admin-ajax.php' ),
],
]
);
Expand Down
10 changes: 10 additions & 0 deletions classes/suggested-tasks/providers/class-settings-saved.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,14 @@ public function add_task_actions( $data = [], $actions = [] ) {

return $actions;
}

/**
* Check if the task is completed.
*
* @param string $task_id Optional task ID to check completion for.
* @return bool
*/
public function is_task_completed( $task_id = '' ) {
return false !== \get_option( 'progress_planner_pro_license_key', false );
}
}
2 changes: 2 additions & 0 deletions views/admin-page-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<?php \progress_planner()->the_view( 'page-settings/settings.php' ); ?>
</div>

<?php \progress_planner()->the_view( 'page-settings/api-status.php' ); ?>

<?php \wp_nonce_field( 'progress_planner' ); ?>

<button
Expand Down
53 changes: 53 additions & 0 deletions views/page-settings/api-status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Api status settings.
*
* @package Progress_Planner
*/

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>

<div class="prpl-column">
<div class="prpl-widget-wrapper">
<h2 class="prpl-settings-section-title prpl-settings-section-api-status">
<span class="icon">
<?php \progress_planner()->the_asset( 'images/icon_server.svg' ); ?>
</span>
<span>
<?php \esc_html_e( 'Check API status', 'progress-planner' ); ?>
</span>
</h2>
<div class="prpl-api-status-wrapper">
<label for="prpl-setting-api-status">
<?php \esc_html_e( 'Ping our server and check the API status.', 'progress-planner' ); ?>
</label>
<div class="prpl-api-status-controls">
<input
id="prpl-setting-api-status"
class="prpl-button-secondary"
name="prpl-api-status"
type="button"
value="<?php \esc_attr_e( 'Ping API', 'progress-planner' ); ?>"
/>
<span class="prpl-api-status-response-wrapper">
<span class="prpl-api-status-icon-spinner" title="<?php esc_attr_e( 'Checking...', 'progress-planner' ); ?>">
<img src="<?php echo \esc_url( \admin_url( 'images/spinner.gif' ) ); ?>" alt="<?php esc_attr_e( 'Checking...', 'progress-planner' ); ?>" />
</span>
<span class="prpl-api-status-icon-ok" title="<?php esc_attr_e( 'Accessible', 'progress-planner' ); ?>">
<?php \progress_planner()->the_asset( 'images/icon_check_circle.svg' ); ?>
</span>
<span class="prpl-api-status-icon-error" title="<?php esc_attr_e( 'Not accessible', 'progress-planner' ); ?>">
<?php \progress_planner()->the_asset( 'images/icon_exclamation_circle.svg' ); ?>
</span>
<span class="prpl-api-status-text">
<?php \esc_html_e( 'API is accessible', 'progress-planner' ); ?>
</span>
</span>
</div>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions views/page-settings/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
if ( ! \defined( 'ABSPATH' ) ) {
exit;
}

$prpl_pages = \progress_planner()->get_admin__page_settings()->get_settings();
?>

<div class="prpl-column prpl-column-pages">
Expand All @@ -20,6 +22,8 @@
<?php \esc_html_e( 'Your pages', 'progress-planner' ); ?>
</span>
</h2>

<?php if ( ! empty( $prpl_pages ) ) : ?>
<p>
<?php \esc_html_e( 'Let us know if you have following pages.', 'progress-planner' ); ?>
</p>
Expand All @@ -30,4 +34,9 @@
}
?>
</div>
<?php else : ?>
<p>
<?php esc_html_e( 'There seems to be a problem with loading page types from our server. Please try again later or check the API status.', 'progress-planner' ); ?>
</p>
<?php endif; ?>
</div>
Loading