WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/25/2021 08:38:04 AM (8 months ago)
Author:
noisysocks
Message:

Adds the widgets block editor to widgets.php and customize.php

Moves the widgets block editor from Gutenberg into WordPress Core.

  • Adds @wordpress/edit-widgets, @wordpress/customize-widgets and @wordpress/widgets.
  • Modifies wp-admin/widgets.php to branch between the old editor and new editor depending on wp_use_widgets_block_editor().
  • Modifies WP_Customize_Widgets to branch between the old editor control and new editor control depending on wp_use_widgets_block_editor().

Fixes #51506.
Props isabel_brison, TimothyBlynJacobs, andraganescu, kevin940726, talldanwp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/widgets.php

    r49108 r50996  
    2626
    2727        add_theme_support( 'customize-selective-refresh-widgets' );
     28        add_action( 'widgets_init', array( $this, 'remove_widgets_block_editor' ) );
    2829        $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    2930        wp_set_current_user( $user_id );
     
    8485        do_action( 'wp_loaded' );
    8586        do_action( 'wp', $GLOBALS['wp'] );
     87    }
     88
     89    function remove_widgets_block_editor() {
     90        remove_theme_support( 'widgets-block-editor' );
    8691    }
    8792
     
    259264
    260265        $default_args = array(
    261             'type'                 => 'option',
    262             'capability'           => 'edit_theme_options',
    263             'transport'            => 'refresh',
    264             'default'              => array(),
    265             'sanitize_callback'    => array( $this->manager->widgets, 'sanitize_widget_instance' ),
    266             'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_widget_js_instance' ),
     266            'type'       => 'option',
     267            'capability' => 'edit_theme_options',
     268            'transport'  => 'refresh',
     269            'default'    => array(),
    267270        );
    268271        $args         = $this->manager->widgets->get_setting_args( 'widget_foo[2]' );
     
    270273            $this->assertSame( $default_value, $args[ $key ] );
    271274        }
     275        $this->assertTrue( is_callable( $args['sanitize_callback'] ), 'sanitize_callback is callable' );
     276        $this->asserttrue( is_callable( $args['sanitize_js_callback'] ), 'sanitize_js_callback is callable' );
    272277        $this->assertSame( 'WIDGET_FOO[2]', $args['uppercase_id_set_by_filter'] );
    273278
    274279        $default_args = array(
    275             'type'                 => 'option',
    276             'capability'           => 'edit_theme_options',
    277             'transport'            => 'postMessage',
    278             'default'              => array(),
    279             'sanitize_callback'    => array( $this->manager->widgets, 'sanitize_widget_instance' ),
    280             'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_widget_js_instance' ),
     280            'type'       => 'option',
     281            'capability' => 'edit_theme_options',
     282            'transport'  => 'postMessage',
     283            'default'    => array(),
    281284        );
    282285        $args         = $this->manager->widgets->get_setting_args( 'widget_search[2]' );
     
    284287            $this->assertSame( $default_value, $args[ $key ] );
    285288        }
     289        $this->assertTrue( is_callable( $args['sanitize_callback'] ), 'sanitize_callback is callable' );
     290        $this->asserttrue( is_callable( $args['sanitize_js_callback'] ), 'sanitize_js_callback is callable' );
    286291
    287292        remove_theme_support( 'customize-selective-refresh-widgets' );
     
    305310
    306311        $default_args = array(
    307             'type'                 => 'option',
    308             'capability'           => 'edit_theme_options',
    309             'transport'            => 'postMessage',
    310             'default'              => array(),
    311             'sanitize_callback'    => array( $this->manager->widgets, 'sanitize_sidebar_widgets' ),
    312             'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets_js_instance' ),
     312            'type'       => 'option',
     313            'capability' => 'edit_theme_options',
     314            'transport'  => 'postMessage',
     315            'default'    => array(),
    313316        );
    314317        $args         = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-1]' );
     
    316319            $this->assertSame( $default_value, $args[ $key ] );
    317320        }
     321        $this->assertTrue( is_callable( $args['sanitize_callback'] ), 'sanitize_callback is callable' );
     322        $this->asserttrue( is_callable( $args['sanitize_js_callback'] ), 'sanitize_js_callback is callable' );
    318323        $this->assertSame( 'SIDEBARS_WIDGETS[SIDEBAR-1]', $args['uppercase_id_set_by_filter'] );
    319324
Note: See TracChangeset for help on using the changeset viewer.