_settings[ $key ] ) ? $this->_settings[ $key ] : NULL; } /** * @var US_Shortcodes */ protected static $instance; /** * Singleton pattern: US_Shortcodes::instance()->us_grid($atts, $content) * * @return US_Shortcodes */ public static function instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self; } return self::$instance; } protected function __construct() { global $us_template_directory, $us_stylesheet_directory; $this->config = us_config( 'shortcodes' ); add_filter( 'the_content', 'us_paragraph_fix' ); add_filter( 'us_page_block_the_content', 'us_paragraph_fix', 11 ); add_filter( 'the_content', array( $this, 'a_to_img_magnific_pupup' ) ); add_filter( 'us_page_block_the_content', array( $this, 'a_to_img_magnific_pupup' ) ); // Make sure that priority makes the class init after WPBakery Page Builder add_action( 'init', array( $this, 'init' ), 20 ); $this->_template_directory = $us_template_directory; $this->_stylesheet_directory = $us_stylesheet_directory; } /** * @var bool Is the shortcode inited? */ protected $inited = FALSE; public function init() { // Adding new shortcodes foreach ( $this->config['theme_elements'] as $element ) { $shortcode = 'us_' . $element; add_shortcode( $shortcode, array( $this, $shortcode ) ); } // Adding aliases foreach ( $this->config['alias'] as $shortcode => $alias ) { // Overloading the previous declaration if exists if ( shortcode_exists( $shortcode ) ) { remove_shortcode( $shortcode ); } add_shortcode( $shortcode, array( $this, $shortcode ) ); } // Modifying existing shortcodes foreach ( $this->config['modified'] as $shortcode => $shortcode_params ) { // Some shortcodes should not be overloaded if ( isset( $shortcode_params['overload'] ) AND ! $shortcode_params['overload'] ) { continue; } // Overloading the previous declaration if exists if ( shortcode_exists( $shortcode ) ) { remove_shortcode( $shortcode ); } add_shortcode( $shortcode, array( $this, $shortcode ) ); } // Removing disabled shortcodes if ( us_get_option( 'disable_extra_vc', 1 ) == 1 ) { foreach ( $this->config['disabled'] as $shortcode ) { if ( shortcode_exists( $shortcode ) ) { remove_shortcode( $shortcode ); } } } $this->inited = TRUE; } /** * Handling shortcodes * * @param string $shortcode Shortcode name * @param array $args * * @return string Generated shortcode output * */ public function __call( $shortcode, $args ) { $_output = ''; $shortcode_base = $shortcode; // Checking wif it is alias and getting real shortcode name if ( isset( $this->config['alias'][ $shortcode ] ) ) { $shortcode = $this->config['alias'][ $shortcode ]; } // Check if it is theme element or modified shortcode if ( substr( $shortcode, 0, 3 ) == 'us_' ) { $element = substr( $shortcode, 3 ); } else { $element = $shortcode; } if ( ! in_array( $element, $this->config['theme_elements'] ) AND ! isset( $this->config['modified'][ $element ] ) ) { return $_output; } // Preparing params for shortcodes (can be used inside of the input) $atts = isset( $args[0] ) ? $args[0] : array(); $content = isset( $args[1] ) ? $args[1] : ''; // VC's special chars replacement if ( is_array( $atts ) ) { $atts_result = array(); foreach ( $atts as $key => $val ) { $atts_result[ $key ] = str_replace( array( '`{`', '`}`', '``', ), array( '[', ']', '"', ), $val ); } $atts = $atts_result; } // Preserving VC before hook if ( substr( $shortcode_base, 0, 3 ) == 'vc_' AND defined( 'VC_SHORTCODE_BEFORE_CUSTOMIZE_PREFIX' ) ) { $custom_output_before = VC_SHORTCODE_BEFORE_CUSTOMIZE_PREFIX . $shortcode_base; if ( function_exists( $custom_output_before ) ) { $_output .= $custom_output_before( $atts, $content ); } unset( $custom_output_before ); } $_filename = $this->_template_directory . '/framework/templates/elements/' . $element . '.php'; // We are using this context in some element templates $us_elm_context = 'shortcode'; $filled_atts = us_shortcode_atts( $atts, $shortcode ); // Only for theme elements aliases: get params for both base and alias if ( $shortcode_base != $shortcode AND substr( $shortcode, 0, 3 ) == 'us_' ) { $filled_atts_base = us_shortcode_atts( $atts, $shortcode_base ); $filled_atts = us_array_merge( $filled_atts, $filled_atts_base ); } unset( $filled_atts['content'] ); extract( $filled_atts ); ob_start(); require $_filename; $_output .= ob_get_clean(); // Preserving VC after hooks if ( substr( $shortcode_base, 0, 3 ) == 'vc_' ) { if ( defined( 'VC_SHORTCODE_AFTER_CUSTOMIZE_PREFIX' ) ) { $custom_output_after = VC_SHORTCODE_AFTER_CUSTOMIZE_PREFIX . $shortcode_base; if ( function_exists( $custom_output_after ) ) { $_output .= $custom_output_after( $atts, $content ); } } $this->_settings = array( 'base' => $shortcode_base, ); $_output = apply_filters( 'vc_shortcode_output', $_output, $this, isset( $args[0] ) ? $args[0] : array() ); } return $_output; } public function paragraph_fix( $content ) { $array = array( '
[' => '[', ']
' => ']', ']