public function save() { $template_name = vc_post_param( 'template_name' ); $template = vc_post_param( 'template' ); if ( ! isset( $template_name ) || $template_name == "" || ! isset( $template ) || $template == "" ) { echo 'Error: TPL-01'; die(); } $template_arr = array( "name" => stripslashes( $template_name ), "template" => stripslashes( $template ) ); $option_name = 'wpb_js_templates'; $saved_templates = get_option( $option_name ); $template_id = sanitize_title( $template_name ) . "_" . rand(); if ( $saved_templates == false ) { $deprecated = ''; $autoload = 'no'; // $new_template = array(); $new_template[$template_id] = $template_arr; // add_option( $option_name, $new_template, $deprecated, $autoload ); } else { $saved_templates[$template_id] = $template_arr; update_option( $option_name, $saved_templates ); } echo vc_backend_editor()->getLayout()->getNavBar()->getTemplateMenu( true ); //delete_option('wpb_js_templates'); die(); }
/** * Set default content by post type in editor. * * Data for post type templates stored in settings. * * @param $post_content * @param $post * @since 4.12 * * @return null */ function vc_set_default_content_for_post_type($post_content, $post) { if (!empty($post_content) || !vc_backend_editor()->isValidPostType($post->post_type)) { return $post_content; } $template_settings = new Vc_Setting_Post_Type_Default_Template_Field('general', 'default_template_post_type'); if (($new_post_content = $template_settings->getTemplateByPostType($post->post_type)) !== null) { add_filter('wpb_vc_js_status_filter', 'vc_set_default_content_for_post_type_wpb_vc_js_status_filter'); return $new_post_content; } return $post_content; }
/** * Load required logic for operating in Wp Admin dashboard. * * @since 4.2 * @access protected * * @return void */ protected function asAdmin() { vc_license()->init(); vc_backend_editor()->addHooksSettings(); }
/** * Load required logic for operating in Wp Admin dashboard. * * @since 4.2 * @access protected * @return void */ protected function asAdmin() { // License management and activation/deactivation methods. vc_license()->addAjaxHooks(); // Settings page. Adds menu page in admin panel. vc_settings()->addMenuPageHooks(); // Load backend editor hooks vc_backend_editor()->addHooksSettings(); // If auto updater is enabled initialize updating notifications service. }
public function contentAdmin($atts, $content = null) { $width = $el_class = $title = ''; extract(shortcode_atts($this->predefined_atts, $atts)); $output = ''; $column_controls = $this->getColumnControls($this->settings('controls')); $column_controls_bottom = $this->getColumnControls('add', 'bottom-controls'); if ($width == 'column_14' || $width == '1/4') { $width = array('vc_span3'); } else { if ($width == 'column_14-14-14-14') { $width = array('vc_span3', 'vc_span3', 'vc_span3', 'vc_span3'); } else { if ($width == 'column_13' || $width == '1/3') { $width = array('vc_span4'); } else { if ($width == 'column_13-23') { $width = array('vc_span4', 'vc_span8'); } else { if ($width == 'column_13-13-13') { $width = array('vc_span4', 'vc_span4', 'vc_span4'); } else { if ($width == 'column_12' || $width == '1/2') { $width = array('vc_span6'); } else { if ($width == 'column_12-12') { $width = array('vc_span6', 'vc_span6'); } else { if ($width == 'column_23' || $width == '2/3') { $width = array('vc_span8'); } else { if ($width == 'column_34' || $width == '3/4') { $width = array('vc_span9'); } else { if ($width == 'column_16' || $width == '1/6') { $width = array('vc_span2'); } else { $width = array(''); } } } } } } } } } } for ($i = 0; $i < count($width); $i++) { $output .= '<div class="group wpb_sortable">'; $output .= '<h3><span class="tab-label"><%= params.title %></span></h3>'; $output .= '<div ' . $this->mainHtmlBlockParams($width, $i) . '>'; $output .= str_replace("%column_size%", wpb_translateColumnWidthToFractional($width[$i]), $column_controls); $output .= '<div class="wpb_element_wrapper">'; $output .= '<div ' . $this->containerHtmlBlockParams($width, $i) . '>'; $output .= do_shortcode(shortcode_unautop($content)); $output .= vc_backend_editor()->getLayout()->getContainerHelper(); $output .= '</div>'; if (isset($this->settings['params'])) { $inner = ''; foreach ($this->settings['params'] as $param) { $param_value = isset(${$param}['param_name']) ? ${$param}['param_name'] : ''; if (is_array($param_value)) { // Get first element from the array reset($param_value); $first_key = key($param_value); $param_value = $param_value[$first_key]; } $inner .= $this->singleParamHtmlHolder($param, $param_value); } $output .= $inner; } $output .= '</div>'; $output .= str_replace("%column_size%", wpb_translateColumnWidthToFractional($width[$i]), $column_controls_bottom); $output .= '</div>'; $output .= '</div>'; } return $output; }
<?php if (!defined('ABSPATH')) { die('-1'); } add_action('admin_enqueue_scripts', array(vc_backend_editor(), 'enqueueEditorScripts')); add_action('admin_enqueue_scripts', array(visual_composer()->templatesPanelEditor(), 'enqueuePreviewScripts')); add_filter('admin_body_class', array(visual_composer()->templatesPanelEditor(), 'addBodyClassTemplatePreview')); do_action('vc-render-templates-preview-template'); global $menu, $submenu, $parent_file, $post_ID, $post, $post_type; $post_ID = $editorPost->ID; $post_type = $editorPost->post_type; $post_title = trim($editorPost->post_title); $nonce_action = $nonce_action = 'update-post_' . $post_ID; $user_ID = isset($current_user) && isset($current_user->ID) ? (int) $current_user->ID : 0; $form_action = 'editpost'; $menu = array(); remove_action('wp_head', 'print_emoji_detection_script'); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('admin_print_styles', 'print_emoji_styles'); add_thickbox(); wp_enqueue_script('vc_editors-templates-preview-js'); wp_enqueue_media(array('post' => $post_ID)); require_once ABSPATH . 'wp-admin/admin-header.php'; ?> <style type="text/css"> #screen-meta, #adminmenumain, .notice { display: none !important; }
/** * Enqueue required scripts for template preview * @since 4.8 */ public function enqueuePreviewScripts() { vc_backend_editor()->enqueueCss(); vc_backend_editor()->enqueueJs(); wp_enqueue_script('vc_editors-templates-preview-js'); }