wpdreams / ajax-search-pro-development

Issues and dev tracking repository for Ajax Search Pro for WordPress plugin
0 stars 0 forks source link

Block Editor - Blocks should be only available on selected post types (as defined on compatibility settings) #120

Closed ernestmarcinko closed 1 month ago

ernestmarcinko commented 1 month ago

Similarly to the classic editor (tinyMCE) the block editor blocks should respect the meta box on post editor screen options.

Subsequentily that option should be renamed accordingly as well as added some descriptions on exactly what it disables.

Take the check from the buttons.php:

    public function load(): void {
        $post_types     = wd_asp()->o['asp_compatibility']['meta_box_post_types']; // Allow only for selected post types
        $post_types     = explode('|', $post_types);
        $current_screen = get_current_screen();

        if ( is_null($current_screen) || is_wp_error($current_screen) ) {
            return;
        }

        if ( in_array( $current_screen->post_type, $post_types, true ) ) {
            add_action( 'admin_head', array( $this, 'addMceVariables' ), 999 );
            add_filter( 'mce_external_plugins', array( $this, 'addMceScript' ) );
            add_filter( 'mce_buttons', array( $this, 'addMceButton' ) );
        }
    }

Possibly make a shouldLoad() function on SearchBlocks.php - but be careful about get_current_screen(), it may not exist, as well as if the site editor is active.

ernestmarcinko commented 1 month ago

This can be adjusted on the block editor itself, so no need for an additional implementation now.