title = esc_attr__( 'Shortcode Mapper', 'js_composer' ); } /** * */ public function addAjaxActions() { add_action( 'wp_ajax_vc_automapper_create', array( $this, 'create', ) ); add_action( 'wp_ajax_vc_automapper_read', array( $this, 'read', ) ); add_action( 'wp_ajax_vc_automapper_update', array( $this, 'update', ) ); add_action( 'wp_ajax_vc_automapper_delete', array( $this, 'delete', ) ); return $this; } /** * Builds html for Automapper CRUD like administration block * * @return bool */ public function renderHtml() { if ( $this->disabled() ) { return false; } ?>

renderTemplates(); ?> ', esc_html( $shortcode->name ), esc_attr( $shortcode->id ), esc_attr( $shortcode->tag ), esc_attr( $shortcode->id ), esc_attr( $shortcode->tag ) ); } /** * */ public function renderMapFormTpl() { $custom_tag = 'script'; // Maybe use html shadow dom or ajax response for templates ?> < type="text/html" id="vc_automapper-add-form-tpl">
> < type="text/html" id="vc_automapper-item-complex-tpl">

{{ name }}

> < type="text/html" id="vc_automapper-form-tpl">
{{{ shortcode_preview }}}

+
> < type="text/html" id="vc_atm-form-param-tpl">
<# if ( 'content' === param_name) { #> <# } else { #> <# } #>
disabled="disabled" <# } #>>
> < type="text/html" id="vc_automapper-item-tpl"> > renderMapFormTpl(); } public function create() { if ( ! vc_request_param( '_vcnonce' ) ) { return; } vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'manage_options' )->validateDie()->part( 'settings' )->can( 'vc-automapper-tab' )->validateDie(); $data = vc_post_param( 'data' ); $shortcode = new Vc_Automap_Model( $data ); $this->result( $shortcode->save() ); } public function update() { if ( ! vc_request_param( '_vcnonce' ) ) { return; } vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'manage_options' )->validateDie()->part( 'settings' )->can( 'vc-automapper-tab' )->validateDie(); $id = (int) vc_post_param( 'id' ); $data = vc_post_param( 'data' ); $shortcode = new Vc_Automap_Model( $id ); if ( ! isset( $data['params'] ) ) { $data['params'] = array(); } $shortcode->set( $data ); $this->result( $shortcode->save() ); } public function delete() { if ( ! vc_request_param( '_vcnonce' ) ) { return; } vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'manage_options' )->validateDie()->part( 'settings' )->can( 'vc-automapper-tab' )->validateDie(); $id = vc_post_param( 'id' ); $shortcode = new Vc_Automap_Model( $id ); $this->result( $shortcode->delete() ); } public function read() { if ( ! vc_request_param( '_vcnonce' ) ) { return; } vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'manage_options' )->validateDie()->part( 'settings' )->can( 'vc-automapper-tab' )->validateDie(); $this->result( Vc_Automap_Model::findAll() ); } /** * Ajax result output * * @param $data */ public function result( $data ) { if ( false !== $data ) { wp_send_json_success( $data ); } else { wp_send_json_error( $data ); } } /** * Setter/Getter for Disabling Automapper * @static * * @param bool $disable */ public static function setDisabled( $disable = true ) { self::$disabled = $disable; } /** * @return bool */ public static function disabled() { return self::$disabled; } /** * Setter/Getter for Automapper title * * @static * * @param string $title */ public function setTitle( $title ) { $this->title = $title; } /** * @return string|void */ public function title() { return $this->title; } /** * */ public static function map() { $shortcodes = Vc_Automap_Model::findAll(); foreach ( $shortcodes as $shortcode ) { vc_map( array( 'name' => $shortcode->name, 'base' => $shortcode->tag, 'category' => vc_atm_build_categories_array( $shortcode->category ), 'description' => $shortcode->description, 'params' => vc_atm_build_params_array( $shortcode->params ), 'show_settings_on_create' => ! empty( $shortcode->params ), 'atm' => true, 'icon' => 'icon-wpb-atm', ) ); } } } }