_register_widget_form_callback

Registers the form callback for a widget.

Description

_register_widget_form_callback( (int|string) $id, (string) $name, (callable) $form_callback, (array) $options = array() ); 

Parameters (4)

0. $id (int|string)
Widget ID.
1. $name (string)
Name attribute for the widget.
2. $form_callback (callable)
The form callback.
3. $options — Optional. (array) => array()
Widget control options. See wp_register_widget_control(). Default empty array.

Usage

  1. if ( !function_exists( '_register_widget_form_callback' ) ) { 
  2. require_once ABSPATH . WPINC . '/widgets.php'; 
  3.  
  4. // Widget ID. 
  5. $id = null; 
  6.  
  7. // Name attribute for the widget. 
  8. $name = ''; 
  9.  
  10. // The form callback. 
  11. $form_callback = null; 
  12.  
  13. // Optional. Widget control options. See wp_register_widget_control(). 
  14. // Default empty array. 
  15. $options = array(); 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = _register_widget_form_callback($id, $name, $form_callback, $options); 
  19.  

Defined (1)

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

/wp-includes/widgets.php  
  1. function _register_widget_form_callback($id, $name, $form_callback, $options = array()) { 
  2. global $wp_registered_widget_controls; 
  3.  
  4. $id = strtolower($id); 
  5.  
  6. if ( empty($form_callback) ) { 
  7. unset($wp_registered_widget_controls[$id]); 
  8. return; 
  9.  
  10. if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) ) 
  11. return; 
  12.  
  13. $defaults = array('width' => 250, 'height' => 200 ); 
  14. $options = wp_parse_args($options, $defaults); 
  15. $options['width'] = (int) $options['width']; 
  16. $options['height'] = (int) $options['height']; 
  17.  
  18. $widget = array( 
  19. 'name' => $name,  
  20. 'id' => $id,  
  21. 'callback' => $form_callback,  
  22. 'params' => array_slice(func_get_args(), 4) 
  23. ); 
  24. $widget = array_merge($widget, $options); 
  25.  
  26. $wp_registered_widget_controls[$id] = $widget;