/** * Load a section template with an available data payload for use in the template. * * @since 1.0.0. * * @param string $section The section data. * @param array $data The data payload to inject into the section. * @return void */ public function load_section($section, $data = array()) { if (!isset($section['id'])) { return; } // Globalize the data to provide access within the template global $ttfmake_section_data; $ttfmake_section_data = array('data' => $data, 'section' => $section); // Include the template ttfmake_load_section_template($ttfmake_section_data['section']['builder_template'], $ttfmake_section_data['section']['path']); // Destroy the variable as a good citizen does unset($GLOBALS['ttfmake_section_data']); }
/** * Based on section data, generate a post's post_content. * * @since 1.0.4. * * @param array $data Data for sections used to comprise a page's post_content. * @return string The post content. */ public function generate_post_content($data) { // Run wpautop when saving the data add_filter('make_the_builder_content', 'wpautop'); // Handle oEmbeds correctly add_filter('make_the_builder_content', array($this, 'embed_handling'), 8); add_filter('embed_handler_html', array($this, 'embed_handler_html'), 10, 3); add_filter('embed_oembed_html', array($this, 'embed_oembed_html'), 10, 4); // Remove editor image constraints while rendering section data. add_filter('editor_max_image_size', array(&$this, 'remove_image_constraints')); // Start the output buffer to collect the contents of the templates ob_start(); // For each sections, render it using the template foreach ($data as $section) { global $ttfmake_section_data, $ttfmake_sections; $ttfmake_section_data = $section; $ttfmake_sections = $data; // Get the registered sections $registered_sections = ttfmake_get_sections(); // Get the template for the section ttfmake_load_section_template($registered_sections[$section['section-type']]['display_template'], $registered_sections[$section['section-type']]['path']); // Cleanup the global unset($GLOBALS['ttfmake_section_data']); } // Get the rendered templates from the output buffer $post_content = ob_get_clean(); // Allow constraints again after builder data processing is complete. remove_filter('editor_max_image_size', array(&$this, 'remove_image_constraints')); /** * Filter the generated post content. * * This content is the full HTML version of the content that will be saved as "post_content". * * @since 1.2.3. * * @param string $post_content The fully generated post content. * @param array $data The data used to generate the content. */ return apply_filters('make_generate_post_content', $post_content, $data); }