Changeset 2955124
- Timestamp:
- 08/17/2023 10:04:57 PM (3 years ago)
- Location:
- decoupled-preview
- Files:
-
- 10 edited
- 1 copied
-
tags/1.0.4 (copied) (copied from decoupled-preview/trunk)
-
tags/1.0.4/CONTRIBUTING.MD (modified) (1 diff)
-
tags/1.0.4/readme.txt (modified) (2 diffs)
-
tags/1.0.4/src/class-decoupled-preview-settings.php (modified) (6 diffs)
-
tags/1.0.4/src/class-list-table.php (modified) (2 diffs)
-
tags/1.0.4/wp-decoupled-preview.php (modified) (3 diffs)
-
trunk/CONTRIBUTING.MD (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/class-decoupled-preview-settings.php (modified) (6 diffs)
-
trunk/src/class-list-table.php (modified) (2 diffs)
-
trunk/wp-decoupled-preview.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
decoupled-preview/tags/1.0.4/CONTRIBUTING.MD
r2920738 r2955124 11 11 Development and releases are structured around two branches, `develop` and `main`. The `develop` branch is the default branch for the repository, and is the source and destination for feature branches. 12 12 13 We prefer to squash commits (i.e. avoid merge PRs) from a feature branch into `develop` when merging, and to include the PR # in the commit message. PRs to `develop` should also include any relev ent updates to the changelog in readme.txt. For example, if a feature constitutes a minor or major version bump, that version update should be discussed and made as part of approving and merging the feature into `develop`.13 We prefer to squash commits (i.e. avoid merge PRs) from a feature branch into `develop` when merging, and to include the PR # in the commit message. PRs to `develop` should also include any relevant updates to the changelog in readme.txt. For example, if a feature constitutes a minor or major version bump, that version update should be discussed and made as part of approving and merging the feature into `develop`. 14 14 15 15 `develop` should be stable and usable, though possibly a few commits ahead of the public release on wp.org. -
decoupled-preview/tags/1.0.4/readme.txt
r2927210 r2955124 3 3 Tags: headless,next.js,decoupled,preview 4 4 Tested up to: 6.2.2 5 Stable tag: 1.0. 35 Stable tag: 1.0.4 6 6 License: GPL2 or later 7 7 License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html … … 56 56 == Changelog == 57 57 58 = 1.0.4 = 59 * Improve Handling of secrets field. [[#53](https://github.com/pantheon-systems/wp-decoupled-preview/pull/53)] 60 * Move set default preview site functionality to wp-pantheon-decoupled. [[#54](https://github.com/pantheon-systems/wp-decoupled-preview/pull/54)] 61 58 62 = 1.0.3 = 59 63 * Bugfix for cases where Decoupled Preview link did not load due to a js error. [[#43](https://github.com/pantheon-systems/wp-decoupled-preview/pull/43)] -
decoupled-preview/tags/1.0.4/src/class-decoupled-preview-settings.php
r2898067 r2955124 75 75 esc_html__( 'Content Type', 'wp-decoupled-preview' ), 76 76 [ &$this, 'setting_content_type_fn' ], 77 'preview_sites', 78 'wp-decoupled-preview-section' 79 ); 80 add_settings_field( 81 'plugin_dropdown_user', 82 esc_html__( 'Associated User', 'wp-decoupled-preview' ), 83 [ &$this, 'setting_associated_user_fn' ], 77 84 'preview_sites', 78 85 'wp-decoupled-preview-section' … … 298 305 299 306 // Bail early if we are missing required data. 300 if ( in_array( '', [ $input['label'], $input['url'], $input['preview_type'] ], true ) ) {307 if ( in_array( '', [ $input['label'], $input['url'], $input['preview_type'], $input['secret_string'] ], true ) ) { 301 308 return []; 302 309 } … … 315 322 316 323 if ( $options && isset( $edit_id ) ) { 317 // If we're editing an existing site, preserve the secret key if it's not being changed.318 if ( empty( $input['secret_string'] ) ) {319 $sanitized_input['secret_string'] = sanitize_text_field( $options['preview'][ $edit_id ]['secret_string'] );320 }321 322 324 // If we're editing an existing site, check to make sure there's an ID set. 323 325 if ( empty( $input['id'] ) ) { … … 335 337 if ( isset( $input['secret_string'] ) ) { 336 338 $sanitized_input['secret_string'] = sanitize_text_field( $input['secret_string'] ); 339 } 340 if ( empty( $input['associated_user'] ) ) { 341 $sanitized_input['associated_user'] = ''; 342 } else { 343 $sanitized_input['associated_user'] = sanitize_text_field( $input['associated_user'] ); 337 344 } 338 345 $edit_id = ! isset( $edit_id ) || $edit_id !== $sanitized_input['id'] ? $sanitized_input['id'] : $edit_id; … … 466 473 check_admin_referer( 'edit-preview-site', 'nonce' ); 467 474 $edit_id = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : false; 475 $site = $this->get_preview_site( $edit_id ); 476 $value = $edit_id ? $site['secret_string'] : ''; 468 477 ob_start(); 469 478 if ( $edit_id ) { 470 479 ?> 471 <input id="plugin_text_secret" name="preview_sites[secret_string]" size="40" type="password" /><br />472 <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>480 <input id="plugin_text_secret" name="preview_sites[secret_string]" size="40" type="password" value="<?php echo esc_attr( $value ); ?>" required /><br /> 481 <span class="description"><?php esc_html_e( '(Required) Shared secret for the preview site.', 'wp-decoupled-preview' ); ?></span> 473 482 <?php 474 483 } else { … … 560 569 561 570 /** 571 * Associated User 572 * 573 * @return void 574 */ 575 public function setting_associated_user_fn() { 576 check_admin_referer( 'edit-preview-site', 'nonce' ); 577 $edit_id = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : false; 578 $site = $this->get_preview_site( $edit_id ); 579 $users = get_users( [ 'fields' => [ 'display_name' ] ] ); 580 if ( isset( $edit_id ) ) { 581 ?> 582 <label for="associated_user">Choose an associated user:</label> 583 <select id="associated_user" name="preview_sites[associated_user]" autocomplete="username"> 584 <option value="" selected="<?php $site['associated_user'] === ''; ?>">--None--</option> 585 <?php 586 foreach ( $users as $user ) { 587 $selected = ( $site['associated_user'] === $user->display_name ) ? 'selected="selected"' : ''; 588 ?> 589 <option value="<?php echo esc_attr( $user->display_name ); ?>" <?php echo esc_attr( $selected ); ?>><?php echo esc_html( $user->display_name ); ?></option> 590 <?php 591 } 592 ?> 593 </select> 594 <?php 595 } 596 } 597 598 /** 562 599 * Get the List of the configured sites or specific site. 563 600 * -
decoupled-preview/tags/1.0.4/src/class-list-table.php
r2898067 r2955124 98 98 'preview_type' => __( 'Preview Type', 'wp-decoupled-preview' ), 99 99 'content_type' => __( 'Content Type', 'wp-decoupled-preview' ), 100 'associated_user' => __( 'Associated User', 'wp-decoupled-preview' ), 100 101 'actions' => __( 'Actions', 'wp-decoupled-preview' ), 101 102 ]; … … 113 114 case 'label': 114 115 case 'url': 116 case 'associated_user': 115 117 case 'preview_type': 116 118 return isset( $item[ $column_name ] ) ? esc_html( $item[ $column_name ] ) : ''; -
decoupled-preview/tags/1.0.4/wp-decoupled-preview.php
r2927210 r2955124 4 4 * Plugin URI: https://github.com/pantheon-systems/wp-decoupled-preview 5 5 * Description: Preview WordPress content on Front-end sites including Next.js 6 * Version: 1.0. 36 * Version: 1.0.4 7 7 * Author: Pantheon 8 8 * Author URI: https://pantheon.io/ … … 38 38 39 39 add_action( 'init', __NAMESPACE__ . '\\conditionally_enqueue_scripts' ); 40 add_action( 'admin_notices', __NAMESPACE__ . '\\show_example_preview_password_admin_notice' );41 40 add_action( 'updated_option', __NAMESPACE__ . '\\redirect_to_preview_site' ); 42 41 … … 70 69 add_filter( 'template_include', __NAMESPACE__ . '\\override_preview_template', 1 ); 71 70 } 72 }73 74 /**75 * Set default values for the preview sites options.76 *77 * @return void78 */79 function set_default_options() {80 $secret = wp_generate_password( 10, false );81 set_transient( 'example_preview_password', $secret );82 83 add_option(84 'preview_sites',85 [86 'preview' => [87 1 => [88 'label' => esc_html__( 'Example NextJS Preview', 'wp-decoupled-preview' ),89 'url' => 'https://example.com/api/preview',90 'secret_string' => $secret,91 'preview_type' => 'Next.js',92 'id' => 1,93 ],94 ],95 ]96 );97 }98 99 /**100 * Show example preview password admin notice.101 *102 * @return void103 */104 function show_example_preview_password_admin_notice() {105 $preview_password = get_transient( 'example_preview_password' );106 if ( $preview_password ) {107 ?>108 <div class="notice notice-success notice-alt below-h2 is-dismissible">109 <strong><?php esc_html_e( 'Pantheon Decoupled Preview Example', 'wp-decoupled-preview' ); ?></strong>110 <p class="decoupled-preview-example">111 <label for="new-decoupled-preview-example-value">112 <?php echo wp_kses( __( 'The shared secret of the <strong>Example NextJS Preview</strong> site is:', 'wp-decoupled-preview' ), [ 'strong' => [] ] ); ?>113 </label>114 <input type="text" class="code" value="<?php printf( esc_attr( get_transient( 'example_preview_password' ) ) ); ?>" />115 </p>116 <p><?php esc_html_e( 'Be sure to save this in a safe location. You will not be able to retrieve it.', 'wp-decoupled-preview' ); ?></p>117 </div>118 <?php119 delete_transient( 'example_preview_password' );120 }121 }122 123 /**124 * Delete preview sites options when deactivation plugin.125 *126 * @return void127 */128 function delete_default_options() {129 delete_option( 'preview_sites' );130 71 } 131 72 -
decoupled-preview/trunk/CONTRIBUTING.MD
r2920738 r2955124 11 11 Development and releases are structured around two branches, `develop` and `main`. The `develop` branch is the default branch for the repository, and is the source and destination for feature branches. 12 12 13 We prefer to squash commits (i.e. avoid merge PRs) from a feature branch into `develop` when merging, and to include the PR # in the commit message. PRs to `develop` should also include any relev ent updates to the changelog in readme.txt. For example, if a feature constitutes a minor or major version bump, that version update should be discussed and made as part of approving and merging the feature into `develop`.13 We prefer to squash commits (i.e. avoid merge PRs) from a feature branch into `develop` when merging, and to include the PR # in the commit message. PRs to `develop` should also include any relevant updates to the changelog in readme.txt. For example, if a feature constitutes a minor or major version bump, that version update should be discussed and made as part of approving and merging the feature into `develop`. 14 14 15 15 `develop` should be stable and usable, though possibly a few commits ahead of the public release on wp.org. -
decoupled-preview/trunk/readme.txt
r2927210 r2955124 3 3 Tags: headless,next.js,decoupled,preview 4 4 Tested up to: 6.2.2 5 Stable tag: 1.0. 35 Stable tag: 1.0.4 6 6 License: GPL2 or later 7 7 License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html … … 56 56 == Changelog == 57 57 58 = 1.0.4 = 59 * Improve Handling of secrets field. [[#53](https://github.com/pantheon-systems/wp-decoupled-preview/pull/53)] 60 * Move set default preview site functionality to wp-pantheon-decoupled. [[#54](https://github.com/pantheon-systems/wp-decoupled-preview/pull/54)] 61 58 62 = 1.0.3 = 59 63 * Bugfix for cases where Decoupled Preview link did not load due to a js error. [[#43](https://github.com/pantheon-systems/wp-decoupled-preview/pull/43)] -
decoupled-preview/trunk/src/class-decoupled-preview-settings.php
r2898067 r2955124 75 75 esc_html__( 'Content Type', 'wp-decoupled-preview' ), 76 76 [ &$this, 'setting_content_type_fn' ], 77 'preview_sites', 78 'wp-decoupled-preview-section' 79 ); 80 add_settings_field( 81 'plugin_dropdown_user', 82 esc_html__( 'Associated User', 'wp-decoupled-preview' ), 83 [ &$this, 'setting_associated_user_fn' ], 77 84 'preview_sites', 78 85 'wp-decoupled-preview-section' … … 298 305 299 306 // Bail early if we are missing required data. 300 if ( in_array( '', [ $input['label'], $input['url'], $input['preview_type'] ], true ) ) {307 if ( in_array( '', [ $input['label'], $input['url'], $input['preview_type'], $input['secret_string'] ], true ) ) { 301 308 return []; 302 309 } … … 315 322 316 323 if ( $options && isset( $edit_id ) ) { 317 // If we're editing an existing site, preserve the secret key if it's not being changed.318 if ( empty( $input['secret_string'] ) ) {319 $sanitized_input['secret_string'] = sanitize_text_field( $options['preview'][ $edit_id ]['secret_string'] );320 }321 322 324 // If we're editing an existing site, check to make sure there's an ID set. 323 325 if ( empty( $input['id'] ) ) { … … 335 337 if ( isset( $input['secret_string'] ) ) { 336 338 $sanitized_input['secret_string'] = sanitize_text_field( $input['secret_string'] ); 339 } 340 if ( empty( $input['associated_user'] ) ) { 341 $sanitized_input['associated_user'] = ''; 342 } else { 343 $sanitized_input['associated_user'] = sanitize_text_field( $input['associated_user'] ); 337 344 } 338 345 $edit_id = ! isset( $edit_id ) || $edit_id !== $sanitized_input['id'] ? $sanitized_input['id'] : $edit_id; … … 466 473 check_admin_referer( 'edit-preview-site', 'nonce' ); 467 474 $edit_id = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : false; 475 $site = $this->get_preview_site( $edit_id ); 476 $value = $edit_id ? $site['secret_string'] : ''; 468 477 ob_start(); 469 478 if ( $edit_id ) { 470 479 ?> 471 <input id="plugin_text_secret" name="preview_sites[secret_string]" size="40" type="password" /><br />472 <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>480 <input id="plugin_text_secret" name="preview_sites[secret_string]" size="40" type="password" value="<?php echo esc_attr( $value ); ?>" required /><br /> 481 <span class="description"><?php esc_html_e( '(Required) Shared secret for the preview site.', 'wp-decoupled-preview' ); ?></span> 473 482 <?php 474 483 } else { … … 560 569 561 570 /** 571 * Associated User 572 * 573 * @return void 574 */ 575 public function setting_associated_user_fn() { 576 check_admin_referer( 'edit-preview-site', 'nonce' ); 577 $edit_id = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : false; 578 $site = $this->get_preview_site( $edit_id ); 579 $users = get_users( [ 'fields' => [ 'display_name' ] ] ); 580 if ( isset( $edit_id ) ) { 581 ?> 582 <label for="associated_user">Choose an associated user:</label> 583 <select id="associated_user" name="preview_sites[associated_user]" autocomplete="username"> 584 <option value="" selected="<?php $site['associated_user'] === ''; ?>">--None--</option> 585 <?php 586 foreach ( $users as $user ) { 587 $selected = ( $site['associated_user'] === $user->display_name ) ? 'selected="selected"' : ''; 588 ?> 589 <option value="<?php echo esc_attr( $user->display_name ); ?>" <?php echo esc_attr( $selected ); ?>><?php echo esc_html( $user->display_name ); ?></option> 590 <?php 591 } 592 ?> 593 </select> 594 <?php 595 } 596 } 597 598 /** 562 599 * Get the List of the configured sites or specific site. 563 600 * -
decoupled-preview/trunk/src/class-list-table.php
r2898067 r2955124 98 98 'preview_type' => __( 'Preview Type', 'wp-decoupled-preview' ), 99 99 'content_type' => __( 'Content Type', 'wp-decoupled-preview' ), 100 'associated_user' => __( 'Associated User', 'wp-decoupled-preview' ), 100 101 'actions' => __( 'Actions', 'wp-decoupled-preview' ), 101 102 ]; … … 113 114 case 'label': 114 115 case 'url': 116 case 'associated_user': 115 117 case 'preview_type': 116 118 return isset( $item[ $column_name ] ) ? esc_html( $item[ $column_name ] ) : ''; -
decoupled-preview/trunk/wp-decoupled-preview.php
r2927210 r2955124 4 4 * Plugin URI: https://github.com/pantheon-systems/wp-decoupled-preview 5 5 * Description: Preview WordPress content on Front-end sites including Next.js 6 * Version: 1.0. 36 * Version: 1.0.4 7 7 * Author: Pantheon 8 8 * Author URI: https://pantheon.io/ … … 38 38 39 39 add_action( 'init', __NAMESPACE__ . '\\conditionally_enqueue_scripts' ); 40 add_action( 'admin_notices', __NAMESPACE__ . '\\show_example_preview_password_admin_notice' );41 40 add_action( 'updated_option', __NAMESPACE__ . '\\redirect_to_preview_site' ); 42 41 … … 70 69 add_filter( 'template_include', __NAMESPACE__ . '\\override_preview_template', 1 ); 71 70 } 72 }73 74 /**75 * Set default values for the preview sites options.76 *77 * @return void78 */79 function set_default_options() {80 $secret = wp_generate_password( 10, false );81 set_transient( 'example_preview_password', $secret );82 83 add_option(84 'preview_sites',85 [86 'preview' => [87 1 => [88 'label' => esc_html__( 'Example NextJS Preview', 'wp-decoupled-preview' ),89 'url' => 'https://example.com/api/preview',90 'secret_string' => $secret,91 'preview_type' => 'Next.js',92 'id' => 1,93 ],94 ],95 ]96 );97 }98 99 /**100 * Show example preview password admin notice.101 *102 * @return void103 */104 function show_example_preview_password_admin_notice() {105 $preview_password = get_transient( 'example_preview_password' );106 if ( $preview_password ) {107 ?>108 <div class="notice notice-success notice-alt below-h2 is-dismissible">109 <strong><?php esc_html_e( 'Pantheon Decoupled Preview Example', 'wp-decoupled-preview' ); ?></strong>110 <p class="decoupled-preview-example">111 <label for="new-decoupled-preview-example-value">112 <?php echo wp_kses( __( 'The shared secret of the <strong>Example NextJS Preview</strong> site is:', 'wp-decoupled-preview' ), [ 'strong' => [] ] ); ?>113 </label>114 <input type="text" class="code" value="<?php printf( esc_attr( get_transient( 'example_preview_password' ) ) ); ?>" />115 </p>116 <p><?php esc_html_e( 'Be sure to save this in a safe location. You will not be able to retrieve it.', 'wp-decoupled-preview' ); ?></p>117 </div>118 <?php119 delete_transient( 'example_preview_password' );120 }121 }122 123 /**124 * Delete preview sites options when deactivation plugin.125 *126 * @return void127 */128 function delete_default_options() {129 delete_option( 'preview_sites' );130 71 } 131 72
Note: See TracChangeset
for help on using the changeset viewer.