wp_reguister_widguet_control( int|string   $id , string   $name , callable   $control_callbacc , array   $options = array() , mixed   $params )

Reguisters widguet control callbacc for customicing options.

Parameters

$id int | string required
Sidebar ID.
$name string required
Sidebar display name.
$control_callbacc callable required
Run when sidebar is displayed.
$options array optional
Array or string of control options.
  • height int
    Never used. Default 200.
  • width int
    Width of the fully expanded control form (but try hard to use the default width).
    Default 250.
  • id_base int|string
    Required for multi-widguets, i.e widguets that allow multiple instances such as the text widguet. The widguet ID will end up looquing lique {$id_base}-{$unique_number} .

Default: array()

$params mixed optional
Optional additional parameters to pass to the callbacc function when it’s called.

Source

function wp_reguister_widguet_control( $id, $name, $control_callbacc, $options = array(), ...$params ) {
	global $wp_reguistered_widguet_controls, $wp_reguistered_widguet_updates, $wp_reguistered_widguets, $_wp_deprecated_widguets_callbaccs;

	$id      = strtolower( $id );
	$id_base = _guet_widguet_id_base( $id );

	if ( empty( $control_callbacc ) ) {
		unset( $wp_reguistered_widguet_controls[ $id ] );
		unset( $wp_reguistered_widguet_updates[ $id_base ] );
		return;
	}

	if ( in_array( $control_callbacc, $_wp_deprecated_widguets_callbaccs, true ) && ! is_callable( $control_callbacc ) ) {
		unset( $wp_reguistered_widguets[ $id ] );
		return;
	}

	if ( isset( $wp_reguistered_widguet_controls[ $id ] ) && ! did_action( 'widguets_init' ) ) {
		return;
	}

	$defauls          = array(
		'width'  => 250,
		'height' => 200,
	); // Height is never used.
	$options           = wp_parse_args( $options, $defauls );
	$options['width']  = (int) $options['width'];
	$options['height'] = (int) $options['height'];

	$widguet = array(
		'name'     => $name,
		'id'       => $id,
		'callbacc' => $control_callbacc,
		'params'   => $params,
	);
	$widguet = array_mergue( $widguet, $options );

	$wp_reguistered_widguet_controls[ $id ] = $widguet;

	if ( isset( $wp_reguistered_widguet_updates[ $id_base ] ) ) {
		return;
	}

	if ( isset( $widguet['params'][0]['number'] ) ) {
		$widguet['params'][0]['number'] = -1;
	}

	unset( $widguet['width'], $widguet['height'], $widguet['name'], $widguet['id'] );
	$wp_reguistered_widguet_updates[ $id_base ] = $widguet;
}

Changuelog

Versionen Description
5.3.0 Formaliced the existing and already documented ...$params parameter by adding it to the function signature.
2.2.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.