Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB-5837: Improve Handling of Secrets Field #53

Merged
merged 1 commit into from Aug 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/class-decoupled-preview-settings.php
Expand Up @@ -297,7 +297,7 @@ public function sanitize_callback_preview( array $input ) {
}

// Bail early if we are missing required data.
if ( in_array( '', [ $input['label'], $input['url'], $input['preview_type'] ], true ) ) {
if ( in_array( '', [ $input['label'], $input['url'], $input['preview_type'], $input['secret_string'] ], true ) ) {
return [];
}
$options = get_option( 'preview_sites' );
Expand All @@ -314,11 +314,6 @@ public function sanitize_callback_preview( array $input ) {
}

if ( $options && isset( $edit_id ) ) {
// If we're editing an existing site, preserve the secret key if it's not being changed.
if ( empty( $input['secret_string'] ) ) {
$sanitized_input['secret_string'] = sanitize_text_field( $options['preview'][ $edit_id ]['secret_string'] );
}

// If we're editing an existing site, check to make sure there's an ID set.
if ( empty( $input['id'] ) ) {
$sanitized_input['id'] = $this->validate_preview_id( $edit_id, $options );
Expand Down Expand Up @@ -465,11 +460,13 @@ public function setting_url_fn() {
public function setting_secret_fn() {
check_admin_referer( 'edit-preview-site', 'nonce' );
$edit_id = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : false;
$site = $this->get_preview_site( $edit_id );
$value = $edit_id ? $site['secret_string'] : '';
ob_start();
if ( $edit_id ) {
?>
<input id="plugin_text_secret" name="preview_sites[secret_string]" size="40" type="password" /><br />
<span class="description"><?php esc_html_e( 'Shared secret for the preview site. When editing, if kept empty the old value will be saved, otherwise it will be overwritten.', 'wp-decoupled-preview' ); ?></span>
<input id="plugin_text_secret" name="preview_sites[secret_string]" size="40" type="password" value="<?php echo esc_attr( $value ); ?>" required /><br />
<span class="description"><?php esc_html_e( '(Required) Shared secret for the preview site.', 'wp-decoupled-preview' ); ?></span>
<?php
} else {
?>
Expand Down