loadOptionData(); $this->id = is_array( $d ) && isset( $d['id'] ) ? $d['id'] : $d; if ( is_array( $d ) ) $this->data = stripslashes_deep( $d ); foreach ( $this->vars as $var ) { $this->$var = $this->get( $var ); } } static function findAll() { self::loadOptionData(); $records = array(); foreach ( self::$option_data as $id => $record ) { $record['id'] = $id; $model = new Vc_Automap_Model( $record ); if ( $model ) $records[] = $model; } return $records; } final protected static function loadOptionData() { if ( is_null( self::$option_data ) ) self::$option_data = Configuration::get( self::$option_name ); if ( ! self::$option_data ) self::$option_data = array(); return self::$option_data; } function get( $key ) { if ( is_null( $this->data ) ) $this->data = isset( self::$option_data[$this->id] ) ? self::$option_data[$this->id] : array(); return isset( $this->data[$key] ) ? $this->data[$key] : null; } function set( $attr, $value = null ) { if ( is_array( $attr ) ) { foreach ( $attr as $key => $value ) { $this->set( $key, $value ); } } elseif ( ! is_null( $value ) ) { $this->$attr = $value; } } function save() { if ( ! $this->isValid() ) return false; foreach ( $this->vars as $var ) { $this->data[$var] = $this->$var; } return $this->saveOption(); } function delete() { return $this->deleteOption(); } public function isValid() { if ( ! is_string( $this->name ) || empty( $this->name ) ) { return false; } if ( ! preg_match( '/^\S+$/', $this->tag ) ) return false; return true; } protected function saveOption() { self::$option_data[$this->id] = $this->data; return Configuration::updateValue( self::$option_name, self::$option_data ); } protected function deleteOption() { unset( self::$option_data[$this->id] ); return Configuration::updateValue( self::$option_name, self::$option_data ); } } } if ( ! class_exists( 'Vc_Automapper' ) ) { /** * Automated shortcode mapping * * Automapper adds settings tab for VC settings tabs with ability to map custom shortcodes to VC editors, * if shortcode is not mapped by default or developers haven't done this yet. * No more shortcode copy/paste. Add any third party shortcode to the list of VC menu elements for reuse. * Edit params, values and description. * * @since 4.1 */ class Vc_Automapper { protected static $disabled = false; public function __construct() { $jscomposer = JsComposer::getInstance(); $this->title = $jscomposer->l('My shortcodes'); } public function addAjaxActions() { // add_action( 'wp_ajax_vc_automapper', array( &$this, 'goAction' ) ); $actions = array( 'vc_automapper' => array( &$this, 'goAction' ) ); if($action = Tools::getValue('action')){ if(isset($actions[$action])) call_user_func ($actions[$action]); } } public function build() { $jscomposer = JsComposer::getInstance(); wp_register_script( 'wpb_js_composer_automapper', vc_asset_url( 'js/backend/composer-automapper.js' ), array( 'wpb_js_composer_settings', 'backbone', 'shortcode' ), WPB_VC_VERSION, true ); // TODO: remove to automapper render wp_enqueue_script( 'wpb_js_composer_automapper' ); wp_localize_script( 'wpb_js_composer_automapper', 'i18nLocaleVcAutomapper', array( 'are_you_sure_delete' => $jscomposer->l('Are you sure you want to delete this shortcode?'), 'are_you_sure_delete_param' => __( "Are you sure you want to delete the shortcode's param?", 'js_composer' ), 'my_shortcodes_category' => $jscomposer->l('My shortcodes'), 'error_shortcode_name_is_required' => __( "Shortcode name is required.", 'js_composer' ), 'error_enter_valid_shortcode_tag' => __( "Please enter valid shortcode tag.", 'js_composer' ), 'error_enter_required_fields' => __( "Please enter all required fields for params.", 'js_composer' ), 'new_shortcode_mapped' => $jscomposer->l('New shortcode mapped from string!'), 'shortcode_updated' => $jscomposer->l('Shortcode updated!'), 'error_content_param_not_manually' => $jscomposer->l('Content param can not be added manually, please use checkbox.'), 'error_param_already_exists' => $jscomposer->l('Param %s already exists. Param names must be unique.'), 'error_wrong_param_name' => $jscomposer->l('Please use only letters, numbers and underscore for param name'), 'error_enter_valid_shortcode' => $jscomposer->l('Please enter valid shortcode to parse!') ) ); } // Render methods {{ /** * Builds html for Automapper CRUD like administration block * * @return bool */ public function renderHtml() { if ( $this->disabled() ) return false; ?>