]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/customize/class-wp-customize-theme-control.php
WordPress 4.7.1-scripts
[autoinstalls/wordpress.git] / wp-includes / customize / class-wp-customize-theme-control.php
1 <?php
2 /**
3  * Customize API: WP_Customize_Theme_Control class
4  *
5  * @package WordPress
6  * @subpackage Customize
7  * @since 4.4.0
8  */
9
10 /**
11  * Customize Theme Control class.
12  *
13  * @since 4.2.0
14  *
15  * @see WP_Customize_Control
16  */
17 class WP_Customize_Theme_Control extends WP_Customize_Control {
18
19         /**
20          * Customize control type.
21          *
22          * @since 4.2.0
23          * @access public
24          * @var string
25          */
26         public $type = 'theme';
27
28         /**
29          * Theme object.
30          *
31          * @since 4.2.0
32          * @access public
33          * @var WP_Theme
34          */
35         public $theme;
36
37         /**
38          * Refresh the parameters passed to the JavaScript via JSON.
39          *
40          * @since 4.2.0
41          * @access public
42          *
43          * @see WP_Customize_Control::to_json()
44          */
45         public function to_json() {
46                 parent::to_json();
47                 $this->json['theme'] = $this->theme;
48         }
49
50         /**
51          * Don't render the control content from PHP, as it's rendered via JS on load.
52          *
53          * @since 4.2.0
54          * @access public
55          */
56         public function render_content() {}
57
58         /**
59          * Render a JS template for theme display.
60          *
61          * @since 4.2.0
62          * @access public
63          */
64         public function content_template() {
65                 $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
66                 $active_url  = esc_url( remove_query_arg( 'customize_theme', $current_url ) );
67                 $preview_url = esc_url( add_query_arg( 'customize_theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces.
68                 $preview_url = str_replace( '__THEME__', '{{ data.theme.id }}', $preview_url );
69                 ?>
70                 <# if ( data.theme.isActiveTheme ) { #>
71                         <div class="theme active" tabindex="0" data-preview-url="<?php echo esc_attr( $active_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
72                 <# } else { #>
73                         <div class="theme" tabindex="0" data-preview-url="<?php echo esc_attr( $preview_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
74                 <# } #>
75
76                         <# if ( data.theme.screenshot[0] ) { #>
77                                 <div class="theme-screenshot">
78                                         <img data-src="{{ data.theme.screenshot[0] }}" alt="" />
79                                 </div>
80                         <# } else { #>
81                                 <div class="theme-screenshot blank"></div>
82                         <# } #>
83
84                         <# if ( data.theme.isActiveTheme ) { #>
85                                 <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Customize' ); ?></span>
86                         <# } else { #>
87                                 <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Live Preview' ); ?></span>
88                         <# } #>
89
90                         <div class="theme-author"><?php
91                                 /* translators: Theme author name */
92                                 printf( _x( 'By %s', 'theme author' ), '{{ data.theme.author }}' );
93                         ?></div>
94
95                         <# if ( data.theme.isActiveTheme ) { #>
96                                 <h3 class="theme-name" id="{{ data.theme.id }}-name">
97                                         <?php
98                                         /* translators: %s: theme name */
99                                         printf( __( '<span>Active:</span> %s' ), '{{{ data.theme.name }}}' );
100                                         ?>
101                                 </h3>
102                         <# } else { #>
103                                 <h3 class="theme-name" id="{{ data.theme.id }}-name">{{{ data.theme.name }}}</h3>
104                                 <div class="theme-actions">
105                                         <button type="button" class="button theme-details"><?php _e( 'Theme Details' ); ?></button>
106                                 </div>
107                         <# } #>
108                 </div>
109         <?php
110         }
111 }