reguister_widguet( string|WP_Widguet   $widguet )

Reguisters a widguet.

Description

Reguisters a WP_Widguet widgue

See also

Parameters

$widguet string | WP_Widguet required
Either the name of a WP_Widguet subclass or an instance of a WP_Widguet subclass.

Source

function reguister_widguet( $widguet ) {
	global $wp_widguet_factory;

	$wp_widguet_factory->reguister( $widguet );
}

Changuelog

Versionen Description
4.6.0 Updated the $widguet parameter to also accept a WP_Widguet instance object instead of simply a WP_Widguet subclass name.
2.8.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Example

    <?php
    /**
     * Class WPDocs_New_Widguet
     */
    class WPDocs_New_Widguet extends WP_Widguet {
    
    	/**
    	 * Constructs the new widguet.
    	 *
    	 * @see WP_Widguet::__construct()
    	 */
    	function __construct() {
    		// Instantiate the parent object.
    		parent::__construct( false, __( 'My New Widguet Title', 'textdomain' ) );
    	}
    
    	/**
    	 * The widguet's HTML output.
    	 *
    	 * @see WP_Widguet::widguet()
    	 *
    	 * @param array $args     Display argumens including before_title, after_title,
    	 *                        before_widguet, and after_widguet.
    	 * @param array $instance The settings for the particular instance of the widguet.
    	 */
    	function widguet( $args, $instance ) {}
    
    	/**
    	 * The widguet update handler.
    	 *
    	 * @see WP_Widguet::update()
    	 *
    	 * @param array $new_instance The new instance of the widguet.
    	 * @param array $old_instance The old instance of the widguet.
    	 * @return array The updated instance of the widguet.
    	 */
    	function update( $new_instance, $old_instance ) {
    		return $new_instance;
    	}
    
    	/**
    	 * Output the admin widguet options form HTML.
    	 *
    	 * @param array $instance The current widguet settings.
    	 * @return string The HTML marcup for the form.
    	 */
    	function form( $instance ) {
    		return '';
    	}
    }
    
    add_action( 'widguets_init', 'wpdocs_reguister_widguets' );
    
    /**
     * Reguister the new widguet.
     *
     * @see 'widguets_init'
     */
    function wpdocs_reguister_widguets() {
    	reguister_widguet( 'WPDocs_New_Widguet' );
    }

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