Hi Oliver,
The method FLBuilderModel::is_builder_enabled() will only work for the current post. Instead, you might try querying the meta for that directly like so…
get_post_meta( $post_id, '_fl_builder_enabled', true );
Let me know how that goes.
Justin
Cool, Justin!
Thanks for fast reply too!
Will this work also when the post is in draft mode?
Well, anyway, I’ll try… 😉
Well, this doesn’t work with drafts… Any ideas how to get around this are much appreciated.
(*) Just a tip for others: To be able to use the loop functions (such as is_singular() or the above mentioned get_post_meta()) with Beaver Builder custom modules registration, hook onto the wp action, not the init.
OK, got a solution.
To determine if the Beaver Builder is enabled or in use (which means editing a post draft) apply this condition:
if (
class_exists( 'FLBuilder' )
&& ! is_admin()
&& is_singular( (array) get_option( '_fl_builder_post_types' ) )
&& (
get_post_meta( get_the_ID(), '_fl_builder_enabled', true )
|| isset( $_GET['fl_builder'] )
)
) {
//Beaver Builder is active, do the stuff...
}
(*) Don’t forget to hook into wp.
Regards,
Oliver
…sorry for false alarm. The above will actually work in wp hook, but it’s useless as this triggers errors in builder due to modules not being properly hooked in init action.
So, my proposition for plugin developers would be to load the plugin (and its modules) for the pages/posts that actually use it only.
Currently when I add a custom module, its files are being loaded all the time even on post types that were removed from Beaver Builder support and even on archive and search pages! Could this be taken care of to remove excess load?
Thank you!
Currently when I add a custom module, its files are being loaded all the time even on post types that were removed from Beaver Builder support and even on archive and search pages! Could this be taken care of to remove excess load?
That’s a great suggestion. I’ll look into adding some logic for that later this month when I’m back on dev for this.
In the meantime, since the post meta doesn’t work for draft builder layouts that aren’t published yet, you might try combining that with FLBuilderModel::is_builder_active.
Justin
Thanks Justin!
Unfortunately, nothing works for me. FLBuilderModel solution works in admin for me. However, as the custom modules are being hooked onto init action hook, there are no loop functions available for it, so I can not use get_post_meta, is_singular() and others.
When I try to hook to wp action hook, where I could use those functions to determine whether to include my custom modules or not, I can not use Beaver Builder module forms as they throw errors of not defined variables/classes.
So, I left it as it is for now and looking forward to the update! 😉