main_image = VP_PUBLIC_URL . '/img/vp_shortcode_icon.png'; $this->sprite_image = VP_PUBLIC_URL . '/img/vp_shortcode_icon_sprite.png'; $this->types = array( 'post', 'page' ); $this->included_pages = array(); if (is_array($arr)) { foreach ($arr as $n => $v) { $this->$n = $v; } if (empty($this->name)) die('Unique name required'); if (empty($this->template)) die('Template array / path required'); } if( is_string($this->template) and is_file($this->template) ) $this->template = include $this->template; if(!empty($this->template)) { $this->normalize(); add_action( 'current_screen', array($this, 'init_mce_plugin') ); } self::$pool[$this->name] = $this; } function init_mce_plugin() { if( $this->can_output() ) { // print modal dialog dom add_action( 'admin_footer', array($this, 'print_modal') ); // populate scripts and styles dependencies $loader = VP_WP_Loader::instance(); $loader->add_types( $this->get_field_types(), 'shortcodegenerator' ); } } function normalize() { if(is_array($this->template)) foreach ($this->template as &$shortcode) { foreach ($shortcode['elements'] as &$elements) { if(isset($elements['attributes'])) foreach ($elements['attributes'] as &$f) { if( $f['type'] === 'codeeditor' ) { $f['type'] = 'textarea'; } } } } } function get_field_types() { $field_types = array(); if(is_array($this->template)) foreach ($this->template as $shortcode) { foreach ($shortcode['elements'] as $elements) { if(isset($elements['attributes'])) foreach ($elements['attributes'] as $f) { if( ! in_array($f['type'], $field_types) ) { $field_types[] = $f['type']; } } } } return $field_types; } public static function get_pool() { return self::$pool; } public static function pool_supports_editor() { foreach (self::$pool as $sg) { if( $sg->supports_editor() ) { return true; } } return false; } public function supports_editor() { $post_type = VP_Metabox::_get_current_post_type(); $has_editor = post_type_supports( $post_type, 'editor' ); return $has_editor; } public static function pool_can_output() { foreach (self::$pool as $sg) { if( $sg->can_output() ) { return true; } } return false; } public function can_output() { $screen = ''; $can = true; if( function_exists('get_current_screen') ) { $screen = get_current_screen(); if( !is_null($screen) ) $screen = $screen->id; } // if in post / page if( VP_Metabox::_is_post_or_page() ) { // then consider the types if( !in_array("*", $this->types) ) // if wildcard exists, then always shows $can &= in_array(VP_Metabox::_get_current_post_type(), $this->types); else $can &= true; } else { // if not, only consider the screen id if( !empty($screen) ) { $can &= in_array($screen, $this->included_pages); } else { if( !is_admin() ) { $can &= false; } } } return $can; } public function print_modal() { $modal_id = $this->name . '_modal'; ?>