WP_Widget_Custom_HTML::_register_one() WordPress Method

The WP_Widget_Custom_HTML::_register_one() method is used to register a single widget with WordPress. This method takes two arguments: the widget ID and the widget name. The widget ID is used to identify the widget in the database, and the widget name is used to display the widget in the WordPress admin interface.

WP_Widget_Custom_HTML::_register_one( int $number = -1 ) #

Add hooks for enqueueing assets when registering all widget instances of this widget class.


Parameters

$number

(int)(Optional) The unique order number of this widget instance compared to other instances of the same class.

Default value: -1


Top ↑

Source

File: wp-includes/widgets/class-wp-widget-custom-html.php

	public function _register_one( $number = -1 ) {
		parent::_register_one( $number );
		if ( $this->registered ) {
			return;
		}
		$this->registered = true;

		wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );

		// Note that the widgets component in the customizer will also do
		// the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
		add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );

		// Note that the widgets component in the customizer will also do
		// the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
		add_action( 'admin_footer-widgets.php', array( 'WP_Widget_Custom_HTML', 'render_control_template_scripts' ) );

		// Note this action is used to ensure the help text is added to the end.
		add_action( 'admin_head-widgets.php', array( 'WP_Widget_Custom_HTML', 'add_help_text' ) );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.9.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.