WP_Widget::__construct() WordPress Method

The WP_Widget::__construct() method allows a plugin to register a widget with WordPress. This method takes two arguments: the widget ID and the widget name. The widget ID is a unique identifier for the widget. The widget name is the name that will be displayed in the WordPress admin interface. This method can be used in conjunction with the WP_Widget::register() method to programmatically register a widget with WordPress.

WP_Widget::__construct( string $id_base, string $name, array $widget_options = array(), array $control_options = array() ) #

PHP5 constructor.


Parameters

$id_base

(string)(Optional) Base ID for the widget, lowercase and unique. If left empty, a portion of the widget's PHP class name will be used. Has to be unique.

$name

(string)(Optional)Name for the widget displayed on the configuration page.

$widget_options

(array)(Optional) Widget options. See wp_register_sidebar_widget() for information on accepted arguments.

Default value: array()

$control_options

(array)(Optional) Widget control options. See wp_register_widget_control() for information on accepted arguments.

Default value: array()


Top ↑

Source

File: wp-includes/class-wp-widget.php

	public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
		if ( ! empty( $id_base ) ) {
			$id_base = strtolower( $id_base );
		} else {
			$id_base = preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) );
		}

		$this->id_base         = $id_base;
		$this->name            = $name;
		$this->option_name     = 'widget_' . $this->id_base;
		$this->widget_options  = wp_parse_args(
			$widget_options,
			array(
				'classname'                   => str_replace( '\\', '_', $this->option_name ),
				'customize_selective_refresh' => false,
			)
		);
		$this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
	}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.