Changeset 12975 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
- Timestamp:
- 11/22/2023 06:44:21 AM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r12933 r12975 723 723 724 724 /** 725 * Is a live preview available for the plugin, and allowed for the current user to view? 726 * 727 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 728 * @return bool True if a preview is available and the current user is permitted to see it. 729 */ 730 public static function is_preview_available( $post = null ) { 731 732 if ( self::preview_link( $post ) ) { 733 // Plugin committers can always use the plugin preview button if it exists. 734 if ( current_user_can( 'plugin_admin_edit', $post ) ) { 735 return true; 736 } 737 } 738 return false; 739 } 740 741 /** 725 742 * Generate a live preview (playground) link for a given plugin. 726 743 * 727 744 * @param int|\WP_Post|null $post Optional. Post ID or post object. Defaults to global $post. 728 * @param string $landing_page The landing page for the preview. Option. Default: /wp-admin/plugins.php. 729 * @return string The preview url. 730 */ 731 public static function preview_link( $post = null, $landing_page = '/wp-admin/plugins.php' ) { 745 * @return false|string The preview url. False if no preview is configured. 746 */ 747 public static function preview_link( $post = null ) { 732 748 $post = get_post( $post ); 733 749 734 return sprintf( 'https://playground.wordpress.net/?plugin=%s&login=1&url=%s', esc_attr( $post->post_name ), esc_attr( $landing_page ) ); 750 $blueprints = get_post_meta( $post->ID, 'assets_blueprints', true ); 751 // Note: for now, only use a file called `blueprint.json`. 752 if ( !isset( $blueprints['blueprint.json'] ) ) { 753 return false; 754 } 755 $blueprint = $blueprints['blueprint.json']; 756 if ( !$blueprint || !isset( $blueprint['contents'] ) || !is_string( $blueprint['contents'] ) ) { 757 return false; 758 } 759 760 $blueprint_encoded = esc_html( $blueprint['contents'] ); 761 762 return sprintf( 'https://playground.wordpress.net/?plugin=%s#%s', $post->post_name, $blueprint_encoded ); 735 763 } 736 764
Note: See TracChangeset
for help on using the changeset viewer.