wp/wp-admin/includes/theme.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    70 	$themes_dir = $wp_filesystem->wp_themes_dir();
    70 	$themes_dir = $wp_filesystem->wp_themes_dir();
    71 	if ( empty( $themes_dir ) ) {
    71 	if ( empty( $themes_dir ) ) {
    72 		return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
    72 		return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
    73 	}
    73 	}
    74 
    74 
       
    75 	/**
       
    76 	 * Fires immediately before a theme deletion attempt.
       
    77 	 *
       
    78 	 * @since 5.8.0
       
    79 	 *
       
    80 	 * @param string $stylesheet Stylesheet of the theme to delete.
       
    81 	 */
       
    82 	do_action( 'delete_theme', $stylesheet );
       
    83 
    75 	$themes_dir = trailingslashit( $themes_dir );
    84 	$themes_dir = trailingslashit( $themes_dir );
    76 	$theme_dir  = trailingslashit( $themes_dir . $stylesheet );
    85 	$theme_dir  = trailingslashit( $themes_dir . $stylesheet );
    77 	$deleted    = $wp_filesystem->delete( $theme_dir, true );
    86 	$deleted    = $wp_filesystem->delete( $theme_dir, true );
       
    87 
       
    88 	/**
       
    89 	 * Fires immediately after a theme deletion attempt.
       
    90 	 *
       
    91 	 * @since 5.8.0
       
    92 	 *
       
    93 	 * @param string $stylesheet Stylesheet of the theme to delete.
       
    94 	 * @param bool   $deleted    Whether the theme deletion was successful.
       
    95 	 */
       
    96 	do_action( 'deleted_theme', $stylesheet, $deleted );
    78 
    97 
    79 	if ( ! $deleted ) {
    98 	if ( ! $deleted ) {
    80 		return new WP_Error(
    99 		return new WP_Error(
    81 			'could_not_remove_theme',
   100 			'could_not_remove_theme',
    82 			/* translators: %s: Theme name. */
   101 			/* translators: %s: Theme name. */
   277  *              'Front Page Posting', 'Microformats', 'RTL Language Support',
   296  *              'Front Page Posting', 'Microformats', 'RTL Language Support',
   278  *              'Threaded Comments', and 'Translation Ready' features.
   297  *              'Threaded Comments', and 'Translation Ready' features.
   279  * @since 5.5.0 Added 'Block Editor Patterns', 'Block Editor Styles',
   298  * @since 5.5.0 Added 'Block Editor Patterns', 'Block Editor Styles',
   280  *              and 'Full Site Editing' features.
   299  *              and 'Full Site Editing' features.
   281  * @since 5.5.0 Added 'Wide Blocks' layout option.
   300  * @since 5.5.0 Added 'Wide Blocks' layout option.
       
   301  * @since 5.8.1 Added 'Template Editing' feature.
   282  *
   302  *
   283  * @param bool $api Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true.
   303  * @param bool $api Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true.
   284  * @return array Array of features keyed by category with translations keyed by slug.
   304  * @return array Array of features keyed by category with translations keyed by slug.
   285  */
   305  */
   286 function get_theme_feature_list( $api = true ) {
   306 function get_theme_feature_list( $api = true ) {
   313 			'footer-widgets'        => __( 'Footer Widgets' ),
   333 			'footer-widgets'        => __( 'Footer Widgets' ),
   314 			'full-site-editing'     => __( 'Full Site Editing' ),
   334 			'full-site-editing'     => __( 'Full Site Editing' ),
   315 			'full-width-template'   => __( 'Full Width Template' ),
   335 			'full-width-template'   => __( 'Full Width Template' ),
   316 			'post-formats'          => __( 'Post Formats' ),
   336 			'post-formats'          => __( 'Post Formats' ),
   317 			'sticky-post'           => __( 'Sticky Post' ),
   337 			'sticky-post'           => __( 'Sticky Post' ),
       
   338 			'template-editing'      => __( 'Template Editing' ),
   318 			'theme-options'         => __( 'Theme Options' ),
   339 			'theme-options'         => __( 'Theme Options' ),
   319 		),
   340 		),
   320 
   341 
   321 		__( 'Layout' )   => array(
   342 		__( 'Layout' )   => array(
   322 			'grid-layout'   => __( 'Grid Layout' ),
   343 			'grid-layout'   => __( 'Grid Layout' ),
   647 		}
   668 		}
   648 	}
   669 	}
   649 
   670 
   650 	$updates    = array();
   671 	$updates    = array();
   651 	$no_updates = array();
   672 	$no_updates = array();
   652 	if ( current_user_can( 'update_themes' ) ) {
   673 	if ( ! is_multisite() && current_user_can( 'update_themes' ) ) {
   653 		$updates_transient = get_site_transient( 'update_themes' );
   674 		$updates_transient = get_site_transient( 'update_themes' );
   654 		if ( isset( $updates_transient->response ) ) {
   675 		if ( isset( $updates_transient->response ) ) {
   655 			$updates = $updates_transient->response;
   676 			$updates = $updates_transient->response;
   656 		}
   677 		}
   657 		if ( isset( $updates_transient->no_update ) ) {
   678 		if ( isset( $updates_transient->no_update ) ) {
   714 				'requires'     => $theme->get( 'RequiresWP' ),
   735 				'requires'     => $theme->get( 'RequiresWP' ),
   715 				'requires_php' => $theme->get( 'RequiresPHP' ),
   736 				'requires_php' => $theme->get( 'RequiresPHP' ),
   716 			);
   737 			);
   717 		}
   738 		}
   718 
   739 
   719 		$type = 'theme';
   740 		$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $auto_update_filter_payload );
   720 		/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
       
   721 		$auto_update_forced = apply_filters( "auto_update_{$type}", null, $auto_update_filter_payload );
       
   722 
   741 
   723 		$prepared_themes[ $slug ] = array(
   742 		$prepared_themes[ $slug ] = array(
   724 			'id'             => $slug,
   743 			'id'             => $slug,
   725 			'name'           => $theme->display( 'Name' ),
   744 			'name'           => $theme->display( 'Name' ),
   726 			'screenshot'     => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
   745 			'screenshot'     => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
   746 				'forced'    => $auto_update_forced,
   765 				'forced'    => $auto_update_forced,
   747 			),
   766 			),
   748 			'actions'        => array(
   767 			'actions'        => array(
   749 				'activate'   => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
   768 				'activate'   => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
   750 				'customize'  => $customize_action,
   769 				'customize'  => $customize_action,
   751 				'delete'     => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
   770 				'delete'     => ( ! is_multisite() && current_user_can( 'delete_themes' ) ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
   752 				'autoupdate' => wp_is_auto_update_enabled_for_type( 'theme' ) && ! is_multisite() && current_user_can( 'update_themes' )
   771 				'autoupdate' => wp_is_auto_update_enabled_for_type( 'theme' ) && ! is_multisite() && current_user_can( 'update_themes' )
   753 					? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&stylesheet=' . $encoded_slug ), 'updates' )
   772 					? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&stylesheet=' . $encoded_slug ), 'updates' )
   754 					: null,
   773 					: null,
   755 			),
   774 			),
   756 		);
   775 		);
  1127 
  1146 
  1128 /**
  1147 /**
  1129  * Renders an admin notice in case some themes have been paused due to errors.
  1148  * Renders an admin notice in case some themes have been paused due to errors.
  1130  *
  1149  *
  1131  * @since 5.2.0
  1150  * @since 5.2.0
       
  1151  *
       
  1152  * @global string $pagenow
  1132  */
  1153  */
  1133 function paused_themes_notice() {
  1154 function paused_themes_notice() {
  1134 	if ( 'themes.php' === $GLOBALS['pagenow'] ) {
  1155 	if ( 'themes.php' === $GLOBALS['pagenow'] ) {
  1135 		return;
  1156 		return;
  1136 	}
  1157 	}