EnlighterJS / Plugin.Gutenberg

:pencil: Official EnlighterJS Plugin for WordPress Gutenberg Editor
Mozilla Public License 2.0
20 stars 1 forks source link

Knowing if EnlighterJS is used on page? #40

Closed robbelroot closed 1 year ago

robbelroot commented 1 year ago

Hey guys,

I wanted to know, if there is any kind of possibility, to know if a gutenberg enlighter block is used on a page?

I tried finding out, which blocks/shortcodes you've defined, but had no success, I tried like:

global $post;
  // has_shortcode($post->post_content, 'enlighter')
  if (is_a($post, 'WP_POST') && has_block('enlighter-gutenberg', $post)) {
    echo 'true!';
  } else {
    echo 'nope';
  }

Any tips for me?

EDIT: Just when I was about to give up, I found the code block name inside the html and got it to work: enlighter/codeblock

Feel free to delete this..

AndiDittrich commented 1 year ago

has_blocks should work fine using the correct block names - see https://github.com/EnlighterJS/Plugin.Gutenberg/blob/master/src/EnlighterJS.Gutenberg.js

btw. this only work for Gutenberg content - other content types (transform filters, shortcodes, tinymce, ...) won't be detected. Maybe the js code of the DRI detection may help