/** * Styles are loaded in preview in the page so they can be modified with JS. * If we need to clear a style, the rule and/or property will be deleted from the inline style. * * @since 1.0.0 */ function render_preview_style() { $css = ''; if (!function_exists('WP_Filesystem')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); global $wp_filesystem; // Get stylesheet based in global styling, templates, template parts and custom CSS. $css = TF_Model::get_style_preview(); if (!empty($css)) { echo $css; } }
/** * Update Template Part region. * * @since 1.0.0 * @access public * @return json */ public function builder_update_template_part() { // Check ajax referer check_ajax_referer($this->action_nonce, $this->field_nonce); global $TF_Layout, $tf_editor_ui; $temp_layout = $TF_Layout; $template_id = intval($_POST['template_part_id']); $parent_template_id = intval($_POST['parent_template_id']); $parent_post = get_post($parent_template_id); $template_part = get_post($template_id); $region = sanitize_text_field($_POST['region']); $shortcode = sprintf('[%s id="%d"]', 'tf_template_part', $template_id); $edit_url = add_query_arg(array('tf' => true, 'iframe' => true, 'tf_region' => $region), get_permalink($template_id)); // Setup Layout $TF_Layout->setup_layout($parent_post); $css = TF_Model::get_style_preview(); if (!empty($css)) { $css = '<style id="tf-style-preview">' . $css . '</style>'; } $tf_editor_ui->force_read_shortcode(); // Apply filters shortcode_atts $data = array('region' => $region, 'html' => do_shortcode($shortcode), 'shortcode' => $shortcode, 'edit_url' => $edit_url, 'caption' => sprintf(__('Template Part: %s', 'themify-flow'), esc_html($template_part->post_title)), 'styles' => $css); $TF_Layout = $temp_layout; wp_send_json_success($data); }