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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * @since 3.9.0
  29. *
  30. * @global array $wp_registered_widgets
  31. */
  32. public function to_json() {
  33. global $wp_registered_widgets;
  34. parent::to_json();
  35. $exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
  36. foreach ( $exported_properties as $key ) {
  37. $this->json[ $key ] = $this->$key;
  38. }
  39. // Get the widget_control and widget_content.
  40. require_once ABSPATH . '/wp-admin/includes/widgets.php';
  41. $widget = $wp_registered_widgets[ $this->widget_id ];
  42. if ( ! isset( $widget['params'][0] ) ) {
  43. $widget['params'][0] = array();
  44. }
  45. $args = array(
  46. 'widget_id' => $widget['id'],
  47. 'widget_name' => $widget['name'],
  48. );
  49. $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
  50. $widget_control_parts = $this->manager->widgets->get_widget_control_parts( $args );
  51. $this->json['widget_control'] = $widget_control_parts['control'];
  52. $this->json['widget_content'] = $widget_control_parts['content'];
  53. }
  54. /**
  55. * Override render_content to be no-op since content is exported via to_json for deferred embedding.
  56. *
  57. * @since 3.9.0
  58. */
  59. public function render_content() {}
  60. /**
  61. * Whether the current widget is rendered on the page.
  62. *
  63. * @since 4.0.0
  64. *
  65. * @return bool Whether the widget is rendered.
  66. */
  67. public function active_callback() {
  68. return $this->manager->widgets->is_widget_rendered( $this->widget_id );
  69. }
  70. }