Example #1
0
/**
 * Boots Frond End Builder App,
 *
 * @return Front End Builder wrap if main query, $content otherwise.
 */
function et_fb_app_boot($content)
{
    // Don't boot the app if the builder is not in use
    if (!et_pb_is_pagebuilder_used(get_the_ID())) {
        return $content;
    }
    $class = apply_filters('et_fb_app_preloader_class', 'et-fb-page-preloading');
    if ('' !== $class) {
        $class = sprintf(' class="%1$s"', esc_attr($class));
    }
    // Only return React app wrapper once for the main query.
    if (is_main_query()) {
        return sprintf('<div id="et-fb-app"%1$s></div>', $class);
    }
    // Stop shortcode object processor so that shortcode in the content are treated normaly.
    et_fb_reset_shortcode_object_processing();
    return $content;
}
Example #2
0
function et_fb_process_shortcode($content, $parent_address = '', $global_parent = '', $global_parent_type = '')
{
    global $shortcode_tags;
    if (false === strpos($content, '[')) {
        return $content;
    }
    // Find all registered tag names in $content.
    preg_match_all('@\\[([^<>&/\\[\\]\\x00-\\x20=]++)@', $content, $matches);
    $tagnames = array_intersect(array_keys($shortcode_tags), $matches[1]);
    $pattern = get_shortcode_regex($tagnames);
    $content = preg_match_all("/{$pattern}/", $content, $matches, PREG_SET_ORDER);
    $_matches = array();
    $_index = 0;
    foreach ($matches as $match) {
        $tag = $match[2];
        // reset global parent data to calculate it correctly for next modules
        if ($global_parent_type === $tag && '' !== $global_parent) {
            $global_parent = '';
            $global_parent_type = '';
        }
        $attr = shortcode_parse_atts($match[3]);
        $index = $_index++;
        $address = isset($parent_address) && '' !== $parent_address ? (string) $parent_address . '.' . (string) $index : (string) $index;
        // set global parent and global parent tag if current module is global and can be a parent
        $possible_global_parents = array('et_pb_section', 'et_pb_row', 'et_pb_row_inner');
        if ('' === $global_parent && in_array($tag, $possible_global_parents)) {
            $global_parent = isset($attr['global_module']) ? $attr['global_module'] : '';
            $global_parent_type = $tag;
        }
        $attr['_i'] = $index;
        $attr['_address'] = $address;
        // Flag that the shortcode object is being built.
        $GLOBALS['et_fb_processing_shortcode_object'] = true;
        if (isset($match[5])) {
            // enclosing tag - extra parameter
            // do not process rows without columns
            if (!(in_array($tag, array('et_pb_row', 'et_pb_row_inner')) && empty($match[5]))) {
                $output = call_user_func($shortcode_tags[$tag], $attr, $match[5], $tag, $parent_address, $global_parent, $global_parent_type);
            }
        } else {
            // self-closing tag
            $output = call_user_func($shortcode_tags[$tag], $attr, null, $tag);
        }
        // if row doesn't contain any columns then put an empty value instead of array
        if (in_array($tag, array('et_pb_row', 'et_pb_row_inner')) && empty($match[5])) {
            $_matches = '';
        } else {
            $_matches[] = $output;
        }
    }
    // Turn off the flag since the shortcode object is done being built.
    et_fb_reset_shortcode_object_processing();
    return $_matches;
}