wordpressshortcodevisual-composer

Visual composer Converting Double quote ("some text") into back quote ( ``some text`` )


How to escape visual composer shortcode with double quote into double quote in textfield Every time in string i add double quote, VC convert it with back quote ex. Lorem ipsum dolor sit amet, "consectetur" into Lorem ipsum dolor sit amet,``consectetur``

below is the code i created for custom header with custom title, custom text, back ground image and right side image.

i used all most every Data Sanitization/Escaping methods & regex but no luck

class vcCustomHeader extends WPBakeryShortCode {

    // Element Init
    function __construct() {
        add_action( 'init', array( $this, 'vc_customheader_mapping' ) );
        add_shortcode( 'vc_customheader', array( $this, 'vc_customheader_html' ) );
    }

    // Element Mapping
    public function vc_customheader_mapping() {

        // Stop all if VC is not enabled
        if ( !defined( 'WPB_VC_VERSION' ) ) {
            return;
        }

        // Map the block with vc_map()
        vc_map(
            array(
                'name' => __('VC Custom Header', 'text-domain'),
                'base' => 'vc_customheader',
                'description' => __('VC Custom Header addon', 'text-domain'),
                'category' => __('Stevetrautman theme', 'text-domain'),
                'icon' => get_template_directory_uri().'/assets/images/demo.png',
                'params' => array(

                    array(
                        "type" => "textfield",
                        "holder" => "h3",
                        "class" => "title-class",
                        "heading" => __( "Title", "text-domain" ),
                        "param_name" => "title",
                        "value" => __( "", "text-domain" ),
                        "description" => __( "Add Header Title", "text-domain" ),
                        "admin_label" => false,
                        "weight" => 0,
                        "group" => "Text",
                    ),

                    array(
                        "type" => "textarea",
                        "holder" => "div",
                        "class" => "text-class",
                        "heading" => __( "Text", "text-domain" ),
                        "param_name" => "text",
                        "value" => __( "", "text-domain" ),
                        "description" => __( "Add Header Text", "text-domain" ),
                        "admin_label" => false,
                        "weight" => 0,
                        "group" => "Text",
                    ),

                    array(
                        "type" => "attach_image",
                        "holder" => "img",
                        "class" => "head-bg-img",
                        "heading" => __( "BackGround Image", "text-domain" ),
                        "param_name" => "imagebg",
                        "value" => __( "", "text-domain" ),
                        "description" => __( "Add Header Background Image", "text-domain" ),
                        "admin_label" => false,
                        "weight" => 0,
                        "group" => "Image",
                    ),
                    array(
                        "type" => "attach_image",
                        "holder" => "img",
                        "class" => "head-right-img",
                        "heading" => __( "Header Right Image", "text-domain" ),
                        "param_name" => "imageright",
                        "value" => __( "", "text-domain" ),
                        "description" => __( "Add Header Right Image", "text-domain" ),
                        "admin_label" => false,
                        "weight" => 0,
                        "group" => "Image",
                    )
                )
            )
        );

    }


    // Element HTML
    public function vc_customheader_html( $atts ) {
        $html='';
        // Params extraction
        extract(
            shortcode_atts(
                array(
                    'title'     => '',
                    'text'      => '',
                    'imagebg'   => '',
                    'imageright'=> '',
                ),
                $atts
            )
        );

        // Fill $html var with data
        $imageBG = wp_get_attachment_image_src($imagebg, 'full');
        $headerRight = wp_get_attachment_image_src($imageright, 'full');
$html = '
        <div class="lp-hero-main full-section" style="background-color: #f4f4f4; background-image: url('.$imageBG[0].'); background-position: bottom right; background-repeat: no-repeat; background-size: 37% auto; padding: 134px 0 47px;">
    <div class="inner-hero-lp full-section">
        <div class="lp-left">
            <h1>' . $title . '</h1>
            <p>' . $text . '</p>
        </div>';
        if($headerRight){
            $html.='
                <div class="lp-right text-center">
                    <img src="'.$headerRight[0].'">
                </div>';
        }
        $html.='</div>
    </div>';
        return $html;

    }

} // End Element Class


// Element Class Init
new vcCustomHeader();

Solution

  • Tried <h1>' . str_replace('``', '"', $title) . '</h1> and its working, i know it not the right method but solved my problem