parsing nested blocks (in columns, etc) via PHP

If I understand it correctly, you can use a recursive function which loops through inner blocks to find the specific block. Example: /* Sample usage, assuming $post is defined properly: $blocks = parse_blocks( $post->post_content ); wpse_387661( $blocks ); */ function wpse_387661( $blocks ) { foreach ( $blocks as $block ) { if ( ! empty( … Read more

Style Gutenberg Editor based on Post Type or Page Template

Natively, no, not yet. I did find this helper plugin (and your question!) while searching for the same thing though: https://github.com/bigboxwc/wp-editor-page-template-class Clever JS based solution, it uses the Gutenberg Plugins API and props.selectedTemplate to generate a classname and add it to the editor. You could easily use the code from this plugin in your own … Read more

Weird failing request

Can you help me identify what the problem is and how can I prevent this? Where is this request coming from? The shortcode is only processed on the frontend. As far as the block editor is concerned the URL specified is [picsum] which is an unprocessed shortcode. There is no simple fix to this, and … Read more

How to keep the capability of users and disable Gutenberg editor in WordPress?

add these lines in your ‘functions.php’, it will work //if not gutenberg reapprove posts add_filter( ‘wp_insert_post_data’, ‘re_aprove’, ’99’, 2 ); function re_aprove( $data, $postarr ) { //check if current user is not admin if ( ! current_user_can( ‘manage_options’ ) ) { if ( ‘publish’ === $data[‘post_status’] ) { $data[‘post_status’] = ‘pending’; } } return $data; … Read more

How to find out whether a plugin is used in pages or posts?

You are looking for: is_plugin_active( string $plugin ) This function takes a string parameter that is the representation of the path to the plugin relative path in the plugins directory. So your practical implementation would look something like this: <?php if(is_plugin_active(‘elementor/elementor.php’) || is_plugin_active(‘woocommerce/woocommerce.php’)){ // Do something, remove scripts etc.. }

Remove WooCommerce block styles

The dequeue handle is incorrect it should be wp_dequeue_style(‘wc-block-style’); and not wp_dequeue_style(‘wc-block-style-css’); A bit confusing at first i agree, every js and css that was enqued via wp_enqueue_style or wp_enqueue_script gets a suffix of css/js Example wp_enqueue_style(‘swiper’, ‘https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.4.6/css/swiper.min.css’) This will create a <link> with an id attribute of swiper-css, im guessing this is why you … Read more