_register_one example

$empty    = true;

        // When $settings is an array-like object, get an intrinsic array for use with array_keys().         if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) {
            $settings = $settings->getArrayCopy();
        }

        if ( is_array( $settings ) ) {
            foreach ( array_keys( $settings ) as $number ) {
                if ( is_numeric( $number ) ) {
                    $this->_set( $number );
                    $this->_register_one( $number );
                    $empty = false;
                }
            }
        }

        if ( $empty ) {
            // If there are none, we register the widget's existence with a generic template.             $this->_set( 1 );
            $this->_register_one();
        }
    }

    


    /** * Add hooks while registering all widget instances of this widget class. * * @since 4.8.0 * * @param int $number Optional. The unique order number of this widget instance * compared to other instances of the same class. Default -1. */
    public function _register_one( $number = -1 ) {
        parent::_register_one( $number );
        if ( $this->registered ) {
            return;
        }
        $this->registered = true;

        /* * 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' ) );

        


    /** * Add hooks for enqueueing assets when registering all widget instances of this widget class. * * @since 4.9.0 * * @param int $number Optional. The unique order number of this widget instance * compared to other instances of the same class. Default -1. */
    public function _register_one( $number = -1 ) {
        parent::_register_one( $number );
        if ( $this->registered ) {
            return;
        }
        $this->registered = true;

        /* * 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' ) );

        
ob_start();
            call_user_func_array( $callback$params );
            ob_end_clean();
        }

        $_POST    = $original_post;
        $_REQUEST = $original_request;

        if ( $widget_object ) {
            // Register any multi-widget that the update callback just created.             $widget_object->_set( $number );
            $widget_object->_register_one( $number );

            /* * WP_Widget sets `updated = true` after an update to prevent more than one widget * from being saved per request. This isn't what we want in the REST API, though, * as we support batch requests. */
            $widget_object->updated = false;
        }

        /** * Fires after a widget is created or updated via the REST API. * * @since 5.8.0 * * @param string $id ID of the widget being saved. * @param string $sidebar_id ID of the sidebar containing the widget being saved. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a widget, false when updating. */

        parent::__construct( 'text', __( 'Text' )$widget_ops$control_ops );
    }

    /** * Adds hooks for enqueueing assets when registering all widget instances of this widget class. * * @param int $number Optional. The unique order number of this widget instance * compared to other instances of the same class. Default -1. */
    public function _register_one( $number = -1 ) {
        parent::_register_one( $number );
        if ( $this->registered ) {
            return;
        }
        $this->registered = true;

        if ( $this->is_preview() ) {
            add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
        }

        /* * Note that the widgets component in the customizer will also do * the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts(). */
Home | Imprint | This part of the site doesn't use cookies.