Make WordPress Core


Ignore:
Timestamp:
06/23/2022 06:46:18 PM (21 months ago)
Author:
jorbin
Message:

Editor: Universalize functions for checking block editor status.

use_block_editor_for_post_type and use_block_editor_for_post can be very useful in more contexts than wp-admin, especially when a site is in transition. For example, you may want to do things on init that are different.

Neither function depends on other functions that are available only in wp-admin (other than use_block_editor_for_post() relying on use_block_editor_for_post_type() and an admin-referrer check that's historically gated by a query variable and now also gated by is_admin), therefore moving them to wp-includes seems both feasible and beneficial

Props ethitter, jorbin.
Fixes #51819.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r53268 r53559  
    788788
    789789        $this->assertSame( $p, post_exists( $title, $content, $date ) );
    790     }
    791 
    792     public function test_use_block_editor_for_post() {
    793         $this->assertFalse( use_block_editor_for_post( -1 ) );
    794         $bogus_post_id = $this->factory()->post->create(
    795             array(
    796                 'post_type' => 'bogus',
    797             )
    798         );
    799         $this->assertFalse( use_block_editor_for_post( $bogus_post_id ) );
    800 
    801         register_post_type(
    802             'restless',
    803             array(
    804                 'show_in_rest' => false,
    805             )
    806         );
    807         $restless_post_id = $this->factory()->post->create(
    808             array(
    809                 'post_type' => 'restless',
    810             )
    811         );
    812         $this->assertFalse( use_block_editor_for_post( $restless_post_id ) );
    813 
    814         $generic_post_id = $this->factory()->post->create();
    815 
    816         add_filter( 'use_block_editor_for_post', '__return_false' );
    817         $this->assertFalse( use_block_editor_for_post( $generic_post_id ) );
    818         remove_filter( 'use_block_editor_for_post', '__return_false' );
    819 
    820         add_filter( 'use_block_editor_for_post', '__return_true' );
    821         $this->assertTrue( use_block_editor_for_post( $restless_post_id ) );
    822         remove_filter( 'use_block_editor_for_post', '__return_true' );
    823790    }
    824791
Note: See TracChangeset for help on using the changeset viewer.