class-wp-customize-theme-control.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. * Customize Theme Control class.
  11. *
  12. * @since 4.2.0
  13. *
  14. * @see WP_Customize_Control
  15. */
  16. class WP_Customize_Theme_Control extends WP_Customize_Control {
  17. /**
  18. * Customize control type.
  19. *
  20. * @since 4.2.0
  21. * @var string
  22. */
  23. public $type = 'theme';
  24. /**
  25. * Theme object.
  26. *
  27. * @since 4.2.0
  28. * @var WP_Theme
  29. */
  30. public $theme;
  31. /**
  32. * Refresh the parameters passed to the JavaScript via JSON.
  33. *
  34. * @since 4.2.0
  35. *
  36. * @see WP_Customize_Control::to_json()
  37. */
  38. public function to_json() {
  39. parent::to_json();
  40. $this->json['theme'] = $this->theme;
  41. }
  42. /**
  43. * Don't render the control content from PHP, as it's rendered via JS on load.
  44. *
  45. * @since 4.2.0
  46. */
  47. public function render_content() {}
  48. /**
  49. * Render a JS template for theme display.
  50. *
  51. * @since 4.2.0
  52. */
  53. public function content_template() {
  54. /* translators: %s: Theme name. */
  55. $details_label = sprintf( __( 'Details for theme: %s' ), '{{ data.theme.name }}' );
  56. /* translators: %s: Theme name. */
  57. $customize_label = sprintf( __( 'Customize theme: %s' ), '{{ data.theme.name }}' );
  58. /* translators: %s: Theme name. */
  59. $preview_label = sprintf( __( 'Live preview theme: %s' ), '{{ data.theme.name }}' );
  60. /* translators: %s: Theme name. */
  61. $install_label = sprintf( __( 'Install and preview theme: %s' ), '{{ data.theme.name }}' );
  62. ?>
  63. <# if ( data.theme.active ) { #>
  64. <div class="theme active" tabindex="0" aria-describedby="{{ data.section }}-{{ data.theme.id }}-action">
  65. <# } else { #>
  66. <div class="theme" tabindex="0" aria-describedby="{{ data.section }}-{{ data.theme.id }}-action">
  67. <# } #>
  68. <# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #>
  69. <div class="theme-screenshot">
  70. <img data-src="{{ data.theme.screenshot[0] }}?ver={{ data.theme.version }}" alt="" />
  71. </div>
  72. <# } else { #>
  73. <div class="theme-screenshot blank"></div>
  74. <# } #>
  75. <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>
  76. <div class="theme-author">
  77. <?php
  78. /* translators: Theme author name. */
  79. printf( _x( 'By %s', 'theme author' ), '{{ data.theme.author }}' );
  80. ?>
  81. </div>
  82. <# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #>
  83. <# if ( data.theme.updateResponse.compatibleWP && data.theme.updateResponse.compatiblePHP ) { #>
  84. <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}">
  85. <p>
  86. <?php
  87. if ( is_multisite() ) {
  88. _e( 'New version available.' );
  89. } else {
  90. printf(
  91. /* translators: %s: "Update now" button. */
  92. __( 'New version available. %s' ),
  93. '<button class="button-link update-theme" type="button">' . __( 'Update now' ) . '</button>'
  94. );
  95. }
  96. ?>
  97. </p>
  98. </div>
  99. <# } else { #>
  100. <div class="update-message notice inline notice-error notice-alt" data-slug="{{ data.theme.id }}">
  101. <p>
  102. <# if ( ! data.theme.updateResponse.compatibleWP && ! data.theme.updateResponse.compatiblePHP ) { #>
  103. <?php
  104. printf(
  105. /* translators: %s: Theme name. */
  106. __( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ),
  107. '{{{ data.theme.name }}}'
  108. );
  109. if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
  110. printf(
  111. /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
  112. ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
  113. self_admin_url( 'update-core.php' ),
  114. esc_url( wp_get_update_php_url() )
  115. );
  116. wp_update_php_annotation( '</p><p><em>', '</em>' );
  117. } elseif ( current_user_can( 'update_core' ) ) {
  118. printf(
  119. /* translators: %s: URL to WordPress Updates screen. */
  120. ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
  121. self_admin_url( 'update-core.php' )
  122. );
  123. } elseif ( current_user_can( 'update_php' ) ) {
  124. printf(
  125. /* translators: %s: URL to Update PHP page. */
  126. ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
  127. esc_url( wp_get_update_php_url() )
  128. );
  129. wp_update_php_annotation( '</p><p><em>', '</em>' );
  130. }
  131. ?>
  132. <# } else if ( ! data.theme.updateResponse.compatibleWP ) { #>
  133. <?php
  134. printf(
  135. /* translators: %s: Theme name. */
  136. __( 'There is a new version of %s available, but it does not work with your version of WordPress.' ),
  137. '{{{ data.theme.name }}}'
  138. );
  139. if ( current_user_can( 'update_core' ) ) {
  140. printf(
  141. /* translators: %s: URL to WordPress Updates screen. */
  142. ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
  143. self_admin_url( 'update-core.php' )
  144. );
  145. }
  146. ?>
  147. <# } else if ( ! data.theme.updateResponse.compatiblePHP ) { #>
  148. <?php
  149. printf(
  150. /* translators: %s: Theme name. */
  151. __( 'There is a new version of %s available, but it does not work with your version of PHP.' ),
  152. '{{{ data.theme.name }}}'
  153. );
  154. if ( current_user_can( 'update_php' ) ) {
  155. printf(
  156. /* translators: %s: URL to Update PHP page. */
  157. ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
  158. esc_url( wp_get_update_php_url() )
  159. );
  160. wp_update_php_annotation( '</p><p><em>', '</em>' );
  161. }
  162. ?>
  163. <# } #>
  164. </p>
  165. </div>
  166. <# } #>
  167. <# } #>
  168. <# if ( ! data.theme.compatibleWP || ! data.theme.compatiblePHP ) { #>
  169. <div class="notice notice-error notice-alt"><p>
  170. <# if ( ! data.theme.compatibleWP && ! data.theme.compatiblePHP ) { #>
  171. <?php
  172. _e( 'This theme does not work with your versions of WordPress and PHP.' );
  173. if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
  174. printf(
  175. /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
  176. ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
  177. self_admin_url( 'update-core.php' ),
  178. esc_url( wp_get_update_php_url() )
  179. );
  180. wp_update_php_annotation( '</p><p><em>', '</em>' );
  181. } elseif ( current_user_can( 'update_core' ) ) {
  182. printf(
  183. /* translators: %s: URL to WordPress Updates screen. */
  184. ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
  185. self_admin_url( 'update-core.php' )
  186. );
  187. } elseif ( current_user_can( 'update_php' ) ) {
  188. printf(
  189. /* translators: %s: URL to Update PHP page. */
  190. ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
  191. esc_url( wp_get_update_php_url() )
  192. );
  193. wp_update_php_annotation( '</p><p><em>', '</em>' );
  194. }
  195. ?>
  196. <# } else if ( ! data.theme.compatibleWP ) { #>
  197. <?php
  198. _e( 'This theme does not work with your version of WordPress.' );
  199. if ( current_user_can( 'update_core' ) ) {
  200. printf(
  201. /* translators: %s: URL to WordPress Updates screen. */
  202. ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
  203. self_admin_url( 'update-core.php' )
  204. );
  205. }
  206. ?>
  207. <# } else if ( ! data.theme.compatiblePHP ) { #>
  208. <?php
  209. _e( 'This theme does not work with your version of PHP.' );
  210. if ( current_user_can( 'update_php' ) ) {
  211. printf(
  212. /* translators: %s: URL to Update PHP page. */
  213. ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
  214. esc_url( wp_get_update_php_url() )
  215. );
  216. wp_update_php_annotation( '</p><p><em>', '</em>' );
  217. }
  218. ?>
  219. <# } #>
  220. </p></div>
  221. <# } #>
  222. <# if ( data.theme.active ) { #>
  223. <div class="theme-id-container">
  224. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">
  225. <span><?php _ex( 'Previewing:', 'theme' ); ?></span> {{ data.theme.name }}
  226. </h3>
  227. <div class="theme-actions">
  228. <button type="button" class="button button-primary customize-theme" aria-label="<?php echo esc_attr( $customize_label ); ?>"><?php _e( 'Customize' ); ?></button>
  229. </div>
  230. </div>
  231. <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
  232. <# } else if ( 'installed' === data.theme.type ) { #>
  233. <# if ( data.theme.blockTheme ) { #>
  234. <div class="theme-id-container">
  235. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
  236. <div class="theme-actions">
  237. <# if ( data.theme.actions.activate ) { #>
  238. <?php
  239. /* translators: %s: Theme name. */
  240. $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
  241. ?>
  242. <a href="{{{ data.theme.actions.activate }}}" class="button button-primary activate" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
  243. <# } #>
  244. </div>
  245. </div>
  246. <div class="notice notice-error notice-alt"><p>
  247. <?php
  248. _e( 'This theme doesn\'t support Customizer.' );
  249. ?>
  250. <# if ( data.theme.actions.activate ) { #>
  251. <?php
  252. echo ' ';
  253. printf(
  254. /* translators: %s: URL to the themes page (also it activates the theme). */
  255. __( 'However, you can still <a href="%s">activate this theme</a>, and use the Site Editor to customize it.' ),
  256. '{{{ data.theme.actions.activate }}}'
  257. );
  258. ?>
  259. <# } #>
  260. </p></div>
  261. <# } else { #>
  262. <div class="theme-id-container">
  263. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
  264. <div class="theme-actions">
  265. <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #>
  266. <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>
  267. <# } else { #>
  268. <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $preview_label ); ?>"><?php _e( 'Live Preview' ); ?></button>
  269. <# } #>
  270. </div>
  271. </div>
  272. <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
  273. <# } #>
  274. <# } else { #>
  275. <div class="theme-id-container">
  276. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
  277. <div class="theme-actions">
  278. <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #>
  279. <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 &amp; Preview' ); ?></button>
  280. <# } else { #>
  281. <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $install_label ); ?>" disabled><?php _e( 'Install &amp; Preview' ); ?></button>
  282. <# } #>
  283. </div>
  284. </div>
  285. <# } #>
  286. </div>
  287. <?php
  288. }
  289. }