- Timestamp:
- 09/20/2024 02:05:50 AM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
r58707 r59073 327 327 */ 328 328 public function get_item( $request ) { 329 if ( isset( $request['source'] ) && 'theme' === $request['source']) {329 if ( isset( $request['source'] ) && ( 'theme' === $request['source'] || 'plugin' === $request['source'] ) ) { 330 330 $template = get_block_file_template( $request['id'], $this->post_type ); 331 331 } else { … … 777 777 } 778 778 779 if ( rest_is_field_included( 'plugin', $fields ) ) { 780 $registered_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $template->slug ); 781 if ( $registered_template ) { 782 $data['plugin'] = $registered_template->plugin; 783 } 784 } 785 779 786 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 780 787 $data = $this->add_additional_fields_to_object( $data, $request ); … … 832 839 833 840 // Added by plugin. 834 if ( $template_object->has_theme_file &&'plugin' === $template_object->origin ) {841 if ( 'plugin' === $template_object->origin ) { 835 842 return 'plugin'; 836 843 } … … 866 873 return empty( $theme_name ) ? $template_object->theme : $theme_name; 867 874 case 'plugin': 868 $plugins = get_plugins(); 869 $plugin = $plugins[ plugin_basename( sanitize_text_field( $template_object->theme . '.php' ) ) ]; 870 return empty( $plugin['Name'] ) ? $template_object->theme : $plugin['Name']; 875 if ( ! function_exists( 'get_plugins' ) || ! function_exists( 'get_plugin_data' ) ) { 876 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 877 } 878 if ( isset( $template_object->plugin ) ) { 879 $plugins = wp_get_active_and_valid_plugins(); 880 881 foreach ( $plugins as $plugin_file ) { 882 $plugin_basename = plugin_basename( $plugin_file ); 883 // Split basename by '/' to get the plugin slug. 884 list( $plugin_slug, ) = explode( '/', $plugin_basename ); 885 886 if ( $plugin_slug === $template_object->plugin ) { 887 $plugin_data = get_plugin_data( $plugin_file ); 888 889 if ( ! empty( $plugin_data['Name'] ) ) { 890 return $plugin_data['Name']; 891 } 892 893 break; 894 } 895 } 896 } 897 898 /* 899 * Fall back to the theme name if the plugin is not defined. That's needed to keep backwards 900 * compatibility with templates that were registered before the plugin attribute was added. 901 */ 902 $plugins = get_plugins(); 903 $plugin_basename = plugin_basename( sanitize_text_field( $template_object->theme . '.php' ) ); 904 if ( isset( $plugins[ $plugin_basename ] ) && isset( $plugins[ $plugin_basename ]['Name'] ) ) { 905 return $plugins[ $plugin_basename ]['Name']; 906 } 907 return isset( $template_object->plugin ) ? 908 $template_object->plugin : 909 $template_object->theme; 871 910 case 'site': 872 911 return get_bloginfo( 'name' ); … … 1135 1174 'readonly' => true, 1136 1175 ); 1176 $schema['properties']['plugin'] = array( 1177 'type' => 'string', 1178 'description' => __( 'Plugin that registered the template.' ), 1179 'readonly' => true, 1180 'context' => array( 'view', 'edit', 'embed' ), 1181 ); 1137 1182 } 1138 1183
Note: See TracChangeset
for help on using the changeset viewer.