wp/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   199 
   199 
   200 		$active_themes = wp_get_themes();
   200 		$active_themes = wp_get_themes();
   201 		$current_theme = wp_get_theme();
   201 		$current_theme = wp_get_theme();
   202 		$status        = $request['status'];
   202 		$status        = $request['status'];
   203 
   203 
   204 		foreach ( $active_themes as $theme_name => $theme ) {
   204 		foreach ( $active_themes as $theme ) {
   205 			$theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive';
   205 			$theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive';
   206 			if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) {
   206 			if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) {
   207 				continue;
   207 				continue;
   208 			}
   208 			}
   209 
   209 
   344 			if ( $this->is_same_theme( $theme, $current_theme ) ) {
   344 			if ( $this->is_same_theme( $theme, $current_theme ) ) {
   345 				$data['template_uri'] = get_template_directory_uri();
   345 				$data['template_uri'] = get_template_directory_uri();
   346 			} else {
   346 			} else {
   347 				$data['template_uri'] = $theme->get_template_directory_uri();
   347 				$data['template_uri'] = $theme->get_template_directory_uri();
   348 			}
   348 			}
       
   349 		}
       
   350 
       
   351 		if ( rest_is_field_included( 'default_template_types', $fields ) && $this->is_same_theme( $theme, $current_theme ) ) {
       
   352 			$default_template_types = array();
       
   353 			foreach ( get_default_block_template_types() as $slug => $template_type ) {
       
   354 				$template_type['slug']    = (string) $slug;
       
   355 				$default_template_types[] = $template_type;
       
   356 			}
       
   357 			$data['default_template_types'] = $default_template_types;
       
   358 		}
       
   359 
       
   360 		if ( rest_is_field_included( 'default_template_part_areas', $fields ) && $this->is_same_theme( $theme, $current_theme ) ) {
       
   361 			$data['default_template_part_areas'] = get_allowed_block_template_part_areas();
   349 		}
   362 		}
   350 
   363 
   351 		$data = $this->add_additional_fields_to_object( $data, $request );
   364 		$data = $this->add_additional_fields_to_object( $data, $request );
   352 
   365 
   353 		// Wrap the data in a response object.
   366 		// Wrap the data in a response object.
   457 		$schema = array(
   470 		$schema = array(
   458 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
   471 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
   459 			'title'      => 'theme',
   472 			'title'      => 'theme',
   460 			'type'       => 'object',
   473 			'type'       => 'object',
   461 			'properties' => array(
   474 			'properties' => array(
   462 				'stylesheet'     => array(
   475 				'stylesheet'                  => array(
   463 					'description' => __( 'The theme\'s stylesheet. This uniquely identifies the theme.' ),
   476 					'description' => __( 'The theme\'s stylesheet. This uniquely identifies the theme.' ),
   464 					'type'        => 'string',
   477 					'type'        => 'string',
   465 					'readonly'    => true,
   478 					'readonly'    => true,
   466 				),
   479 				),
   467 				'stylesheet_uri' => array(
   480 				'stylesheet_uri'              => array(
   468 					'description' => __( 'The uri for the theme\'s stylesheet directory.' ),
   481 					'description' => __( 'The uri for the theme\'s stylesheet directory.' ),
   469 					'type'        => 'string',
   482 					'type'        => 'string',
   470 					'format'      => 'uri',
   483 					'format'      => 'uri',
   471 					'readonly'    => true,
   484 					'readonly'    => true,
   472 				),
   485 				),
   473 				'template'       => array(
   486 				'template'                    => array(
   474 					'description' => __( 'The theme\'s template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet.' ),
   487 					'description' => __( 'The theme\'s template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet.' ),
   475 					'type'        => 'string',
   488 					'type'        => 'string',
   476 					'readonly'    => true,
   489 					'readonly'    => true,
   477 				),
   490 				),
   478 				'template_uri'   => array(
   491 				'template_uri'                => array(
   479 					'description' => __( 'The uri for the theme\'s template directory. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet directory.' ),
   492 					'description' => __( 'The uri for the theme\'s template directory. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet directory.' ),
   480 					'type'        => 'string',
   493 					'type'        => 'string',
   481 					'format'      => 'uri',
   494 					'format'      => 'uri',
   482 					'readonly'    => true,
   495 					'readonly'    => true,
   483 				),
   496 				),
   484 				'author'         => array(
   497 				'author'                      => array(
   485 					'description' => __( 'The theme author.' ),
   498 					'description' => __( 'The theme author.' ),
   486 					'type'        => 'object',
   499 					'type'        => 'object',
   487 					'readonly'    => true,
   500 					'readonly'    => true,
   488 					'properties'  => array(
   501 					'properties'  => array(
   489 						'raw'      => array(
   502 						'raw'      => array(
   494 							'description' => __( 'HTML for the theme author, transformed for display.' ),
   507 							'description' => __( 'HTML for the theme author, transformed for display.' ),
   495 							'type'        => 'string',
   508 							'type'        => 'string',
   496 						),
   509 						),
   497 					),
   510 					),
   498 				),
   511 				),
   499 				'author_uri'     => array(
   512 				'author_uri'                  => array(
   500 					'description' => __( 'The website of the theme author.' ),
   513 					'description' => __( 'The website of the theme author.' ),
   501 					'type'        => 'object',
   514 					'type'        => 'object',
   502 					'readonly'    => true,
   515 					'readonly'    => true,
   503 					'properties'  => array(
   516 					'properties'  => array(
   504 						'raw'      => array(
   517 						'raw'      => array(
   511 							'type'        => 'string',
   524 							'type'        => 'string',
   512 							'format'      => 'uri',
   525 							'format'      => 'uri',
   513 						),
   526 						),
   514 					),
   527 					),
   515 				),
   528 				),
   516 				'description'    => array(
   529 				'description'                 => array(
   517 					'description' => __( 'A description of the theme.' ),
   530 					'description' => __( 'A description of the theme.' ),
   518 					'type'        => 'object',
   531 					'type'        => 'object',
   519 					'readonly'    => true,
   532 					'readonly'    => true,
   520 					'properties'  => array(
   533 					'properties'  => array(
   521 						'raw'      => array(
   534 						'raw'      => array(
   526 							'description' => __( 'The theme description, transformed for display.' ),
   539 							'description' => __( 'The theme description, transformed for display.' ),
   527 							'type'        => 'string',
   540 							'type'        => 'string',
   528 						),
   541 						),
   529 					),
   542 					),
   530 				),
   543 				),
   531 				'is_block_theme' => array(
   544 				'is_block_theme'              => array(
   532 					'description' => __( 'Whether the theme is a block-based theme.' ),
   545 					'description' => __( 'Whether the theme is a block-based theme.' ),
   533 					'type'        => 'boolean',
   546 					'type'        => 'boolean',
   534 					'readonly'    => true,
   547 					'readonly'    => true,
   535 				),
   548 				),
   536 				'name'           => array(
   549 				'name'                        => array(
   537 					'description' => __( 'The name of the theme.' ),
   550 					'description' => __( 'The name of the theme.' ),
   538 					'type'        => 'object',
   551 					'type'        => 'object',
   539 					'readonly'    => true,
   552 					'readonly'    => true,
   540 					'properties'  => array(
   553 					'properties'  => array(
   541 						'raw'      => array(
   554 						'raw'      => array(
   546 							'description' => __( 'The theme name, transformed for display.' ),
   559 							'description' => __( 'The theme name, transformed for display.' ),
   547 							'type'        => 'string',
   560 							'type'        => 'string',
   548 						),
   561 						),
   549 					),
   562 					),
   550 				),
   563 				),
   551 				'requires_php'   => array(
   564 				'requires_php'                => array(
   552 					'description' => __( 'The minimum PHP version required for the theme to work.' ),
   565 					'description' => __( 'The minimum PHP version required for the theme to work.' ),
   553 					'type'        => 'string',
   566 					'type'        => 'string',
   554 					'readonly'    => true,
   567 					'readonly'    => true,
   555 				),
   568 				),
   556 				'requires_wp'    => array(
   569 				'requires_wp'                 => array(
   557 					'description' => __( 'The minimum WordPress version required for the theme to work.' ),
   570 					'description' => __( 'The minimum WordPress version required for the theme to work.' ),
   558 					'type'        => 'string',
   571 					'type'        => 'string',
   559 					'readonly'    => true,
   572 					'readonly'    => true,
   560 				),
   573 				),
   561 				'screenshot'     => array(
   574 				'screenshot'                  => array(
   562 					'description' => __( 'The theme\'s screenshot URL.' ),
   575 					'description' => __( 'The theme\'s screenshot URL.' ),
   563 					'type'        => 'string',
   576 					'type'        => 'string',
   564 					'format'      => 'uri',
   577 					'format'      => 'uri',
   565 					'readonly'    => true,
   578 					'readonly'    => true,
   566 				),
   579 				),
   567 				'tags'           => array(
   580 				'tags'                        => array(
   568 					'description' => __( 'Tags indicating styles and features of the theme.' ),
   581 					'description' => __( 'Tags indicating styles and features of the theme.' ),
   569 					'type'        => 'object',
   582 					'type'        => 'object',
   570 					'readonly'    => true,
   583 					'readonly'    => true,
   571 					'properties'  => array(
   584 					'properties'  => array(
   572 						'raw'      => array(
   585 						'raw'      => array(
   580 							'description' => __( 'The theme tags, transformed for display.' ),
   593 							'description' => __( 'The theme tags, transformed for display.' ),
   581 							'type'        => 'string',
   594 							'type'        => 'string',
   582 						),
   595 						),
   583 					),
   596 					),
   584 				),
   597 				),
   585 				'textdomain'     => array(
   598 				'textdomain'                  => array(
   586 					'description' => __( 'The theme\'s text domain.' ),
   599 					'description' => __( 'The theme\'s text domain.' ),
   587 					'type'        => 'string',
   600 					'type'        => 'string',
   588 					'readonly'    => true,
   601 					'readonly'    => true,
   589 				),
   602 				),
   590 				'theme_supports' => array(
   603 				'theme_supports'              => array(
   591 					'description' => __( 'Features supported by this theme.' ),
   604 					'description' => __( 'Features supported by this theme.' ),
   592 					'type'        => 'object',
   605 					'type'        => 'object',
   593 					'readonly'    => true,
   606 					'readonly'    => true,
   594 					'properties'  => array(),
   607 					'properties'  => array(),
   595 				),
   608 				),
   596 				'theme_uri'      => array(
   609 				'theme_uri'                   => array(
   597 					'description' => __( 'The URI of the theme\'s webpage.' ),
   610 					'description' => __( 'The URI of the theme\'s webpage.' ),
   598 					'type'        => 'object',
   611 					'type'        => 'object',
   599 					'readonly'    => true,
   612 					'readonly'    => true,
   600 					'properties'  => array(
   613 					'properties'  => array(
   601 						'raw'      => array(
   614 						'raw'      => array(
   608 							'type'        => 'string',
   621 							'type'        => 'string',
   609 							'format'      => 'uri',
   622 							'format'      => 'uri',
   610 						),
   623 						),
   611 					),
   624 					),
   612 				),
   625 				),
   613 				'version'        => array(
   626 				'version'                     => array(
   614 					'description' => __( 'The theme\'s current version.' ),
   627 					'description' => __( 'The theme\'s current version.' ),
   615 					'type'        => 'string',
   628 					'type'        => 'string',
   616 					'readonly'    => true,
   629 					'readonly'    => true,
   617 				),
   630 				),
   618 				'status'         => array(
   631 				'status'                      => array(
   619 					'description' => __( 'A named status for the theme.' ),
   632 					'description' => __( 'A named status for the theme.' ),
   620 					'type'        => 'string',
   633 					'type'        => 'string',
   621 					'enum'        => array( 'inactive', 'active' ),
   634 					'enum'        => array( 'inactive', 'active' ),
       
   635 				),
       
   636 				'default_template_types'      => array(
       
   637 					'description' => __( 'A list of default template types.' ),
       
   638 					'type'        => 'array',
       
   639 					'readonly'    => true,
       
   640 					'items'       => array(
       
   641 						'type'       => 'object',
       
   642 						'properties' => array(
       
   643 							'slug'        => array(
       
   644 								'type' => 'string',
       
   645 							),
       
   646 							'title'       => array(
       
   647 								'type' => 'string',
       
   648 							),
       
   649 							'description' => array(
       
   650 								'type' => 'string',
       
   651 							),
       
   652 						),
       
   653 					),
       
   654 				),
       
   655 				'default_template_part_areas' => array(
       
   656 					'description' => __( 'A list of allowed area values for template parts.' ),
       
   657 					'type'        => 'array',
       
   658 					'readonly'    => true,
       
   659 					'items'       => array(
       
   660 						'type'       => 'object',
       
   661 						'properties' => array(
       
   662 							'area'        => array(
       
   663 								'type' => 'string',
       
   664 							),
       
   665 							'label'       => array(
       
   666 								'type' => 'string',
       
   667 							),
       
   668 							'description' => array(
       
   669 								'type' => 'string',
       
   670 							),
       
   671 							'icon'        => array(
       
   672 								'type' => 'string',
       
   673 							),
       
   674 							'area_tag'    => array(
       
   675 								'type' => 'string',
       
   676 							),
       
   677 						),
       
   678 					),
   622 				),
   679 				),
   623 			),
   680 			),
   624 		);
   681 		);
   625 
   682 
   626 		foreach ( get_registered_theme_features() as $feature => $config ) {
   683 		foreach ( get_registered_theme_features() as $feature => $config ) {