Make WordPress Core


Ignore:
Timestamp:
06/23/2022 06:46:18 PM (4 years 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/post.php

    r53238 r53559  
    18451845                $this->assertSameSets( array( 1, 2, 2 ), get_option( 'sticky_posts' ) );
    18461846        }
     1847
     1848        /**
     1849         * Check if post supports block editor.
     1850         *
     1851         * @ticket 51819
     1852         * @covers ::use_block_editor_for_post
     1853         */
     1854        public function test_use_block_editor_for_post() {
     1855                $this->assertFalse( use_block_editor_for_post( -1 ) );
     1856                $bogus_post_id = $this->factory()->post->create(
     1857                        array(
     1858                                'post_type' => 'bogus',
     1859                        )
     1860                );
     1861                $this->assertFalse( use_block_editor_for_post( $bogus_post_id ) );
     1862
     1863                register_post_type(
     1864                        'restless',
     1865                        array(
     1866                                'show_in_rest' => false,
     1867                        )
     1868                );
     1869                $restless_post_id = $this->factory()->post->create(
     1870                        array(
     1871                                'post_type' => 'restless',
     1872                        )
     1873                );
     1874                $this->assertFalse( use_block_editor_for_post( $restless_post_id ) );
     1875
     1876                $generic_post_id = $this->factory()->post->create();
     1877
     1878                add_filter( 'use_block_editor_for_post', '__return_false' );
     1879                $this->assertFalse( use_block_editor_for_post( $generic_post_id ) );
     1880                remove_filter( 'use_block_editor_for_post', '__return_false' );
     1881
     1882                add_filter( 'use_block_editor_for_post', '__return_true' );
     1883                $this->assertTrue( use_block_editor_for_post( $restless_post_id ) );
     1884                remove_filter( 'use_block_editor_for_post', '__return_true' );
     1885        }
    18471886}
Note: See TracChangeset for help on using the changeset viewer.