options = apply_filters( 'cs_shortcode_options', $options ); $this->exclude_post_types = apply_filters( 'cs_shortcode_exclude', $this->exclude_post_types ); if( ! empty( $this->options ) ) { $this->shortcodes = $this->get_shortcodes(); $this->addAction( 'media_buttons', 'media_shortcode_button', 99 ); $this->addAction( 'admin_footer', 'shortcode_dialog', 99 ); $this->addAction( 'customize_controls_print_footer_scripts', 'shortcode_dialog', 99 ); $this->addAction( 'wp_ajax_cs-get-shortcode', 'shortcode_generator', 99 ); } } // instance public static function instance( $options = array() ){ if ( is_null( self::$instance ) && CS_ACTIVE_SHORTCODE ) { self::$instance = new self( $options ); } return self::$instance; } // add shortcode button public function media_shortcode_button( $editor_id ) { global $post; $post_type = ( isset( $post ) ) ? $post->post_type : ''; if( ! in_array( $post_type, $this->exclude_post_types ) ) { echo ''. __( 'Add Shortcode', 'cs-framework' ) .''; } } // shortcode dialog public function shortcode_dialog() { ?>
shortcodes[$request]; if( isset( $shortcode['fields'] ) ) { foreach ( $shortcode['fields'] as $key => $field ) { if( isset( $field['id'] ) ) { $field['attributes'] = ( isset( $field['attributes'] ) ) ? wp_parse_args( array( 'data-atts' => $field['id'] ), $field['attributes'] ) : array( 'data-atts' => $field['id'] ); } $field_default = ( isset( $field['default'] ) ) ? $field['default'] : ''; if( in_array( $field['type'], array('image_select', 'checkbox') ) && isset( $field['options'] ) ) { $field['attributes']['data-check'] = true; } echo cs_add_element( $field, $field_default, 'shortcode' ); } } if( isset( $shortcode['clone_fields'] ) ) { $clone_id = isset( $shortcode['clone_id'] ) ? $shortcode['clone_id'] : $shortcode['name']; echo '
'; echo ''; foreach ( $shortcode['clone_fields'] as $key => $field ) { $field['sub'] = true; $field['attributes'] = ( isset( $field['attributes'] ) ) ? wp_parse_args( array( 'data-clone-atts' => $field['id'] ), $field['attributes'] ) : array( 'data-clone-atts' => $field['id'] ); $field_default = ( isset( $field['default'] ) ) ? $field['default'] : ''; if( in_array( $field['type'], array('image_select', 'checkbox') ) && isset( $field['options'] ) ) { $field['attributes']['data-check'] = true; } echo cs_add_element( $field, $field_default, 'shortcode' ); } echo '
'; echo '
'. $shortcode['clone_title'] .'
'; } die(); } // getting shortcodes from config array public function get_shortcodes() { $shortcodes = array(); foreach ( $this->options as $group_value ) { foreach ( $group_value['shortcodes'] as $shortcode ) { $shortcodes[$shortcode['name']] = $shortcode; } } return $shortcodes; } }