|
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 * @var string |
|
24 */ |
|
25 public $type = 'theme'; |
|
26 |
|
27 /** |
|
28 * Theme object. |
|
29 * |
|
30 * @since 4.2.0 |
|
31 * @var WP_Theme |
|
32 */ |
|
33 public $theme; |
|
34 |
|
35 /** |
|
36 * Refresh the parameters passed to the JavaScript via JSON. |
|
37 * |
|
38 * @since 4.2.0 |
|
39 * |
|
40 * @see WP_Customize_Control::to_json() |
|
41 */ |
|
42 public function to_json() { |
|
43 parent::to_json(); |
|
44 $this->json['theme'] = $this->theme; |
|
45 } |
|
46 |
|
47 /** |
|
48 * Don't render the control content from PHP, as it's rendered via JS on load. |
|
49 * |
|
50 * @since 4.2.0 |
|
51 */ |
|
52 public function render_content() {} |
|
53 |
|
54 /** |
|
55 * Render a JS template for theme display. |
|
56 * |
|
57 * @since 4.2.0 |
|
58 */ |
|
59 public function content_template() { |
|
60 /* translators: %s: theme name */ |
|
61 $details_label = sprintf( __( 'Details for theme: %s' ), '{{ data.theme.name }}' ); |
|
62 /* translators: %s: theme name */ |
|
63 $customize_label = sprintf( __( 'Customize theme: %s' ), '{{ data.theme.name }}' ); |
|
64 /* translators: %s: theme name */ |
|
65 $preview_label = sprintf( __( 'Live preview theme: %s' ), '{{ data.theme.name }}' ); |
|
66 /* translators: %s: theme name */ |
|
67 $install_label = sprintf( __( 'Install and preview theme: %s' ), '{{ data.theme.name }}' ); |
|
68 ?> |
|
69 <# if ( data.theme.active ) { #> |
|
70 <div class="theme active" tabindex="0" aria-describedby="{{ data.section }}-{{ data.theme.id }}-action"> |
|
71 <# } else { #> |
|
72 <div class="theme" tabindex="0" aria-describedby="{{ data.section }}-{{ data.theme.id }}-action"> |
|
73 <# } #> |
|
74 |
|
75 <# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #> |
|
76 <div class="theme-screenshot"> |
|
77 <img data-src="{{ data.theme.screenshot[0] }}" alt="" /> |
|
78 </div> |
|
79 <# } else { #> |
|
80 <div class="theme-screenshot blank"></div> |
|
81 <# } #> |
|
82 |
|
83 <span class="more-details theme-details" id="{{ data.section }}-{{ data.theme.id }}-action" aria-label="<?php echo esc_attr( $details_label ); ?>"><?php _e( 'Theme Details' ); ?></span> |
|
84 |
|
85 <div class="theme-author"><?php |
|
86 /* translators: Theme author name */ |
|
87 printf( _x( 'By %s', 'theme author' ), '{{ data.theme.author }}' ); |
|
88 ?></div> |
|
89 |
|
90 <# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #> |
|
91 <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}"> |
|
92 <p> |
|
93 <?php |
|
94 /* translators: %s: "Update now" button */ |
|
95 printf( __( 'New version available. %s' ), '<button class="button-link update-theme" type="button">' . __( 'Update now' ) . '</button>' ); |
|
96 ?> |
|
97 </p> |
|
98 </div> |
|
99 <# } #> |
|
100 |
|
101 <# if ( data.theme.active ) { #> |
|
102 <div class="theme-id-container"> |
|
103 <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name"> |
|
104 <?php |
|
105 /* translators: %s: theme name */ |
|
106 printf( __( '<span>Previewing:</span> %s' ), '{{ data.theme.name }}' ); |
|
107 ?> |
|
108 </h3> |
|
109 <div class="theme-actions"> |
|
110 <button type="button" class="button button-primary customize-theme" aria-label="<?php echo esc_attr( $customize_label ); ?>"><?php _e( 'Customize' ); ?></button> |
|
111 </div> |
|
112 </div> |
|
113 <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div> |
|
114 <# } else if ( 'installed' === data.theme.type ) { #> |
|
115 <div class="theme-id-container"> |
|
116 <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> |
|
117 <div class="theme-actions"> |
|
118 <button type="button" class="button button-primary preview-theme" aria-label="<?php echo esc_attr( $preview_label ); ?>" data-slug="{{ data.theme.id }}"><?php _e( 'Live Preview' ); ?></button> |
|
119 </div> |
|
120 </div> |
|
121 <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div> |
|
122 <# } else { #> |
|
123 <div class="theme-id-container"> |
|
124 <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> |
|
125 <div class="theme-actions"> |
|
126 <button type="button" class="button button-primary theme-install preview" aria-label="<?php echo esc_attr( $install_label ); ?>" data-slug="{{ data.theme.id }}" data-name="{{ data.theme.name }}"><?php _e( 'Install & Preview' ); ?></button> |
|
127 </div> |
|
128 </div> |
|
129 <# } #> |
|
130 </div> |
|
131 <?php |
|
132 } |
|
133 } |