Plugin Directory

Changeset 2955124


Ignore:
Timestamp:
08/17/2023 10:04:57 PM (3 years ago)
Author:
getpantheon
Message:

Update to version 1.0.4 from GitHub

Location:
decoupled-preview
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • decoupled-preview/tags/1.0.4/CONTRIBUTING.MD

    r2920738 r2955124  
    1111Development 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.
    1212
    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 relevent 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`.
     13We 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`.
    1414
    1515`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  
    33Tags: headless,next.js,decoupled,preview
    44Tested up to: 6.2.2
    5 Stable tag: 1.0.3
     5Stable tag: 1.0.4
    66License: GPL2 or later
    77License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
     
    5656== Changelog ==
    5757
     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
    5862= 1.0.3 =
    5963* 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  
    7575                esc_html__( 'Content Type', 'wp-decoupled-preview' ),
    7676                [ &$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' ],
    7784                'preview_sites',
    7885                'wp-decoupled-preview-section'
     
    298305
    299306            // 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 ) ) {
    301308                return [];
    302309            }
     
    315322
    316323            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 
    322324                // If we're editing an existing site, check to make sure there's an ID set.
    323325                if ( empty( $input['id'] ) ) {
     
    335337            if ( isset( $input['secret_string'] ) ) {
    336338                $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'] );
    337344            }
    338345            $edit_id = ! isset( $edit_id ) || $edit_id !== $sanitized_input['id'] ? $sanitized_input['id'] : $edit_id;
     
    466473            check_admin_referer( 'edit-preview-site', 'nonce' );
    467474            $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'] : '';
    468477            ob_start();
    469478            if ( $edit_id ) {
    470479                ?>
    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>
    473482                <?php
    474483            } else {
     
    560569
    561570        /**
     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        /**
    562599         * Get the List of the configured sites or specific site.
    563600         *
  • decoupled-preview/tags/1.0.4/src/class-list-table.php

    r2898067 r2955124  
    9898            'preview_type' => __( 'Preview Type', 'wp-decoupled-preview' ),
    9999            'content_type' => __( 'Content Type', 'wp-decoupled-preview' ),
     100            'associated_user' => __( 'Associated User', 'wp-decoupled-preview' ),
    100101            'actions' => __( 'Actions', 'wp-decoupled-preview' ),
    101102        ];
     
    113114            case 'label':
    114115            case 'url':
     116            case 'associated_user':
    115117            case 'preview_type':
    116118                return isset( $item[ $column_name ] ) ? esc_html( $item[ $column_name ] ) : '';
  • decoupled-preview/tags/1.0.4/wp-decoupled-preview.php

    r2927210 r2955124  
    44 * Plugin URI:      https://github.com/pantheon-systems/wp-decoupled-preview
    55 * Description:     Preview WordPress content on Front-end sites including Next.js
    6  * Version:         1.0.3
     6 * Version:         1.0.4
    77 * Author:          Pantheon
    88 * Author URI:      https://pantheon.io/
     
    3838
    3939    add_action( 'init', __NAMESPACE__ . '\\conditionally_enqueue_scripts' );
    40     add_action( 'admin_notices', __NAMESPACE__ . '\\show_example_preview_password_admin_notice' );
    4140    add_action( 'updated_option', __NAMESPACE__ . '\\redirect_to_preview_site' );
    4241
     
    7069        add_filter( 'template_include', __NAMESPACE__ . '\\override_preview_template', 1 );
    7170    }
    72 }
    73 
    74 /**
    75  * Set default values for the preview sites options.
    76  *
    77  * @return void
    78  */
    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 void
    103  */
    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         <?php
    119         delete_transient( 'example_preview_password' );
    120     }
    121 }
    122 
    123 /**
    124  * Delete preview sites options when deactivation plugin.
    125  *
    126  * @return void
    127  */
    128 function delete_default_options() {
    129     delete_option( 'preview_sites' );
    13071}
    13172
  • decoupled-preview/trunk/CONTRIBUTING.MD

    r2920738 r2955124  
    1111Development 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.
    1212
    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 relevent 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`.
     13We 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`.
    1414
    1515`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  
    33Tags: headless,next.js,decoupled,preview
    44Tested up to: 6.2.2
    5 Stable tag: 1.0.3
     5Stable tag: 1.0.4
    66License: GPL2 or later
    77License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
     
    5656== Changelog ==
    5757
     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
    5862= 1.0.3 =
    5963* 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  
    7575                esc_html__( 'Content Type', 'wp-decoupled-preview' ),
    7676                [ &$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' ],
    7784                'preview_sites',
    7885                'wp-decoupled-preview-section'
     
    298305
    299306            // 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 ) ) {
    301308                return [];
    302309            }
     
    315322
    316323            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 
    322324                // If we're editing an existing site, check to make sure there's an ID set.
    323325                if ( empty( $input['id'] ) ) {
     
    335337            if ( isset( $input['secret_string'] ) ) {
    336338                $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'] );
    337344            }
    338345            $edit_id = ! isset( $edit_id ) || $edit_id !== $sanitized_input['id'] ? $sanitized_input['id'] : $edit_id;
     
    466473            check_admin_referer( 'edit-preview-site', 'nonce' );
    467474            $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'] : '';
    468477            ob_start();
    469478            if ( $edit_id ) {
    470479                ?>
    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>
    473482                <?php
    474483            } else {
     
    560569
    561570        /**
     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        /**
    562599         * Get the List of the configured sites or specific site.
    563600         *
  • decoupled-preview/trunk/src/class-list-table.php

    r2898067 r2955124  
    9898            'preview_type' => __( 'Preview Type', 'wp-decoupled-preview' ),
    9999            'content_type' => __( 'Content Type', 'wp-decoupled-preview' ),
     100            'associated_user' => __( 'Associated User', 'wp-decoupled-preview' ),
    100101            'actions' => __( 'Actions', 'wp-decoupled-preview' ),
    101102        ];
     
    113114            case 'label':
    114115            case 'url':
     116            case 'associated_user':
    115117            case 'preview_type':
    116118                return isset( $item[ $column_name ] ) ? esc_html( $item[ $column_name ] ) : '';
  • decoupled-preview/trunk/wp-decoupled-preview.php

    r2927210 r2955124  
    44 * Plugin URI:      https://github.com/pantheon-systems/wp-decoupled-preview
    55 * Description:     Preview WordPress content on Front-end sites including Next.js
    6  * Version:         1.0.3
     6 * Version:         1.0.4
    77 * Author:          Pantheon
    88 * Author URI:      https://pantheon.io/
     
    3838
    3939    add_action( 'init', __NAMESPACE__ . '\\conditionally_enqueue_scripts' );
    40     add_action( 'admin_notices', __NAMESPACE__ . '\\show_example_preview_password_admin_notice' );
    4140    add_action( 'updated_option', __NAMESPACE__ . '\\redirect_to_preview_site' );
    4241
     
    7069        add_filter( 'template_include', __NAMESPACE__ . '\\override_preview_template', 1 );
    7170    }
    72 }
    73 
    74 /**
    75  * Set default values for the preview sites options.
    76  *
    77  * @return void
    78  */
    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 void
    103  */
    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         <?php
    119         delete_transient( 'example_preview_password' );
    120     }
    121 }
    122 
    123 /**
    124  * Delete preview sites options when deactivation plugin.
    125  *
    126  * @return void
    127  */
    128 function delete_default_options() {
    129     delete_option( 'preview_sites' );
    13071}
    13172
Note: See TracChangeset for help on using the changeset viewer.