Making WordPress.org


Ignore:
Timestamp:
12/21/2023 05:40:09 AM (9 months ago)
Author:
tellyworth
Message:

Plugin Dir: Add Preview links for moderators in plugin queue

This adds private Playground Preview links for the plugin review team to more easily test newly submitted plugins that have not yet been published.

Plugins are loaded with plugin-check active.

See #7380.

File:
1 edited

Legend:

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

    r13061 r13076  
    763763
    764764        return sprintf( 'https://playground.wordpress.net/?plugin=%s&blueprint-url=%s', esc_attr($post->post_name), esc_attr($blueprint['url'] ) );
     765    }
     766
     767    /**
     768     * Generate a live preview (playground) link for a zip attachment. Needed for newly uploaded plugins that have not yet been published.
     769     *
     770     * @param string $slug            The slug of the plugin post.
     771     * @param int $attachment_id      The ID of the attachment post corresponding to a plugin zip file. Must be attached to the post identified by $slug.
     772     * @return false|string           The preview URL.
     773     */
     774    public static function preview_link_zip( $slug, $attachment_id ) {
     775
     776        $zip_hash = self::preview_link_hash( $attachment_id );
     777        if ( !$zip_hash ) {
     778            return false;
     779        }
     780        $zip_blueprint = sprintf( 'https://wordpress.org/plugins/wp-json/plugins/v1/plugin/%s/blueprint.json?zip_hash=%s', esc_attr( $slug ), esc_attr( $zip_hash ) );
     781        $zip_preview = add_query_arg( 'blueprint-url', urlencode($zip_blueprint), 'https://playground.wordpress.net/' );
     782
     783        return $zip_preview;
     784    }
     785
     786    /**
     787     * Return a time-dependent variable for zip preview links.
     788     *
     789     * @param int $lifespan           The life span of the nonce, in seconds. Default is one week.
     790     * @return float                  The tick value.
     791     */
     792    public static function preview_link_tick( $lifespan = WEEK_IN_SECONDS ) {
     793        return ceil( time() / ( $lifespan / 2 ) );
     794    }
     795
     796    /**
     797     * Return a nonce-style hash for zip preview links.
     798     *
     799     * @param int $attachment_id      The ID of the attachment post corresponding to a plugin zip file.
     800     * @param int $tick_offest        Number to subtract from the nonce tick. Use both 0 and -1 to verify older nonces.
     801     * @return false|string           The hash as a hex string; or false if the attachment ID is invalid.
     802     */
     803    public static function preview_link_hash( $attachment_id, $tick_offset = 0 ) {
     804        $file = get_attached_file( $attachment_id );
     805        if ( !$file ) {
     806            return false;
     807        }
     808        $tick = self::preview_link_tick() - $tick_offset;
     809        return wp_hash( $tick . '|' . $file, 'nonce' );
    765810    }
    766811
Note: See TracChangeset for help on using the changeset viewer.