Changeset 13335 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
- Timestamp:
- 03/14/2024 05:40:44 AM (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r13310 r13335 774 774 public static function preview_link_zip( $slug, $attachment_id, $type = null ) { 775 775 776 $zip_hash = self::preview_link_hash( $attachment_id ); 776 $file = get_attached_file( $attachment_id ); 777 $zip_hash = self::preview_link_hash( $file ); 777 778 if ( !$zip_hash ) { 778 779 return false; … … 788 789 789 790 /** 791 * Generate a live preview (playground) link for a published plugin that does not yet have a custom blueprint. Needed for developer testing. 792 * 793 * @param string $slug The slug of the plugin post. 794 * @param int $download_link The URL of the zip download for the plugin. 795 * @param bool $blueprint_only False will return a full preview URL. True will return only a blueprint URL. 796 * @return false|string The preview or blueprint URL. 797 */ 798 public static function preview_link_developer( $slug, $download_link, $blueprint_only = false ) { 799 800 $url_hash = self::preview_link_hash( $download_link ); 801 if ( !$url_hash ) { 802 return false; 803 } 804 $dev_blueprint = sprintf( 'https://wordpress.org/plugins/wp-json/plugins/v1/plugin/%s/blueprint.json?url_hash=%s', esc_attr( $slug ), esc_attr( $url_hash ) ); 805 if ( $blueprint_only ) { 806 return $dev_blueprint; 807 } 808 $url_preview = add_query_arg( 'blueprint-url', urlencode($dev_blueprint), 'https://playground.wordpress.net/' ); 809 810 return $url_preview; 811 } 812 813 /** 790 814 * Return a time-dependent variable for zip preview links. 791 815 * … … 800 824 * Return a nonce-style hash for zip preview links. 801 825 * 802 * @param int $attachment_id The ID of the attachment post corresponding to a pluginzip file.826 * @param string $zip_file The filesystem path or URL of the zip file. 803 827 * @param int $tick_offest Number to subtract from the nonce tick. Use both 0 and -1 to verify older nonces. 804 828 * @return false|string The hash as a hex string; or false if the attachment ID is invalid. 805 829 */ 806 public static function preview_link_hash( $attachment_id, $tick_offset = 0 ) { 807 $file = get_attached_file( $attachment_id ); 808 if ( !$file ) { 830 public static function preview_link_hash( $zip_file, $tick_offset = 0 ) { 831 if ( !$zip_file ) { 809 832 return false; 810 833 } 811 834 $tick = self::preview_link_tick() - $tick_offset; 812 return wp_hash( $tick . '|' . $ file, 'nonce' );835 return wp_hash( $tick . '|' . $zip_file, 'nonce' ); 813 836 } 814 837 … … 912 935 return add_query_arg( 913 936 array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ), 937 home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-toggle-preview' ) 938 ); 939 } 940 941 /** 942 * Generates a link to dismiss a missing blueprint notice. 943 * 944 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 945 * @return string URL to toggle status. 946 */ 947 public static function get_self_dismiss_blueprint_notice_link( $post = null ) { 948 $post = get_post( $post ); 949 950 return add_query_arg( 951 array( '_wpnonce' => wp_create_nonce( 'wp_rest' ), 'dismiss' => 1 ), 914 952 home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-toggle-preview' ) 915 953 );
Note: See TracChangeset
for help on using the changeset viewer.