Plugin loading page.php directly (skipping base.php)

I’m using beaver builder (a page builder plugin) which has mostly been fine. But there’s one situation in which beaver builder loads page.php directly - without base.php ever being called. And so, in that situation the page obviously isn’t being setup correctly.

This is getting beyond my understanding of WordPress - so apologies if I’m not describing this correctly. But here’s what I’ve been able to trace.

The plugin calls:

$page = locate_template( array( ‘page.php’ ) );

locate_template() (a core wordpress function) returns the full path to page.php

And then page.php gets loaded without base.php ever loading

My theme is based off of version 9 (I believe alpha 4 - I don’t have any of the blade stuff)

Is there any way I can somehow bypass or detect this to push it through base.php instead? Without having to modify wordpress core (locate_template() is in wordpress core) or the plugin?

Thanks!
Abby

What’s different about this page that makes it skip the wrapper?

How can we re-produce the issue?

Ack! Sorry I didn’t get the email showing that you’d responded, will double check my settings.

The plugin is calling locate_template( array( ‘page.php’ ) );
– which is a core WordPress function that returns the full path to page.php
So then page.php gets loaded without base.php ever loading

As far as I can tell, sage’s code is never even being called in this execution. Is there a way for me to get a stacktrace of what functions are called?

I’m not sure what the correct behavior should be, ie…,

  • is it wrong that they’re calling locate_template on page.php directly? OR
  • is it wrong that sage isn’t able to intercept that call to route it to base.php?

Thanks!
Abby

I took a quick look at the plugin you’re using. Looks like you can hook into fl_builder_template_path. I believe something like this would work…

add_filter('fl_builder_template_path', function ($main) {
    return ((new Template(new Wrapper($main)))->layout());
});

See also:

1 Like

Hmm, no luck. It still loads page.php before anything - before it even gets into that hook.

But then the hook seems to cause some weird recursive thing where base.php gets called 7 times (all on that one webpage).

Any other ideas what I might try?

Thanks!!

bump

Working on a new website where this is actually causing a real problem so thought I’d bump - any ideas what else I can try to get this to work? Thanks so much!!

I think I owe you an apology!

I tried once more and I wish I could say I knew what was different but it is working now. Thank you thank you thank you!

Ok, I think I’ve finally got it working right. Here’s what I’ve got in case anyone else is having this same issue with Beaver Builder.

function isTemplateBuilderPage(){
  global $post;

  return ( $post && $post->post_type == 'fl-builder-template' );
}

add_filter( 'template_include', function( $main ){
  if( isTemplateBuilderPage() ){
    // force page builder for templates to go through Sage's base template
    return ( ( new Template( new Wrapper( $main ) ) )->layout() );
  }

  return $main;
}, 1000 ); // 1000 to come after/override page builder functionality

Note that I’m not using fl_builder_template_path filter.