Changeset 14075
- Timestamp:
- 09/24/2024 07:12:05 AM (6 weeks ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-blueprint.php
r13335 r14075 44 44 } 45 45 46 47 46 $blueprints = get_post_meta( $plugin->ID, 'assets_blueprints', true ); 47 // Note: for now, only use a file called `blueprint.json`. 48 48 if ( !isset( $blueprints['blueprint.json'] ) ) { 49 49 return new \WP_Error( 'no_blueprint', 'File not found', array( 'status' => 404 ) ); 50 51 52 50 } 51 $blueprint = $blueprints['blueprint.json']; 52 if ( !$blueprint || !isset( $blueprint['contents'] ) || !is_string( $blueprint['contents'] ) ) { 53 53 return new \WP_Error( 'invalid_blueprint', 'Invalid file', array( 'status' => 500 ) ); 54 } 54 } 55 56 if ( $request->get_param('lang') && 'en' !== strtolower( substr( $request->get_param('lang'), 0, 2 ) ) ) { 57 // Check if there's already a setSiteLanguage step 58 $blueprint_data = json_decode( $blueprint['contents'] ); 59 if ( isset( $blueprint_data->steps ) ) { 60 if ( !in_array( 'setSiteLanguage', wp_list_pluck( $blueprint_data->steps, 'step' ) ) ) { 61 // Add setSiteLanguage as the final step 62 array_push( $blueprint_data->steps, 63 (object)[ 64 'step' => 'setSiteLanguage', 65 'language' => sanitize_text_field( $request->get_param('lang') ) 66 ] 67 ); 68 } 69 } else { 70 // No steps in blueprint, so create one 71 $blueprint_data->steps = [ 72 (object)[ 73 'step' => 'setSiteLanguage', 74 'language' => sanitize_text_field( $request->get_param('lang') ) 75 ] 76 ]; 77 } 78 header( 'Access-Control-Allow-Origin: *' ); 79 return $blueprint_data; 80 } 55 81 56 82 // Configure this elsewhere? -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r13673 r14075 752 752 * @return false|string The preview url. False if no preview is configured. 753 753 */ 754 public static function preview_link( $post = null ) {754 public static function preview_link( $post = null, $locale = null ) { 755 755 $post = get_post( $post ); 756 756 … … 762 762 $blueprint = $blueprints['blueprint.json']; 763 763 764 return sprintf( 'https://playground.wordpress.net/?plugin=%s&blueprint-url=%s', esc_attr($post->post_name), esc_attr($blueprint['url'] ) ); 764 $blueprint_url = $blueprint['url']; 765 $locale = $locale ?? get_locale(); 766 $blueprint_url = add_query_arg( 'lang', $locale, $blueprint_url ); 767 768 return sprintf( 'https://playground.wordpress.net/?plugin=%s&blueprint-url=%s', esc_attr($post->post_name), rawurlencode($blueprint_url) ); 765 769 } 766 770
Note: See TracChangeset
for help on using the changeset viewer.