Changeset 39140 for trunk/src/wp-includes/class-wp-customize-manager.php
- Timestamp:
- 11/04/2016 03:53:01 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-manager.php
r39133 r39140 296 296 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php' ); 297 297 298 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-panel.php' );299 298 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-themes-section.php' ); 300 299 require_once( ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php' ); … … 352 351 add_action( 'wp_ajax_customize_save', array( $this, 'save' ) ); 353 352 add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) ); 354 add_action( 'wp_ajax_customize-load-themes', array( $this, 'load_themes_ajax' ) );355 353 356 354 add_action( 'customize_register', array( $this, 'register_controls' ) ); … … 369 367 // Export the settings to JS via the _wpCustomizeSettings variable. 370 368 add_action( 'customize_controls_print_footer_scripts', array( $this, 'customize_pane_settings' ), 1000 ); 371 372 // Add theme update notices.373 if ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) ) {374 require_once( ABSPATH . '/wp-admin/includes/update.php' );375 add_action( 'customize_controls_print_footer_scripts', 'wp_print_admin_notice_templates' );376 }377 369 } 378 370 … … 2759 2751 $control->enqueue(); 2760 2752 } 2761 if ( ! is_multisite() && ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) || current_user_can( 'delete_themes' ) ) ) {2762 wp_enqueue_script( 'updates' );2763 }2764 2753 } 2765 2754 … … 2976 2965 'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ), 2977 2966 'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ), 2978 'switch-themes' => wp_create_nonce( 'switch-themes' ),2979 2967 ); 2980 2968 … … 3050 3038 'documentTitleTmpl' => $this->get_document_title_template(), 3051 3039 'previewableDevices' => $this->get_previewable_devices(), 3052 'l10n' => array(3053 'confirmDeleteTheme' => __( 'Are you sure you want to delete this theme?' ),3054 /* translators: %d is the number of theme search results, which cannot consider singular vs. plural forms */3055 'themeSearchResults' => __( '%d themes found' ),3056 /* translators: %d is the number of themes being displayed, which cannot consider singular vs. plural forms */3057 'announceThemeCount' => __( 'Displaying %d themes' ),3058 'announceThemeDetails' => __( 'Showing details for theme: %s' ),3059 ),3060 3040 ); 3061 3041 … … 3161 3141 /* Panel, Section, and Control Types */ 3162 3142 $this->register_panel_type( 'WP_Customize_Panel' ); 3163 $this->register_panel_type( 'WP_Customize_Themes_Panel' );3164 3143 $this->register_section_type( 'WP_Customize_Section' ); 3165 3144 $this->register_section_type( 'WP_Customize_Sidebar_Section' ); 3166 $this->register_section_type( 'WP_Customize_Themes_Section' );3167 3145 $this->register_control_type( 'WP_Customize_Color_Control' ); 3168 3146 $this->register_control_type( 'WP_Customize_Media_Control' ); … … 3175 3153 $this->register_control_type( 'WP_Customize_Theme_Control' ); 3176 3154 3177 /* Themes (controls are loaded via ajax) */ 3178 3179 $this->add_panel( new WP_Customize_Themes_Panel( $this, 'themes', array( 3180 'title' => $this->theme()->display( 'Name' ), 3181 'description' => __( 'Once themes are installed, you can live-preview them on your site, customize them, and publish your new design. Browse available themes via the filters in this menu.' ), 3182 'capability' => 'switch_themes', 3183 'priority' => 0, 3155 /* Themes */ 3156 3157 $this->add_section( new WP_Customize_Themes_Section( $this, 'themes', array( 3158 'title' => $this->theme()->display( 'Name' ), 3159 'capability' => 'switch_themes', 3160 'priority' => 0, 3184 3161 ) ) ); 3185 3186 $this->add_section( new WP_Customize_Themes_Section( $this, 'installed_themes', array(3187 'title' => __( 'Installed' ),3188 'text_before' => __( 'Your local site' ),3189 'action' => 'installed',3190 'capability' => 'switch_themes',3191 'panel' => 'themes',3192 'priority' => 0,3193 ) ) );3194 3195 if ( ! is_multisite() ) {3196 $this->add_section( new WP_Customize_Themes_Section( $this, 'search_themes', array(3197 'title' => __( 'Search themes…' ),3198 'text_before' => __( 'Browse all WordPress.org themes' ),3199 'action' => 'search',3200 'capability' => 'install_themes',3201 'panel' => 'themes',3202 'priority' => 5,3203 ) ) );3204 3205 $this->add_section( new WP_Customize_Themes_Section( $this, 'featured_themes', array(3206 'title' => __( 'Featured' ),3207 'action' => 'featured',3208 'capability' => 'install_themes',3209 'panel' => 'themes',3210 'priority' => 10,3211 ) ) );3212 3213 $this->add_section( new WP_Customize_Themes_Section( $this, 'popular_themes', array(3214 'title' => __( 'Popular' ),3215 'action' => 'popular',3216 'capability' => 'install_themes',3217 'panel' => 'themes',3218 'priority' => 15,3219 ) ) );3220 3221 $this->add_section( new WP_Customize_Themes_Section( $this, 'latest_themes', array(3222 'title' => __( 'Latest' ),3223 'action' => 'latest',3224 'capability' => 'install_themes',3225 'panel' => 'themes',3226 'priority' => 20,3227 ) ) );3228 3229 $this->add_section( new WP_Customize_Themes_Section( $this, 'feature_filter_themes', array(3230 'title' => __( 'Feature Filter' ),3231 'action' => 'feature_filter',3232 'capability' => 'install_themes',3233 'panel' => 'themes',3234 'priority' => 25,3235 ) ) );3236 3237 $this->add_section( new WP_Customize_Themes_Section( $this, 'favorites_themes', array(3238 'title' => __( 'Favorites' ),3239 'action' => 'favorites',3240 'capability' => 'install_themes',3241 'panel' => 'themes',3242 'priority' => 30,3243 ) ) );3244 }3245 3162 3246 3163 // Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience). … … 3248 3165 'capability' => 'switch_themes', 3249 3166 ) ) ); 3167 3168 require_once( ABSPATH . 'wp-admin/includes/theme.php' ); 3169 3170 // Theme Controls. 3171 3172 // Add a control for the active/original theme. 3173 if ( ! $this->is_theme_active() ) { 3174 $themes = wp_prepare_themes_for_js( array( wp_get_theme( $this->original_stylesheet ) ) ); 3175 $active_theme = current( $themes ); 3176 $active_theme['isActiveTheme'] = true; 3177 $this->add_control( new WP_Customize_Theme_Control( $this, $active_theme['id'], array( 3178 'theme' => $active_theme, 3179 'section' => 'themes', 3180 'settings' => 'active_theme', 3181 ) ) ); 3182 } 3183 3184 $themes = wp_prepare_themes_for_js(); 3185 foreach ( $themes as $theme ) { 3186 if ( $theme['active'] || $theme['id'] === $this->original_stylesheet ) { 3187 continue; 3188 } 3189 3190 $theme_id = 'theme_' . $theme['id']; 3191 $theme['isActiveTheme'] = false; 3192 $this->add_control( new WP_Customize_Theme_Control( $this, $theme_id, array( 3193 'theme' => $theme, 3194 'section' => 'themes', 3195 'settings' => 'active_theme', 3196 ) ) ); 3197 } 3250 3198 3251 3199 /* Site Identity */ … … 3702 3650 3703 3651 /** 3704 * Load themes into the theme browsing/installation UI.3705 *3706 * @since 4.7.03707 * @access public3708 */3709 public function load_themes_ajax() {3710 check_ajax_referer( 'switch-themes', 'switch-themes-nonce' );3711 3712 if ( ! current_user_can( 'switch_themes' ) ) {3713 wp_die( -1 );3714 }3715 3716 if ( empty( $_POST['theme_action'] ) ) {3717 wp_send_json_error( 'missing_theme_action' );3718 }3719 3720 if ( 'search' === $_POST['theme_action'] && ! array_key_exists( 'search', $_POST ) ) {3721 wp_send_json_error( 'empty_search' );3722 } elseif ( 'favorites' === $_POST['theme_action'] && ! array_key_exists( 'user', $_POST ) ) {3723 wp_send_json_error( 'empty_user' );3724 } elseif ( 'feature_filter' === $_POST['theme_action'] && ! array_key_exists( 'tags', $_POST ) ) {3725 wp_send_json_error( 'no_features' );3726 }3727 3728 require_once( ABSPATH . 'wp-admin/includes/theme.php' );3729 if ( 'installed' === $_POST['theme_action'] ) {3730 $themes = array( 'themes' => wp_prepare_themes_for_js() );3731 foreach ( $themes['themes'] as &$theme ) {3732 $theme['type'] = 'installed';3733 // Set active based on customized theme.3734 if ( $_POST['customized_theme'] === $theme['id'] ) {3735 $theme['active'] = true;3736 } else {3737 $theme['active'] = false;3738 }3739 }3740 } else {3741 if ( ! current_user_can( 'install_themes' ) ) {3742 wp_die( -1 );3743 }3744 3745 // Arguments for all queries.3746 $args = array(3747 'per_page' => 100,3748 'page' => absint( $_POST['page'] ),3749 'fields' => array(3750 'slug' => true,3751 'screenshot' => true,3752 'description' => true,3753 'requires' => true,3754 'rating' => true,3755 'downloaded' => true,3756 'downloadLink' => true,3757 'last_updated' => true,3758 'homepage' => true,3759 'num_ratings' => true,3760 'tags' => true,3761 ),3762 );3763 3764 // Specialized handling for each query.3765 switch ( $_POST['theme_action'] ) {3766 case 'search':3767 $args['search'] = wp_unslash( $_POST['search'] );3768 break;3769 case 'favorites':3770 $args['user'] = wp_unslash( $_POST['user'] );3771 case 'featured':3772 case 'popular':3773 $args['browse'] = wp_unslash( $_POST['theme_action'] );3774 break;3775 case 'latest':3776 $args['browse'] = 'new';3777 break;3778 case 'feature_filter':3779 $args['tag'] = wp_unslash( $_POST['tags'] );3780 break;3781 }3782 3783 // Load themes from the .org API.3784 $themes = themes_api( 'query_themes', $args );3785 if ( is_wp_error( $themes ) ) {3786 wp_send_json_error();3787 }3788 3789 // This list matches the allowed tags in wp-admin/includes/theme-install.php.3790 $themes_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),3791 'abbr' => array('title' => array()), 'acronym' => array('title' => array()),3792 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),3793 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),3794 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),3795 'img' => array('src' => array(), 'class' => array(), 'alt' => array())3796 );3797 3798 // Prepare a list of installed themes to check against before the loop.3799 $installed_themes = array();3800 $wp_themes = wp_get_themes();3801 foreach ( $wp_themes as $theme ) {3802 $installed_themes[] = $theme->get_stylesheet();3803 }3804 $update_php = network_admin_url( 'update.php?action=install-theme' );3805 foreach ( $themes->themes as &$theme ) {3806 $theme->install_url = add_query_arg( array(3807 'theme' => $theme->slug,3808 '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ),3809 ), $update_php );3810 3811 $theme->name = wp_kses( $theme->name, $themes_allowedtags );3812 $theme->author = wp_kses( $theme->author, $themes_allowedtags );3813 $theme->version = wp_kses( $theme->version, $themes_allowedtags );3814 $theme->description = wp_kses( $theme->description, $themes_allowedtags );3815 $theme->tags = implode( ', ', $theme->tags );3816 $theme->stars = wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings, 'echo' => false ) );3817 $theme->num_ratings = number_format_i18n( $theme->num_ratings );3818 $theme->preview_url = set_url_scheme( $theme->preview_url );3819 3820 // Handle themes that are already installed as installed themes.3821 if ( in_array( $theme->slug, $installed_themes, true ) ) {3822 $theme->type = 'installed';3823 } else {3824 $theme->type = $_POST['theme_action'];3825 }3826 3827 // Set active based on customized theme.3828 if ( $_POST['customized_theme'] === $theme->slug ) {3829 $theme->active = true;3830 } else {3831 $theme->active = false;3832 }3833 3834 // Map available theme properties to installed theme properties.3835 $theme->id = $theme->slug;3836 $theme->screenshot = array( $theme->screenshot_url );3837 $theme->authorAndUri = $theme->author;3838 unset( $theme->slug );3839 unset( $theme->screenshot_url );3840 unset( $theme->author );3841 } // End foreach().3842 } // End if().3843 wp_send_json_success( $themes );3844 }3845 3846 3847 /**3848 3652 * Callback for validating the header_textcolor value. 3849 3653 *
Note: See TracChangeset
for help on using the changeset viewer.