PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / trunk
Gutenify – Visual Site Builder Blocks & Starter Templates vtrunk
1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 All 72 releases
gutenify / core / inc / blocks / class-editor-control.php

class-editor-control.php in Gutenify – Visual Site Builder Blocks & Starter Templates trunk, at core/inc/blocks/class-editor-control.php

81 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Editor control actions.
4 *
5 * Controls the use of the Gutenberg editor based on post type.
6 *
7 * @package Gutenify
8 */
9
10 namespace gutenify;
11
12 // Prevent direct file access.
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Class Editor_Control
17 *
18 * Handles logic for enabling or disabling the Gutenberg editor for specific post types.
19 */
20 class Editor_Control {
21
22 /**
23 * Constructor registers action and filter hooks.
24 */
25 public function __construct() {
26 // Conditionally disable Gutenberg editor.
27 add_action( 'use_block_editor_for_post_type', array( $this, 'disable_gutenberg' ), 10, 2 );
28
29 // Register post types that should skip Gutenberg check.
30 add_filter( 'gutenify_skip_gutenburg_post_type', array( $this, 'skip_gutenburg_post_type' ) );
31 }
32
33 /**
34 * Conditionally disables Gutenberg for post types not in the allowed list.
35 *
36 * @param bool $is_enabled Whether Gutenberg is enabled.
37 * @param string $post_type Current post type.
38 * @return bool Modified Gutenberg enablement flag.
39 */
40 public function disable_gutenberg( $is_enabled, $post_type ) {
41 $filter_name = 'gutenify_skip_gutenburg_post_type';
42 $skip_gutenburg = apply_filters( $filter_name, array() );
43
44 // Skip logic if post type is explicitly excluded.
45 if ( ! in_array( $post_type, $skip_gutenburg, true ) ) {
46 $settings = gutenify_settings();
47
48 // Fetch allowed post types from settings.
49 $active_post_types = ! empty( $settings['active_post_types'] ) ? $settings['active_post_types'] : array();
50
51 // Disable Gutenberg if post type is not active.
52 if ( ! in_array( $post_type, $active_post_types, true ) ) {
53 return false;
54 }
55 }
56
57 // Return the original Gutenberg flag if conditions aren't met.
58 return $is_enabled;
59 }
60
61 /**
62 * Appends specific post types that should bypass Gutenberg editor control logic.
63 *
64 * @param array $post_types Post types already excluded.
65 * @return array Updated list of excluded post types.
66 */
67 public function skip_gutenburg_post_type( $post_types ) {
68 // Add built-in and custom post types to skip list.
69 $skip_types = array(
70 'attachment',
71 'wp_template',
72 'wp_block',
73 'gutenify_template',
74 );
75 return array_merge( $post_types, $skip_types );
76 }
77 }
78
79 // Initialize the class.
80 new Editor_Control();
81