/** * Save builder content data. * * @since 1.0.0 * @access public * @param int $post_id * @param array $post_data */ public function save_builder_content($post_id, $post_data) { $post_type = get_post_type($post_id); $reserved_post_types = array('tf_template', 'tf_template_part'); // Save to post_meta if (!in_array($post_type, $reserved_post_types)) { $post_content = TF_Model::array_to_shortcode($post_data['content']); update_post_meta($post_id, 'tf_builder_content', $post_content); } }
/** * Shortcode render. * * @since 1.0.0 * @access public * @return json */ public function shortcode_render() { // Check ajax referer check_ajax_referer($this->action_nonce, $this->field_nonce); $type = isset($_POST['type']) ? $_POST['type'] : ''; $method = isset($_POST['method']) ? $_POST['method'] : 'add'; $mode = isset($_POST['mode']) ? $_POST['mode'] : 'frontend'; $data = array(); switch ($method) { case 'duplicate': global $TF_Layout; if ('module' == $type) { global $tf_modules, $tf_styles; $module_instance = $tf_modules->get_module($_POST['module']); $atts = isset($_POST['shortcode_params']) ? $_POST['shortcode_params'] : ''; $content = isset($_POST['shortcode_content']) ? wp_kses_stripslashes($_POST['shortcode_content']) : ''; $template_id = (int) $_POST['template_id']; $data_styling = isset($_POST['data_styling']) ? json_decode(stripslashes($_POST['data_styling']), true) : array(); $styles = array(); $atts['sc_id'] = TF_Model::generate_block_id(); // generate new sc_id if (is_array($data_styling) && count($data_styling) > 0) { $data_styling['ID'] = $atts['sc_id']; $styles[$atts['sc_id']] = array('module' => $data_styling['module']); if (isset($data_styling['settings']) && count($data_styling['settings']) > 0) { foreach ($data_styling['settings'] as $fields) { $setting_key = ''; foreach ($fields as $key => $val) { if ('SettingKey' == $key) { $setting_key = $val; } else { $styles[$atts['sc_id']]['settings'][$setting_key][$key] = stripslashes_deep($val); } } } } } $render_style = ''; if (count($styles) > 0) { $render_style = '<style type="text/css" id="tf-template-temp-' . $atts['sc_id'] . '-css">' . $tf_styles->generate_css($styles) . '</style>'; } if (isset($atts['editable_markup'])) { unset($atts['editable_markup']); } if (get_magic_quotes_gpc()) { $atts = stripslashes_deep($atts); } $shortcode_string = $module_instance->to_shortcode($atts, $content); global $post; $post = get_post($template_id); setup_postdata($post); $shortcode = $TF_Layout->render($shortcode_string); $data = array('module' => sanitize_text_field($_POST['module']), 'content' => tf_escape_atts($content), 'atts' => $atts, 'caption' => $module_instance->name, 'element' => $shortcode, 'styles' => $render_style, 'model' => $data_styling); } else { if ('row' == $type) { global $tf_editor_ui; $row_data = isset($_POST['row_data']) ? stripslashes_deep($_POST['row_data']) : array(); tf_recursive_unset($row_data, 'sc_id'); tf_recursive_unset($row_data, 'editable_markup'); $shortcode = TF_Model::array_to_shortcode(array($row_data)); $tf_editor_ui->force_editable_shortcode($mode); $data = $TF_Layout->render($shortcode); } } break; } wp_send_json_success($data); }
/** * Fires when module form saved. * * @since 1.0.0 * @access public * @param array $post_data * @return json */ public function save_module_form($post_data) { global $tf_modules, $TF_Layout; $module_instance = $tf_modules->get_module($post_data['_module_name']); // Check if has builder if (isset($post_data['_has_builder']) && count($post_data['_has_builder']) > 0) { foreach ($post_data['_has_builder'] as $builder) { if (isset($post_data[$builder])) { if (get_magic_quotes_gpc()) { $string = stripslashes($post_data[$builder]); } else { $string = $post_data[$builder]; } $raw_data = json_decode($string, true); $post_data[$builder] = TF_Model::array_to_shortcode($raw_data); } } } elseif (isset($post_data['content']) && is_array($post_data['content'])) { // if "content" is sent as an array, serialize and save it as the content of the shortcode $post_data['content'] = serialize($post_data['content']); } $content = isset($post_data['content']) ? stripslashes($post_data['content']) : ''; $module_fields = $module_instance->get_fields(); $atts = $this->set_atts($module_fields, $post_data); if (isset($atts['content'])) { unset($atts['content']); } // set sc_id $atts['sc_id'] = $post_data['sc_id']; $shortcode_string = $module_instance->to_shortcode($atts, $content); global $post; $post = get_post($post_data['_template_id']); setup_postdata($post); $shortcode = $TF_Layout->render($shortcode_string); $data = array('module' => $post_data['_module_name'], 'content' => $content, 'atts' => $atts, 'caption' => $module_instance->name, 'element' => $shortcode); wp_send_json_success($data); }