/** * 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); }
/** * Unset unwanted key. * * @since 1.0.0 * @param array &$array * @param string $unwanted_key * @return array */ function tf_recursive_unset(&$array, $unwanted_key) { if (isset($array[$unwanted_key])) { unset($array[$unwanted_key]); } foreach ($array as &$value) { if (is_array($value)) { tf_recursive_unset($value, $unwanted_key); } } }