';
foreach ( $buttons as $slug => $button ) {
if ( isset( $button['show'] ) && ! $button['show'] ) {
continue;
}
echo '
' . $button['label'] . '';
}
echo '
';
}
/**
* Renders categorized row templates in the UI panel.
*
* @since 1.8
* @return void
*/
static public function render_ui_panel_row_templates()
{
$is_row_template = FLBuilderModel::is_post_user_template( 'row' );
$is_module_template = FLBuilderModel::is_post_user_template( 'module' );
$has_editing_cap = FLBuilderModel::current_user_has_editing_capability();
$row_templates = FLBuilderModel::get_row_templates_data();
if ( ! $is_row_template && ! $is_module_template && $has_editing_cap ) {
include FL_BUILDER_DIR . 'includes/ui-panel-row-templates.php';
}
}
/**
* Renders categorized module templates in the UI panel.
*
* @since 1.8
* @return void
*/
static public function render_ui_panel_modules_templates()
{
$is_module_template = FLBuilderModel::is_post_user_template( 'module' );
$has_editing_cap = FLBuilderModel::current_user_has_editing_capability();
$module_templates = FLBuilderModel::get_module_templates_data();
if ( ! $is_module_template && $has_editing_cap ) {
include FL_BUILDER_DIR . 'includes/ui-panel-module-templates.php';
}
}
/**
* Renders layouts using a new instance of WP_Query with the provided
* args and enqueues the necessary styles and scripts. We set the global
* $wp_query variable so the builder thinks we are in the loop when content
* is rendered without having to call query_posts.
*
* @link https://codex.wordpress.org/Class_Reference/WP_Query See for a complete list of args.
*
* @since 1.7
* @param array|string $args An array or string of args to be passed to a new instance of WP_Query.
* @param int $site_id The ID of a site on a network to pull the query from.
* @return void
*/
static public function render_query( $args, $site_id = null )
{
global $blog_id;
global $post;
global $wp_query;
// Pull from a site on the network?
if ( $site_id && is_multisite() ) {
$original_blog_id = $blog_id;
switch_to_blog( $site_id );
}
// Get the post and query.
$original_post = $post;
$wp_query = new WP_Query( $args );
$post_data = FLBuilderModel::get_post_data();
// Make sure the builder's render content filter is present.
add_filter( 'the_content', 'FLBuilder::render_content' );
// Unset the builder's post_data post ID so the global $post is used.
FLBuilderModel::update_post_data( 'post_id', null );
// Loop through the posts.
while ( $wp_query->have_posts() ) {
// Set the global post.
$wp_query->the_post();
// Make sure this isn't the same post as the original post to prevent infinite loops.
if ( is_object( $original_post ) && $original_post->ID === $post->ID ) {
continue;
}
// Enqueue styles and scripts for this post.
self::enqueue_layout_styles_scripts();
// Print the styles since we are outside of the head tag.
ob_start();
wp_print_styles();
echo ob_get_clean();
// Backup the main query in case it is overwritten in the_content().
$backup_query = $wp_query;
// Render the content.
the_content();
// Restore the main query in case it was overwritten.
$wp_query = $backup_query;
}
// Reset the post_id if we have one in $post_data.
if ( isset( $post_data['post_id'] ) ) {
FLBuilderModel::update_post_data( 'post_id', $post_data['post_id'] );
}
// Reset the global query.
wp_reset_query();
// Reset the site data?
if ( $site_id && is_multisite() ) {
switch_to_blog( $original_blog_id );
}
}
/**
* Renders the content for a builder layout while in the loop.
* This method should only be called by the_content filter as
* defined in fl-builder.php. To output builder content, use
* the_content function while in a WordPress loop.
*
* @since 1.0
* @param string $content The existing content.
* @return string
*/
static public function render_content( $content )
{
$post_id = FLBuilderModel::get_post_id();
$enabled = FLBuilderModel::is_builder_enabled();
$rendering = $post_id === self::$post_rendering;
$in_loop = in_the_loop();
$is_global = in_array( $post_id, FLBuilderModel::get_global_posts() );
if( $enabled && ! $rendering && ( $in_loop || $is_global ) ) {
// Set the post rendering ID.
self::$post_rendering = $post_id;
// Remove the builder's render_content filter so it's not called again.
remove_filter( 'the_content', 'FLBuilder::render_content' );
// Render the content.
ob_start();
do_action( 'fl_builder_before_render_content', $content );
echo '