wp_widget_control

Meta widget used to display the control form for a widget.

Description

(array) wp_widget_control( (array) $sidebar_args ); 

Called from dynamic_sidebar().

Returns (array)

Parameters (1)

0. $sidebar_args (array)
The sidebar args.

Usage

  1. if ( !function_exists( 'wp_widget_control' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/widgets.php'; 
  3.  
  4. // The sidebar args. 
  5. $sidebar_args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_widget_control($sidebar_args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/widgets.php  
  1. function wp_widget_control( $sidebar_args ) { 
  2. global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets; 
  3.  
  4. $widget_id = $sidebar_args['widget_id']; 
  5. $sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false; 
  6. $key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : '-1'; // position of widget in sidebar 
  7. $control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array(); 
  8. $widget = $wp_registered_widgets[$widget_id]; 
  9.  
  10. $id_format = $widget['id']; 
  11. $widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : ''; 
  12. $id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id; 
  13. $multi_number = isset($sidebar_args['_multi_num']) ? $sidebar_args['_multi_num'] : ''; 
  14. $add_new = isset($sidebar_args['_add']) ? $sidebar_args['_add'] : ''; 
  15.  
  16. $before_form = isset( $sidebar_args['before_form'] ) ? $sidebar_args['before_form'] : '<form method="post">'; 
  17. $after_form = isset( $sidebar_args['after_form'] ) ? $sidebar_args['after_form'] : '</form>'; 
  18. $before_widget_content = isset( $sidebar_args['before_widget_content'] ) ? $sidebar_args['before_widget_content'] : '<div class="widget-content">'; 
  19. $after_widget_content = isset( $sidebar_args['after_widget_content'] ) ? $sidebar_args['after_widget_content'] : '</div>'; 
  20.  
  21. $query_arg = array( 'editwidget' => $widget['id'] ); 
  22. if ( $add_new ) { 
  23. $query_arg['addnew'] = 1; 
  24. if ( $multi_number ) { 
  25. $query_arg['num'] = $multi_number; 
  26. $query_arg['base'] = $id_base; 
  27. } else { 
  28. $query_arg['sidebar'] = $sidebar_id; 
  29. $query_arg['key'] = $key; 
  30.  
  31. /** 
  32. * We aren't showing a widget control, we're outputting a template 
  33. * for a multi-widget control. 
  34. */ 
  35. if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) { 
  36. // number == -1 implies a template where id numbers are replaced by a generic '__i__' 
  37. $control['params'][0]['number'] = -1; 
  38. // With id_base widget id's are constructed like {$id_base}-{$id_number}. 
  39. if ( isset($control['id_base']) ) 
  40. $id_format = $control['id_base'] . '-__i__'; 
  41.  
  42. $wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback']; 
  43. unset($wp_registered_widgets[$widget_id]['_callback']); 
  44.  
  45. $widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) ); 
  46. $has_form = 'noform'; 
  47.  
  48. echo $sidebar_args['before_widget']; ?> 
  49. <div class="widget-top"> 
  50. <div class="widget-title-action"> 
  51. <a class="widget-action hide-if-no-js" href="#available-widgets"></a> 
  52. <a class="widget-control-edit hide-if-js" href="<?php echo esc_url( add_query_arg( $query_arg ) ); ?>"> 
  53. <span class="edit"><?php _ex( 'Edit', 'widget' ); ?></span> 
  54. <span class="add"><?php _ex( 'Add', 'widget' ); ?></span> 
  55. <span class="screen-reader-text"><?php echo $widget_title; ?></span> 
  56. </a> 
  57. </div> 
  58. <div class="widget-title"><h3><?php echo $widget_title; ?><span class="in-widget-title"></span></h3></div> 
  59. </div> 
  60.  
  61. <div class="widget-inside"> 
  62. <?php echo $before_form; ?> 
  63. <?php echo $before_widget_content; ?> 
  64. <?php 
  65. if ( isset( $control['callback'] ) ) { 
  66. $has_form = call_user_func_array( $control['callback'], $control['params'] ); 
  67. } else { 
  68. echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; 
  69. ?> 
  70. <?php echo $after_widget_content; ?> 
  71. <input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($id_format); ?>" /> 
  72. <input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" /> 
  73. <input type="hidden" name="widget-width" class="widget-width" value="<?php if (isset( $control['width'] )) echo esc_attr($control['width']); ?>" /> 
  74. <input type="hidden" name="widget-height" class="widget-height" value="<?php if (isset( $control['height'] )) echo esc_attr($control['height']); ?>" /> 
  75. <input type="hidden" name="widget_number" class="widget_number" value="<?php echo esc_attr($widget_number); ?>" /> 
  76. <input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" /> 
  77. <input type="hidden" name="add_new" class="add_new" value="<?php echo esc_attr($add_new); ?>" /> 
  78.  
  79. <div class="widget-control-actions"> 
  80. <div class="alignleft"> 
  81. <a class="widget-control-remove" href="#remove"><?php _e('Delete'); ?></a> | 
  82. <a class="widget-control-close" href="#close"><?php _e('Close'); ?></a> 
  83. </div> 
  84. <div class="alignright<?php if ( 'noform' === $has_form ) echo ' widget-control-noform'; ?>"> 
  85. <?php submit_button( __( 'Save' ), 'primary widget-control-save right', 'savewidget', false, array( 'id' => 'widget-' . esc_attr( $id_format ) . '-savewidget' ) ); ?> 
  86. <span class="spinner"></span> 
  87. </div> 
  88. <br class="clear" /> 
  89. </div> 
  90. <?php echo $after_form; ?> 
  91. </div> 
  92.  
  93. <div class="widget-description"> 
  94. <?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?> 
  95. </div> 
  96. <?php 
  97. echo $sidebar_args['after_widget']; 
  98.  
  99. return $sidebar_args;