PageRenderTime 627ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/df_home/static/test/portalbkd/wp-includes/class-wp-customize-panel.php

https://gitlab.com/darmawan.fatria/df-skp-2014
PHP | 333 lines | 101 code | 31 blank | 201 comment | 9 complexity | b4aca5bf76a7787e3b29bd5dfb906cd9 MD5 | raw file
  1. <?php
  2. /**
  3. * WordPress Customize Panel classes
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 4.0.0
  8. */
  9. /**
  10. * Customize Panel class.
  11. *
  12. * A UI container for sections, managed by the WP_Customize_Manager.
  13. *
  14. * @since 4.0.0
  15. *
  16. * @see WP_Customize_Manager
  17. */
  18. class WP_Customize_Panel {
  19. /**
  20. * Incremented with each new class instantiation, then stored in $instance_number.
  21. *
  22. * Used when sorting two instances whose priorities are equal.
  23. *
  24. * @since 4.1.0
  25. * @access protected
  26. * @var int
  27. */
  28. protected static $instance_count = 0;
  29. /**
  30. * Order in which this instance was created in relation to other instances.
  31. *
  32. * @since 4.1.0
  33. * @access public
  34. * @var int
  35. */
  36. public $instance_number;
  37. /**
  38. * WP_Customize_Manager instance.
  39. *
  40. * @since 4.0.0
  41. * @access public
  42. * @var WP_Customize_Manager
  43. */
  44. public $manager;
  45. /**
  46. * Unique identifier.
  47. *
  48. * @since 4.0.0
  49. * @access public
  50. * @var string
  51. */
  52. public $id;
  53. /**
  54. * Priority of the panel, defining the display order of panels and sections.
  55. *
  56. * @since 4.0.0
  57. * @access public
  58. * @var integer
  59. */
  60. public $priority = 160;
  61. /**
  62. * Capability required for the panel.
  63. *
  64. * @since 4.0.0
  65. * @access public
  66. * @var string
  67. */
  68. public $capability = 'edit_theme_options';
  69. /**
  70. * Theme feature support for the panel.
  71. *
  72. * @since 4.0.0
  73. * @access public
  74. * @var string|array
  75. */
  76. public $theme_supports = '';
  77. /**
  78. * Title of the panel to show in UI.
  79. *
  80. * @since 4.0.0
  81. * @access public
  82. * @var string
  83. */
  84. public $title = '';
  85. /**
  86. * Description to show in the UI.
  87. *
  88. * @since 4.0.0
  89. * @access public
  90. * @var string
  91. */
  92. public $description = '';
  93. /**
  94. * Customizer sections for this panel.
  95. *
  96. * @since 4.0.0
  97. * @access public
  98. * @var array
  99. */
  100. public $sections;
  101. /**
  102. * Type of this panel.
  103. *
  104. * @since 4.1.0
  105. * @access public
  106. * @var string
  107. */
  108. public $type = 'default';
  109. /**
  110. * Active callback.
  111. *
  112. * @since 4.1.0
  113. * @access public
  114. *
  115. * @see WP_Customize_Section::active()
  116. *
  117. * @var callable Callback is called with one argument, the instance of
  118. * {@see WP_Customize_Section}, and returns bool to indicate
  119. * whether the section is active (such as it relates to the URL
  120. * currently being previewed).
  121. */
  122. public $active_callback = '';
  123. /**
  124. * Constructor.
  125. *
  126. * Any supplied $args override class property defaults.
  127. *
  128. * @since 4.0.0
  129. *
  130. * @param WP_Customize_Manager $manager Customizer bootstrap instance.
  131. * @param string $id An specific ID for the panel.
  132. * @param array $args Panel arguments.
  133. */
  134. public function __construct( $manager, $id, $args = array() ) {
  135. $keys = array_keys( get_object_vars( $this ) );
  136. foreach ( $keys as $key ) {
  137. if ( isset( $args[ $key ] ) ) {
  138. $this->$key = $args[ $key ];
  139. }
  140. }
  141. $this->manager = $manager;
  142. $this->id = $id;
  143. if ( empty( $this->active_callback ) ) {
  144. $this->active_callback = array( $this, 'active_callback' );
  145. }
  146. self::$instance_count += 1;
  147. $this->instance_number = self::$instance_count;
  148. $this->sections = array(); // Users cannot customize the $sections array.
  149. }
  150. /**
  151. * Check whether panel is active to current Customizer preview.
  152. *
  153. * @since 4.1.0
  154. * @access public
  155. *
  156. * @return bool Whether the panel is active to the current preview.
  157. */
  158. final public function active() {
  159. $panel = $this;
  160. $active = call_user_func( $this->active_callback, $this );
  161. /**
  162. * Filter response of WP_Customize_Panel::active().
  163. *
  164. * @since 4.1.0
  165. *
  166. * @param bool $active Whether the Customizer panel is active.
  167. * @param WP_Customize_Panel $panel {@see WP_Customize_Panel} instance.
  168. */
  169. $active = apply_filters( 'customize_panel_active', $active, $panel );
  170. return $active;
  171. }
  172. /**
  173. * Default callback used when invoking {@see WP_Customize_Panel::active()}.
  174. *
  175. * Subclasses can override this with their specific logic, or they may
  176. * provide an 'active_callback' argument to the constructor.
  177. *
  178. * @since 4.1.0
  179. * @access public
  180. *
  181. * @return bool Always true.
  182. */
  183. public function active_callback() {
  184. return true;
  185. }
  186. /**
  187. * Gather the parameters passed to client JavaScript via JSON.
  188. *
  189. * @since 4.1.0
  190. *
  191. * @return array The array to be exported to the client as JSON.
  192. */
  193. public function json() {
  194. $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'type' ) );
  195. $array['content'] = $this->get_content();
  196. $array['active'] = $this->active();
  197. $array['instanceNumber'] = $this->instance_number;
  198. return $array;
  199. }
  200. /**
  201. * Checks required user capabilities and whether the theme has the
  202. * feature support required by the panel.
  203. *
  204. * @since 4.0.0
  205. *
  206. * @return bool False if theme doesn't support the panel or the user doesn't have the capability.
  207. */
  208. final public function check_capabilities() {
  209. if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) {
  210. return false;
  211. }
  212. if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) {
  213. return false;
  214. }
  215. return true;
  216. }
  217. /**
  218. * Get the panel's content template for insertion into the Customizer pane.
  219. *
  220. * @since 4.1.0
  221. *
  222. * @return string Content for the panel.
  223. */
  224. final public function get_content() {
  225. ob_start();
  226. $this->maybe_render();
  227. $template = trim( ob_get_contents() );
  228. ob_end_clean();
  229. return $template;
  230. }
  231. /**
  232. * Check capabilities and render the panel.
  233. *
  234. * @since 4.0.0
  235. */
  236. final public function maybe_render() {
  237. if ( ! $this->check_capabilities() ) {
  238. return;
  239. }
  240. /**
  241. * Fires before rendering a Customizer panel.
  242. *
  243. * @since 4.0.0
  244. *
  245. * @param WP_Customize_Panel $this WP_Customize_Panel instance.
  246. */
  247. do_action( 'customize_render_panel', $this );
  248. /**
  249. * Fires before rendering a specific Customizer panel.
  250. *
  251. * The dynamic portion of the hook name, `$this->id`, refers to
  252. * the ID of the specific Customizer panel to be rendered.
  253. *
  254. * @since 4.0.0
  255. */
  256. do_action( "customize_render_panel_{$this->id}" );
  257. $this->render();
  258. }
  259. /**
  260. * Render the panel container, and then its contents.
  261. *
  262. * @since 4.0.0
  263. * @access protected
  264. */
  265. protected function render() {
  266. $classes = 'accordion-section control-section control-panel control-panel-' . $this->type;
  267. ?>
  268. <li id="accordion-panel-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
  269. <h3 class="accordion-section-title" tabindex="0">
  270. <?php echo esc_html( $this->title ); ?>
  271. <span class="screen-reader-text"><?php _e( 'Press return or enter to open this panel' ); ?></span>
  272. </h3>
  273. <ul class="accordion-sub-container control-panel-content">
  274. <?php $this->render_content(); ?>
  275. </ul>
  276. </li>
  277. <?php
  278. }
  279. /**
  280. * Render the sections that have been added to the panel.
  281. *
  282. * @since 4.1.0
  283. * @access protected
  284. */
  285. protected function render_content() {
  286. ?>
  287. <li class="panel-meta accordion-section control-section<?php if ( empty( $this->description ) ) { echo ' cannot-expand'; } ?>">
  288. <div class="accordion-section-title" tabindex="0">
  289. <span class="preview-notice"><?php
  290. /* translators: %s is the site/panel title in the Customizer */
  291. echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">' . esc_html( $this->title ) . '</strong>' );
  292. ?></span>
  293. </div>
  294. <?php if ( ! empty( $this->description ) ) : ?>
  295. <div class="accordion-section-content description">
  296. <?php echo $this->description; ?>
  297. </div>
  298. <?php endif; ?>
  299. </li>
  300. <?php
  301. }
  302. }