Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
165 changes: 151 additions & 14 deletions assets/css/settings-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,166 @@
}
}

.prpl-license-keys-wrapper {
display: flex;
flex-direction: column;
gap: 1rem;
/* Post types */
.prpl-column-post-types {

.prpl-license-key-wrapper {
.prpl-settings-section-title {

svg {
color: #038d88;

path {
fill: currentcolor;
}
}

background-color: #f3faf9;
}

}

/* Login destination */
.prpl-column-login-destination {

.prpl-settings-section-title {

svg {
color: var(--prpl-color-accent-red);
}

background-color: var(--prpl-background-red);
}

}


/* License */
.prpl-column-license {

.prpl-settings-section-title {

svg {
color: #0773b4;
}
background-color: #effbfe;
}

.prpl-license-keys-wrapper {
display: flex;
align-items: center;
gap: 0.5rem;
flex-direction: column;
gap: 1rem;
max-width: 40rem;

.prpl-license-status {
width: 1rem;
height: 1rem;
& > p:first-child {
margin-top: 0;
}

svg {
.prpl-license-key-wrapper {
display: flex;
align-items: center;
gap: 0.5rem;

.prpl-license-status {
width: 1rem;
height: 1rem;

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

input {
width: 30rem;
max-width: calc(100% - 2rem);
border: 1px solid var(--prpl-color-gray-2);
box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.05);
}
}

}


/* Grid layout for wrapper for:
- Valuable post types
- Default login destination
- License keys
*/
#prpl-grid-column-wrapper {
display: grid;
margin-bottom: var(--prpl-gap);

/* There are 5 or less valuable post types */
grid-template-columns: 1fr 1fr;
grid-template-rows: auto auto;
gap: var(--prpl-settings-page-gap);

.prpl-column {
align-self: stretch;
display: flex;
flex-direction: column;

.prpl-widget-wrapper {
flex: 1;
margin-bottom: 0;
}
}

/* Valuable post types */
.prpl-column:nth-child(1) {
grid-column: 1;
grid-row: 1;
}

/* Default login destination */
.prpl-column:nth-child(2) {
grid-column: 2;
grid-row: 1;
}

input {
width: 20rem;
max-width: calc(100% - 2rem);
/* License keys */
.prpl-column:nth-child(3) {
grid-column: 1 / span 2;
grid-row: 2;
}

/* We have more than 5 valuable post types */
&:has([data-has-many-valuable-post-types]) {
grid-template-rows: auto auto;

/* Valuable post types */
.prpl-column:nth-child(1) {
grid-column: 1;
grid-row: 1 / span 2;

/* Span 2 rows on the left */
}

/* Default login destination */
.prpl-column:nth-child(2) {
grid-column: 2;
grid-row: 1;
}

/* License keys */
.prpl-column:nth-child(3) {
grid-column: 2;
grid-row: 2;
}
}
}

/* Valuable post types */
#prpl-post-types-include-wrapper {
padding-top: 0.75rem;

label {
display: block;
margin-top: 0.75rem;

&:first-child {
margin-top: 0;
}
}
}
1 change: 1 addition & 0 deletions assets/images/icon_copywriting.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/icon_user.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion assets/js/settings-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ prplDocumentReady( function () {
action: 'prpl_settings_form',
};
formData.forEach( function ( value, key ) {
data[ key ] = value;
// Handle array notation in keys
if ( key.endsWith( '[]' ) ) {
const baseKey = key.slice( 0, -2 );
if ( ! data[ baseKey ] ) {
data[ baseKey ] = [];
}
data[ baseKey ].push( value );
} else {
data[ key ] = value;
}
} );
const request = wp.ajax.post( 'prpl_settings_form', data );
request.done( function () {
Expand Down
20 changes: 0 additions & 20 deletions assets/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@
*
* Dependencies: progress-planner/ajax-request, progress-planner/onboard, wp-util, progress-planner/l10n
*/
document
.getElementById( 'prpl-settings-form' )
.addEventListener( 'submit', function ( event ) {
event.preventDefault();
const form = new FormData( this );
const data = form.getAll( 'prpl-settings-post-types-include[]' );

// Save the options.
const request = wp.ajax.post( 'progress_planner_save_cpt_settings', {
_ajax_nonce: progressPlanner.nonce,
include_post_types: data.join( ',' ),
} );
request.done( () => {
window.location.reload();
} );

document.getElementById( 'submit-include-post-types' ).disabled = true;
document.getElementById( 'submit-include-post-types' ).innerHTML =
prplL10n( 'saving' );
} );

// Submit the email.
const settingsLicenseForm = document.getElementById(
Expand Down
35 changes: 31 additions & 4 deletions classes/admin/class-page-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public function store_settings_form_options() {
}

$this->save_settings();
$this->save_post_types();
$this->save_license();

\do_action( 'progress_planner_settings_form_options_stored' );
Expand All @@ -184,21 +185,47 @@ public function store_settings_form_options() {
* @return void
*/
public function save_settings() {
$redirect_on_login = isset( $_POST['prpl-redirect-on-login'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
? \sanitize_text_field( \wp_unslash( $_POST['prpl-redirect-on-login'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Missing

// Check the nonce.
\check_admin_referer( 'progress_planner' );

$redirect_on_login = isset( $_POST['prpl-redirect-on-login'] )
? \sanitize_text_field( \wp_unslash( $_POST['prpl-redirect-on-login'] ) )
: false;

\update_user_meta( \get_current_user_id(), 'prpl_redirect_on_login', (bool) $redirect_on_login );
}

/**
* Save the post types.
*
* @return void
*/
public function save_post_types() {

// Check the nonce.
\check_admin_referer( 'progress_planner' );

$include_post_types = isset( $_POST['prpl-post-types-include'] )
? array_map( 'sanitize_text_field', \wp_unslash( $_POST['prpl-post-types-include'] ) ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
// If no post types are selected, use the default post types (post and page can be deregistered).
: array_intersect( [ 'post', 'page' ], \progress_planner()->get_settings()->get_public_post_types() );

\progress_planner()->get_settings()->set( 'include_post_types', $include_post_types );
}

/**
* Save the license key.
*
* @return void
*/
public function save_license() {
$license = isset( $_POST['prpl-pro-license-key'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
? \sanitize_text_field( \wp_unslash( $_POST['prpl-pro-license-key'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Missing

// Check the nonce.
\check_admin_referer( 'progress_planner' );

$license = isset( $_POST['prpl-pro-license-key'] )
? \sanitize_text_field( \wp_unslash( $_POST['prpl-pro-license-key'] ) )
: '';

$previous = \get_option( 'progress_planner_pro_license_key' );
Expand Down
21 changes: 0 additions & 21 deletions classes/admin/class-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function __construct() {
private function register_hooks() {
\add_action( 'admin_menu', [ $this, 'add_page' ] );
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
\add_action( 'wp_ajax_progress_planner_save_cpt_settings', [ $this, 'save_cpt_settings' ] );
\add_action( 'in_admin_header', [ $this, 'remove_admin_notices' ], PHP_INT_MAX );

// Clear the cache for the activity scores widget.
Expand Down Expand Up @@ -290,26 +289,6 @@ public function enqueue_styles() {
}
}

/**
* Save the post types settings.
*
* @return void
*/
public function save_cpt_settings() {
\check_ajax_referer( 'progress_planner', 'nonce', false );
$include_post_types = isset( $_POST['include_post_types'] )
? \sanitize_text_field( \wp_unslash( $_POST['include_post_types'] ) )
: 'post,page';
$include_post_types = \explode( ',', $include_post_types );
\progress_planner()->get_settings()->set( 'include_post_types', $include_post_types );

\wp_send_json_success(
[
'message' => \esc_html__( 'Settings saved.', 'progress-planner' ),
]
);
}

/**
* Remove all admin notices when the user is on the Progress Planner page.
*
Expand Down
Loading
Loading