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

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