PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/darmawan.fatria/df-skp-2014
PHP | 453 lines | 149 code | 42 blank | 262 comment | 13 complexity | 2188dac51510b3f0e3099870507ec17f MD5 | raw file
  1. <?php
  2. /**
  3. * WordPress Customize Section classes
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 3.4.0
  8. */
  9. /**
  10. * Customize Section class.
  11. *
  12. * A UI container for controls, managed by the WP_Customize_Manager class.
  13. *
  14. * @since 3.4.0
  15. *
  16. * @see WP_Customize_Manager
  17. */
  18. class WP_Customize_Section {
  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 3.4.0
  41. * @access public
  42. * @var WP_Customize_Manager
  43. */
  44. public $manager;
  45. /**
  46. * Unique identifier.
  47. *
  48. * @since 3.4.0
  49. * @access public
  50. * @var string
  51. */
  52. public $id;
  53. /**
  54. * Priority of the section which informs load order of sections.
  55. *
  56. * @since 3.4.0
  57. * @access public
  58. * @var integer
  59. */
  60. public $priority = 160;
  61. /**
  62. * Panel in which to show the section, making it a sub-section.
  63. *
  64. * @since 4.0.0
  65. * @access public
  66. * @var string
  67. */
  68. public $panel = '';
  69. /**
  70. * Capability required for the section.
  71. *
  72. * @since 3.4.0
  73. * @access public
  74. * @var string
  75. */
  76. public $capability = 'edit_theme_options';
  77. /**
  78. * Theme feature support for the section.
  79. *
  80. * @since 3.4.0
  81. * @access public
  82. * @var string|array
  83. */
  84. public $theme_supports = '';
  85. /**
  86. * Title of the section to show in UI.
  87. *
  88. * @since 3.4.0
  89. * @access public
  90. * @var string
  91. */
  92. public $title = '';
  93. /**
  94. * Description to show in the UI.
  95. *
  96. * @since 3.4.0
  97. * @access public
  98. * @var string
  99. */
  100. public $description = '';
  101. /**
  102. * Customizer controls for this section.
  103. *
  104. * @since 3.4.0
  105. * @access public
  106. * @var array
  107. */
  108. public $controls;
  109. /**
  110. * Type of this section.
  111. *
  112. * @since 4.1.0
  113. * @access public
  114. * @var string
  115. */
  116. public $type = 'default';
  117. /**
  118. * Active callback.
  119. *
  120. * @since 4.1.0
  121. * @access public
  122. *
  123. * @see WP_Customize_Section::active()
  124. *
  125. * @var callable Callback is called with one argument, the instance of
  126. * {@see WP_Customize_Section}, and returns bool to indicate
  127. * whether the section is active (such as it relates to the URL
  128. * currently being previewed).
  129. */
  130. public $active_callback = '';
  131. /**
  132. * Constructor.
  133. *
  134. * Any supplied $args override class property defaults.
  135. *
  136. * @since 3.4.0
  137. *
  138. * @param WP_Customize_Manager $manager Customizer bootstrap instance.
  139. * @param string $id An specific ID of the section.
  140. * @param array $args Section arguments.
  141. */
  142. public function __construct( $manager, $id, $args = array() ) {
  143. $keys = array_keys( get_object_vars( $this ) );
  144. foreach ( $keys as $key ) {
  145. if ( isset( $args[ $key ] ) ) {
  146. $this->$key = $args[ $key ];
  147. }
  148. }
  149. $this->manager = $manager;
  150. $this->id = $id;
  151. if ( empty( $this->active_callback ) ) {
  152. $this->active_callback = array( $this, 'active_callback' );
  153. }
  154. self::$instance_count += 1;
  155. $this->instance_number = self::$instance_count;
  156. $this->controls = array(); // Users cannot customize the $controls array.
  157. }
  158. /**
  159. * Check whether section is active to current Customizer preview.
  160. *
  161. * @since 4.1.0
  162. * @access public
  163. *
  164. * @return bool Whether the section is active to the current preview.
  165. */
  166. final public function active() {
  167. $section = $this;
  168. $active = call_user_func( $this->active_callback, $this );
  169. /**
  170. * Filter response of {@see WP_Customize_Section::active()}.
  171. *
  172. * @since 4.1.0
  173. *
  174. * @param bool $active Whether the Customizer section is active.
  175. * @param WP_Customize_Section $section {@see WP_Customize_Section} instance.
  176. */
  177. $active = apply_filters( 'customize_section_active', $active, $section );
  178. return $active;
  179. }
  180. /**
  181. * Default callback used when invoking {@see WP_Customize_Section::active()}.
  182. *
  183. * Subclasses can override this with their specific logic, or they may provide
  184. * an 'active_callback' argument to the constructor.
  185. *
  186. * @since 4.1.0
  187. * @access public
  188. *
  189. * @return bool Always true.
  190. */
  191. public function active_callback() {
  192. return true;
  193. }
  194. /**
  195. * Gather the parameters passed to client JavaScript via JSON.
  196. *
  197. * @since 4.1.0
  198. *
  199. * @return array The array to be exported to the client as JSON.
  200. */
  201. public function json() {
  202. $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'panel', 'type' ) );
  203. $array['content'] = $this->get_content();
  204. $array['active'] = $this->active();
  205. $array['instanceNumber'] = $this->instance_number;
  206. return $array;
  207. }
  208. /**
  209. * Checks required user capabilities and whether the theme has the
  210. * feature support required by the section.
  211. *
  212. * @since 3.4.0
  213. *
  214. * @return bool False if theme doesn't support the section or user doesn't have the capability.
  215. */
  216. final public function check_capabilities() {
  217. if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) {
  218. return false;
  219. }
  220. if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) {
  221. return false;
  222. }
  223. return true;
  224. }
  225. /**
  226. * Get the section's content template for insertion into the Customizer pane.
  227. *
  228. * @since 4.1.0
  229. *
  230. * @return string Contents of the section.
  231. */
  232. final public function get_content() {
  233. ob_start();
  234. $this->maybe_render();
  235. $template = trim( ob_get_contents() );
  236. ob_end_clean();
  237. return $template;
  238. }
  239. /**
  240. * Check capabilities and render the section.
  241. *
  242. * @since 3.4.0
  243. */
  244. final public function maybe_render() {
  245. if ( ! $this->check_capabilities() ) {
  246. return;
  247. }
  248. /**
  249. * Fires before rendering a Customizer section.
  250. *
  251. * @since 3.4.0
  252. *
  253. * @param WP_Customize_Section $this WP_Customize_Section instance.
  254. */
  255. do_action( 'customize_render_section', $this );
  256. /**
  257. * Fires before rendering a specific Customizer section.
  258. *
  259. * The dynamic portion of the hook name, `$this->id`, refers to the ID
  260. * of the specific Customizer section to be rendered.
  261. *
  262. * @since 3.4.0
  263. */
  264. do_action( "customize_render_section_{$this->id}" );
  265. $this->render();
  266. }
  267. /**
  268. * Render the section, and the controls that have been added to it.
  269. *
  270. * @since 3.4.0
  271. */
  272. protected function render() {
  273. $classes = 'accordion-section control-section control-section-' . $this->type;
  274. ?>
  275. <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
  276. <h3 class="accordion-section-title" tabindex="0">
  277. <?php echo esc_html( $this->title ); ?>
  278. <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span>
  279. </h3>
  280. <ul class="accordion-section-content">
  281. <?php if ( ! empty( $this->description ) ) : ?>
  282. <li class="customize-section-description-container">
  283. <p class="description customize-section-description"><?php echo $this->description; ?></p>
  284. </li>
  285. <?php endif; ?>
  286. </ul>
  287. </li>
  288. <?php
  289. }
  290. }
  291. /**
  292. * Customize Themes Section class.
  293. *
  294. * A UI container for theme controls, which behaves like a backwards Panel.
  295. *
  296. * @since 4.2.0
  297. *
  298. * @see WP_Customize_Section
  299. */
  300. class WP_Customize_Themes_Section extends WP_Customize_Section {
  301. /**
  302. * Customize section type.
  303. *
  304. * @since 4.2.0
  305. * @access public
  306. * @var string
  307. */
  308. public $type = 'themes';
  309. /**
  310. * Render the themes section, which behaves like a panel.
  311. *
  312. * @since 4.2.0
  313. * @access protected
  314. */
  315. protected function render() {
  316. $classes = 'accordion-section control-section control-section-' . $this->type;
  317. ?>
  318. <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
  319. <h3 class="accordion-section-title">
  320. <?php
  321. if ( $this->manager->is_theme_active() ) {
  322. /* translators: %s: theme name */
  323. printf( __( '<span>Active theme</span> %s' ), $this->title );
  324. } else {
  325. /* translators: %s: theme name */
  326. printf( __( '<span>Previewing theme</span> %s' ), $this->title );
  327. }
  328. ?>
  329. <button type="button" class="button change-theme"><?php _ex( 'Change', 'theme' ); ?></button>
  330. </h3>
  331. <div class="customize-themes-panel control-panel-content themes-php">
  332. <h2>
  333. <?php _e( 'Themes' ); ?>
  334. <span class="title-count theme-count"><?php echo count( $this->controls ) + 1 /* Active theme */; ?></span>
  335. </h2>
  336. <h3 class="accordion-section-title customize-section-title">
  337. <?php
  338. if ( $this->manager->is_theme_active() ) {
  339. /* translators: %s: theme name */
  340. printf( __( '<span>Active theme</span> %s' ), $this->title );
  341. } else {
  342. /* translators: %s: theme name */
  343. printf( __( '<span>Previewing theme</span> %s' ), $this->title );
  344. }
  345. ?>
  346. <button type="button" class="button customize-theme"><?php _e( 'Customize' ); ?></button>
  347. </h3>
  348. <div class="theme-overlay" tabindex="0" role="dialog" aria-label="<?php esc_attr_e( 'Theme Details' ); ?>"></div>
  349. <div id="customize-container"></div>
  350. <?php if ( count( $this->controls ) > 4 ) : ?>
  351. <p><label for="themes-filter">
  352. <span class="screen-reader-text"><?php _e( 'Search installed themes...' ); ?></span>
  353. <input type="text" id="themes-filter" placeholder="<?php esc_attr_e( 'Search installed themes...' ); ?>" />
  354. </label></p>
  355. <?php endif; ?>
  356. <div class="theme-browser rendered">
  357. <ul class="themes accordion-section-content">
  358. </ul>
  359. </div>
  360. </div>
  361. </li>
  362. <?php }
  363. }
  364. /**
  365. * Customizer section representing widget area (sidebar).
  366. *
  367. * @since 4.1.0
  368. *
  369. * @see WP_Customize_Section
  370. */
  371. class WP_Customize_Sidebar_Section extends WP_Customize_Section {
  372. /**
  373. * Type of this section.
  374. *
  375. * @since 4.1.0
  376. * @access public
  377. * @var string
  378. */
  379. public $type = 'sidebar';
  380. /**
  381. * Unique identifier.
  382. *
  383. * @since 4.1.0
  384. * @access public
  385. * @var string
  386. */
  387. public $sidebar_id;
  388. /**
  389. * Gather the parameters passed to client JavaScript via JSON.
  390. *
  391. * @since 4.1.0
  392. *
  393. * @return array The array to be exported to the client as JSON.
  394. */
  395. public function json() {
  396. $json = parent::json();
  397. $json['sidebarId'] = $this->sidebar_id;
  398. return $json;
  399. }
  400. /**
  401. * Whether the current sidebar is rendered on the page.
  402. *
  403. * @since 4.1.0
  404. * @access public
  405. *
  406. * @return bool Whether sidebar is rendered.
  407. */
  408. public function active_callback() {
  409. return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id );
  410. }
  411. }