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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}">
  84. <p>
  85. <?php
  86. if ( is_multisite() ) {
  87. _e( 'New version available.' );
  88. } else {
  89. printf(
  90. /* translators: %s: "Update now" button. */
  91. __( 'New version available. %s' ),
  92. '<button class="button-link update-theme" type="button">' . __( 'Update now' ) . '</button>'
  93. );
  94. }
  95. ?>
  96. </p>
  97. </div>
  98. <# } #>
  99. <# if ( data.theme.active ) { #>
  100. <div class="theme-id-container">
  101. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">
  102. <span><?php _e( 'Previewing:' ); ?></span> {{ data.theme.name }}
  103. </h3>
  104. <div class="theme-actions">
  105. <button type="button" class="button button-primary customize-theme" aria-label="<?php echo esc_attr( $customize_label ); ?>"><?php _e( 'Customize' ); ?></button>
  106. </div>
  107. </div>
  108. <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
  109. <# } else if ( 'installed' === data.theme.type ) { #>
  110. <div class="theme-id-container">
  111. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
  112. <div class="theme-actions">
  113. <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>
  114. </div>
  115. </div>
  116. <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
  117. <# } else { #>
  118. <div class="theme-id-container">
  119. <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
  120. <div class="theme-actions">
  121. <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>
  122. </div>
  123. </div>
  124. <# } #>
  125. </div>
  126. <?php
  127. }
  128. }