<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Living alongside Gutenberg.
 *
 * Gutenberg stays ACTIVE on the site: it is switched off only on the individual pieces of content
 * that belong to Aura (see {@see AIPB_Ownership}). On those the block editor never opens — Aura's
 * entities (sections, patterns, templates) go to the Studio through
 * AIPB_Admin::maybe_redirect_to_studio, while pages and posts open in the classic screen with no
 * content area (AIPB_Admin::hide_editor_for_aura).
 *
 * The 'editor' support is NOT removed from the post types any more: that is a global setting, and
 * it cannot express a choice made page by page.
 *
 * Front-end assets are governed by {@see AIPB_Assets}, which drops Gutenberg's styles and the
 * theme's together on Aura's pages.
 */
class AIPB_Gutenberg {

	public static function init() {
		add_filter( 'use_block_editor_for_post', array( __CLASS__, 'gate_block_editor' ), 100, 2 );
	}

	/**
	 * @param bool    $use  WordPress's current decision.
	 * @param WP_Post $post The content being opened.
	 */
	public static function gate_block_editor( $use, $post ) {
		return ( $post && AIPB_Ownership::is_aura( $post->ID ) ) ? false : $use;
	}
}
