Support » Plugin: Block Visibility — Conditional Visibility Control for the Block Editor » Visibility not working on Custom Post Types

  • Resolved Chandra M

    (@nhuja)


    Hi,

    I have a WP Event Manager plugin and I am trying to set visibility of a paragraph to just logged in users but its not working. I do see the settings and I can set it to logged in users only but when I view the page in incognito or another browser which is not logged in, I see the block as it is. It does seem to work on Pages and Posts but maybe not in Custom Post Types? Anything I am missing? I checked the settings but I didn’t see anything about CPT there, All the blocks seems to be checked under Block Manager settings. Please guide.

    Even if we do the hide block toggle, it still shows so something is not working.

    EDIT: It looks like it works with other CPT. Looks like this is specific to WP Event Manager Plugin. If you can check it, that would be great.

    Thanks,
    Chandra

    • This topic was modified 4 months, 3 weeks ago by Chandra M.
    • This topic was modified 4 months, 3 weeks ago by Chandra M.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Chandra M

    (@nhuja)

    Ok after digging further on the WP Event Manager plugin I saw this code

    <?php echo apply_filters(‘display_event_description’, get_the_content()); ?>

    So, somehow the get_the_content() and the_content() seems to play the role here. If I use just the_content(), it seems to work but if I use echo get_the_content(), the visibility functions do not work.

    Any ideas?

    Thread Starter Chandra M

    (@nhuja)

    Ok, I just used this code in functions.php to get the actual content. Please let me know if you have better solution. Thanks.

    // show actual description on event listing for visibility block
    add_filter('display_event_description', 'my_get_content');
    function my_get_content() {
         return apply_filters('the_content', get_the_content());
    }
    • This reply was modified 4 months, 3 weeks ago by Chandra M.
    Plugin Author Nick Diego

    (@ndiego)

    Good morning Chandra,

    Thank you for your support ticket and identifying this. I will dig into this today and try to get a better explanation as to why this is happening. My guess is that it has something to do with the way get_the_content() and the_content() render blocks. All visibility controls are running through the render_block filter, which is the documented method of altering block content before the blocks are rendered. So perhaps it’s that get_the_content() is not actually rendering blocks the normal way?

    Anyway, I will look into this more today and see what I can find out.

    Best,
    Nick

    Plugin Author Nick Diego

    (@ndiego)

    After a bit more research:

    “An important difference from the_content() is that get_the_content() does not pass the content through the the_content filter. This means that get_the_content() will not auto-embed videos or expand shortcodes, among other things.” link

    I did see other articles mentioning the same issue when trying to render certain block content when only echoing get_the_content(). I appears you have the recommended solution, which is to pass it through the the_content filter. I will reach out to the WP Event Manager folks and see if they would entertain updating this. I am sure there are plenty of other block-related plugins that will have the same issues integrating.

    Since we have a solution, I am going to close out this ticket. But please let me know if you run into any additional issues!

    Best,
    Nick

    • This reply was modified 4 months, 3 weeks ago by Nick Diego.
    Thread Starter Chandra M

    (@nhuja)

    Yes, I tried another conditional blocks plugin and it behaved the same way so I figured it was coming from the WP Event Manager plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.