Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

class-wp-widget-form-customize-control.php 1.9 KiB

3 роки тому
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Customize API: WP_Widget_Form_Customize_Control class
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 4.4.0
  8. */
  9. /**
  10. * Widget Form Customize Control class.
  11. *
  12. * @since 3.9.0
  13. *
  14. * @see WP_Customize_Control
  15. */
  16. class WP_Widget_Form_Customize_Control extends WP_Customize_Control {
  17. public $type = 'widget_form';
  18. public $widget_id;
  19. public $widget_id_base;
  20. public $sidebar_id;
  21. public $is_new = false;
  22. public $width;
  23. public $height;
  24. public $is_wide = false;
  25. /**
  26. * Gather control params for exporting to JavaScript.
  27. *
  28. * @global array $wp_registered_widgets
  29. */
  30. public function to_json() {
  31. global $wp_registered_widgets;
  32. parent::to_json();
  33. $exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
  34. foreach ( $exported_properties as $key ) {
  35. $this->json[ $key ] = $this->$key;
  36. }
  37. // Get the widget_control and widget_content.
  38. require_once ABSPATH . '/wp-admin/includes/widgets.php';
  39. $widget = $wp_registered_widgets[ $this->widget_id ];
  40. if ( ! isset( $widget['params'][0] ) ) {
  41. $widget['params'][0] = array();
  42. }
  43. $args = array(
  44. 'widget_id' => $widget['id'],
  45. 'widget_name' => $widget['name'],
  46. );
  47. $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
  48. $widget_control_parts = $this->manager->widgets->get_widget_control_parts( $args );
  49. $this->json['widget_control'] = $widget_control_parts['control'];
  50. $this->json['widget_content'] = $widget_control_parts['content'];
  51. }
  52. /**
  53. * Override render_content to be no-op since content is exported via to_json for deferred embedding.
  54. */
  55. public function render_content() {}
  56. /**
  57. * Whether the current widget is rendered on the page.
  58. *
  59. * @since 4.0.0
  60. * @access public
  61. *
  62. * @return bool Whether the widget is rendered.
  63. */
  64. public function active_callback() {
  65. return $this->manager->widgets->is_widget_rendered( $this->widget_id );
  66. }
  67. }