コード例 #1
1
 /**
  * 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
  */
 public static function render_content($content)
 {
     $post_id = FLBuilderModel::get_post_id();
     $enabled = FLBuilderModel::is_builder_enabled();
     $rendering = $post_id === self::$post_rendering;
     $ajax = defined('DOING_AJAX');
     $in_loop = in_the_loop();
     $is_global = in_array($post_id, FLBuilderModel::get_global_posts());
     if ($enabled && !$rendering && !$ajax && ($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();
         echo '<div class="' . self::render_content_classes() . '" data-post-id="' . $post_id . '">';
         self::render_nodes();
         echo '</div>';
         $content = ob_get_clean();
         // Reapply the builder's render_content filter.
         add_filter('the_content', 'FLBuilder::render_content');
         // Do shortcodes here since letting the WP filter run can cause an infinite loop.
         $pattern = get_shortcode_regex();
         $content = preg_replace_callback("/{$pattern}/s", 'FLBuilder::double_escape_shortcodes', $content);
         $content = do_shortcode($content);
         // Add srcset attrs to images with the class wp-image-<ID>.
         if (function_exists('wp_make_content_images_responsive')) {
             $content = wp_make_content_images_responsive($content);
         }
         // Clear the post rendering ID.
         self::$post_rendering = null;
     }
     return $content;
 }
コード例 #2
0
 /**
  * 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
  */
 public static function render_content($content)
 {
     global $wp_filter;
     $post_id = FLBuilderModel::get_post_id();
     $enabled = FLBuilderModel::is_builder_enabled();
     $rendering = $post_id === self::$post_rendering;
     $ajax = defined('DOING_AJAX');
     $in_loop = in_the_loop();
     $is_global = in_array($post_id, FLBuilderModel::get_global_posts());
     if ($enabled && !$rendering && !$ajax && ($in_loop || $is_global)) {
         // Store this post ID so we know it is currently being rendered
         // in case another method or function calls apply filters on the
         // content after this method has run which creates an infinite loop.
         self::$post_rendering = $post_id;
         // Store a reference to the current the_content filters array since
         // any modules or widgets that call apply_filters on the_content cause
         // the array pointer to move to the end. That makes it so the builder
         // content doesn't receive filters after this method runs as it should.
         $filters = $wp_filter['the_content'];
         // Remove the builder's render_content filter so it's not called again
         // by modules or widgets that call apply_filters on the content.
         remove_filter('the_content', 'FLBuilder::render_content');
         // Render the content.
         ob_start();
         echo '<div class="fl-builder-content fl-builder-content-' . $post_id . '" data-post-id="' . $post_id . '">';
         self::render_rows();
         echo '</div>';
         $content = ob_get_clean();
         // Restore the original the_content filters array.
         $wp_filter['the_content'] = $filters;
     }
     return $content;
 }