/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. * Don't render the control content from PHP, as it's rendered via JS on load. 
  51. * 
  52. * @since 4.2.0 
  53. * @access public 
  54. */ 
  55. public function render_content() {} 
  56.  
  57. /** 
  58. * Render a JS template for theme display. 
  59. * 
  60. * @since 4.2.0 
  61. * @access public 
  62. */ 
  63. public function content_template() { 
  64. $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); 
  65. $active_url = esc_url( remove_query_arg( 'customize_theme', $current_url ) ); 
  66. $preview_url = esc_url( add_query_arg( 'customize_theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces. 
  67. $preview_url = str_replace( '__THEME__', '{{ data.theme.id }}', $preview_url ); 
  68. ?> 
  69. <# if ( data.theme.isActiveTheme ) { #> 
  70. <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"> 
  71. <# } else { #> 
  72. <div class="theme" tabindex="0" data-preview-url="<?php echo esc_attr( $preview_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name"> 
  73. <# } #> 
  74.  
  75. <# if ( 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. <# if ( data.theme.isActiveTheme ) { #> 
  84. <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Customize' ); ?></span> 
  85. <# } else { #> 
  86. <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Live Preview' ); ?></span> 
  87. <# } #> 
  88.  
  89. <div class="theme-author"><?php 
  90. /** translators: Theme author name */ 
  91. printf( _x( 'By %s', 'theme author' ), '{{ data.theme.author }}' ); 
  92. ?></div> 
  93.  
  94. <# if ( data.theme.isActiveTheme ) { #> 
  95. <h3 class="theme-name" id="{{ data.theme.id }}-name"> 
  96. <?php 
  97. /** translators: %s: theme name */ 
  98. printf( __( '<span>Active:</span> %s' ), '{{{ data.theme.name }}}' ); 
  99. ?> 
  100. </h3> 
  101. <# } else { #> 
  102. <h3 class="theme-name" id="{{ data.theme.id }}-name">{{{ data.theme.name }}}</h3> 
  103. <div class="theme-actions"> 
  104. <button type="button" class="button theme-details"><?php _e( 'Theme Details' ); ?></button> 
  105. </div> 
  106. <# } #> 
  107. </div> 
  108. <?php 
.