Make WordPress Core


Ignore:
Timestamp:
11/12/2021 03:53:18 AM (3 years ago)
Author:
noisysocks
Message:

Editor: Add Navigation Area infrastructure

Copies Navigation Area infrastrucutre from lib/navigation.php in Gutenberg. This
allows a Navigation block to be associated with a particular area which persists
when switching theme.

Props antonvlasenko, mamaduka, spacedmonkey.
See #54337.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r52141 r52145  
    24482448    do_action( 'block_editor_meta_box_hidden_fields', $post );
    24492449}
     2450
     2451/**
     2452 * Disable block editor for wp_navigation type posts so they can be managed via the UI.
     2453 *
     2454 * @since 5.9.0
     2455 * @access private
     2456 *
     2457 * @param bool   $value Whether the CPT supports block editor or not.
     2458 * @param string $post_type Post type.
     2459 *
     2460 * @return bool
     2461 */
     2462function _disable_block_editor_for_navigation_post_type( $value, $post_type ) {
     2463    if ( 'wp_navigation' === $post_type ) {
     2464        return false;
     2465    }
     2466
     2467    return $value;
     2468}
     2469
     2470/**
     2471 * This callback disables the content editor for wp_navigation type posts.
     2472 * Content editor cannot handle wp_navigation type posts correctly.
     2473 * We cannot disable the "editor" feature in the wp_navigation's CPT definition
     2474 * because it disables the ability to save navigation blocks via REST API.
     2475 *
     2476 * @since 5.9.0
     2477 * @access private
     2478 *
     2479 * @param WP_Post $post An instance of WP_Post class.
     2480 */
     2481function _disable_content_editor_for_navigation_post_type( $post ) {
     2482    $post_type = get_post_type( $post );
     2483    if ( 'wp_navigation' !== $post_type ) {
     2484        return;
     2485    }
     2486
     2487    remove_post_type_support( $post_type, 'editor' );
     2488}
     2489
     2490/**
     2491 * This callback enables content editor for wp_navigation type posts.
     2492 * We need to enable it back because we disable it to hide
     2493 * the content editor for wp_navigation type posts.
     2494 *
     2495 * @since 5.9.0
     2496 * @access private
     2497 *
     2498 * @see _disable_content_editor_for_navigation_post_type
     2499 *
     2500 * @param WP_Post $post An instance of WP_Post class.
     2501 */
     2502function _enable_content_editor_for_navigation_post_type( $post ) {
     2503    $post_type = get_post_type( $post );
     2504    if ( 'wp_navigation' !== $post_type ) {
     2505        return;
     2506    }
     2507
     2508    add_post_type_support( $post_type, 'editor' );
     2509}
Note: See TracChangeset for help on using the changeset viewer.