Membership 2 Pro shortcodes not working correctly with Goodlayers page builder

If you place the [ms-protect-content id="4386"][/ms-protect-content] shortcodes in 2 different content sections of the GoodLayers page builder, they do not properly protect the content. The shortcodes will work if placed in the same content section, but not if split across 2 content sections. Given the needs of this client, placing the shortcodes in the same content section will not work.

  • Dimitris

    Hello Mark,

    hope you're doing good! :slight_smile:

    Shortcodes work by filtering the_content filter hook and each element filter the content separately. So the first element will filter the content and will recognise a shortcode and call the shortcode callback. Second element will not recognize any shortcode though, as it contains only the closing part, which is parsed as plain text.

    So if content has [some_shortcode] it will do do_shortcode( '[some_shortcode]' ), but if it has [\some_shortcode] it will do nothing.

    As a matter of proof and after reviewing GoodLayers page builder a bit, we can see that it prints the content with gdlr_core_content_filter() function. In this function it uses
    return apply_filters('gdlr_core_the_content', $content);

    So each element does
    add_filter( 'gdlr_core_the_content', 'gdlr_core_do_shortcode', 11 );
    which actually does: $content = do_shortcode($content);

    As you may understand, there's no workaround on this, unless we modify a plugin file. :slight_frown:
    This means that after any future plugin update of the page builder, you should re-making below change.

    In wp-content/plugins/goodlayers-core/framework/function/page-builder.php line 625, replace
    return $ret;
    return apply_filters( 'print_page_builder_item', $ret );

    Then in a new MU plugin file, like in wp-content/mu-plugins/page-builder-filter.php (just create the /mu-plugins/ folder, if it doesn't exist already), add:

    add_action( 'template_redirect', function(){
      global $post;
      if( ! $post instanceof WP_Post || 52 != $post->ID ) {
      remove_filter( 'gdlr_core_the_content', 'gdlr_core_do_shortcode', 11 );
      add_filter( 'print_page_builder_item', function($ret){
          return do_shortcode( $ret );
      } );
    } );

    Just replace 52 with the page ID in which you want to use Membership shortcodes in multiple elements. You can find the ID of a page, from browser's URL, whilst editing the page.

    Thank you,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.