Making WordPress.org

Changeset 12999


Ignore:
Timestamp:
12/04/2023 04:42:52 AM (15 months ago)
Author:
tellyworth
Message:

Plugins: improved Test Preview button

This uses the new Playground blueprint-url param to pass the blueprint rather than a URL fragment.

Also, opens the preview in a new tab, as per suggestions.

See #7251.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/class-base.php

    r12933 r12999  
    3939        new Routes\Plugin_Categorization();
    4040        new Routes\Plugin_Upload();
     41        new Routes\Plugin_Blueprint();
    4142    }
    4243
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php

    r12998 r12999  
    3737        $blueprints = get_post_meta( $plugin->ID, 'assets_blueprints', true );
    3838        // Note: for now, only use a file called `blueprint.json`.
    39         if ( !isset( $blueprints['blueprint.json'] ) ) {
    40             return false;
     39        if ( !isset( $blueprints['blueprint.json'] ) ) {
     40            return new \WP_Error( 'no_blueprint', 'File not found', array( 'status' => 404 ) );
    4141        }
    4242        $blueprint = $blueprints['blueprint.json'];
    4343        if ( !$blueprint || !isset( $blueprint['contents'] ) || !is_string( $blueprint['contents'] ) ) {
    44             return false;
     44            return new \WP_Error( 'invalid_blueprint', 'Invalid file', array( 'status' => 500 ) );
    4545        }
    4646
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r12816 r12999  
    5050        add_action( 'wp_head', array( Template::class, 'json_ld_schema' ), 1 );
    5151        add_action( 'wp_head', array( Template::class, 'hreflang_link_attributes' ), 2 );
     52        add_filter( 'allowed_redirect_hosts', array( $this, 'filter_redirect_hosts' ) );
    5253
    5354        // Add no-index headers where appropriate.
     
    13921393        }
    13931394
     1395        if ( is_single() && isset( $_GET['preview'] ) && Template::is_preview_available( ) ) {
     1396            if ( $preview_url = Template::preview_link() ) {
     1397                wp_safe_redirect( $preview_url, 302 );
     1398                die;
     1399            }
     1400        }
     1401
    13941402        if ( is_comment_feed() ) {
    13951403            wp_redirect( 'https://wordpress.org/plugins/', 301 );
     
    13971405        }
    13981406
     1407    }
     1408
     1409    /**
     1410     * Filter allowed_redirect_hosts to allow safe redirect to trusted hosts.
     1411     * @param array $hosts
     1412     */
     1413    function filter_redirect_hosts( $hosts ) {
     1414        $hosts[] = 'playground.wordpress.net';
     1415
     1416        return $hosts;
    13991417    }
    14001418
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r12978 r12999  
    758758        }
    759759
    760         $blueprint_encoded = esc_html( str_replace( '%', '%25', $blueprint['contents'] ) );
    761 
    762         return sprintf( 'https://playground.wordpress.net/?plugin=%s#%s', $post->post_name, $blueprint_encoded );
     760        $blueprint_url = sprintf( 'https://wordpress.org/plugins/wp-json/plugins/v1/plugin/%s/blueprint.json?rev=%d', $post->post_name, $blueprint['revision'] );
     761
     762        return sprintf( 'https://playground.wordpress.net/?plugin=%s&blueprint-url=%s', esc_attr($post->post_name), esc_attr($blueprint_url ) );
    763763    }
    764764
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php

    r12976 r12999  
    4343            <?php endif; ?>
    4444            <?php if ( current_user_can( 'plugin_admin_edit', $post ) && Template::is_preview_available() ) : ?>
    45                 <a class="plugin-preview button download-button button-large" href="<?php echo esc_html( Template::preview_link() ); ?>"><?php esc_html_e( 'Test Preview', 'wporg-plugins' ); ?></a>
     45                <a class="plugin-preview button download-button button-large" target="_blank" href="<?php echo esc_attr( add_query_arg( array( 'preview' => 1 ), get_the_permalink() ) ); ?>"><?php esc_html_e( 'Test Preview', 'wporg-plugins' ); ?></a>
    4646            <?php endif; ?>
    4747        </div>
Note: See TracChangeset for help on using the changeset viewer.