/wp-includes/customize/class-wp-customize-theme-control.php

https://github.com/livinglab/openlab · PHP · 271 lines · 197 code · 12 blank · 62 comment · 10 complexity · ea0209ec184b97ff8a5754d582f563be MD5 · raw file

  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] }}" 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 doesn&#8217;t 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 doesn&#8217;t 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 doesn&#8217;t 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 doesn&#8217;t 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 doesn&#8217;t 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 doesn&#8217;t 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. <div class="theme-id-container">
  234. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
  235. <div class="theme-actions">
  236. <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #>
  237. <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>
  238. <# } else { #>
  239. <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $preview_label ); ?>"><?php _e( 'Live Preview' ); ?></button>
  240. <# } #>
  241. </div>
  242. </div>
  243. <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
  244. <# } else { #>
  245. <div class="theme-id-container">
  246. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
  247. <div class="theme-actions">
  248. <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #>
  249. <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>
  250. <# } else { #>
  251. <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $install_label ); ?>" disabled><?php _e( 'Install &amp; Preview' ); ?></button>
  252. <# } #>
  253. </div>
  254. </div>
  255. <# } #>
  256. </div>
  257. <?php
  258. }
  259. }