i developed visual composer custom element and I want to assign the value of shortcode $atts["elementcolor"] from elementMapping function to elementCss function how can i do That
Please let me know how to assign the value of shortcode $atts["elementcolor"] from elementMapping function to elementCss function
<?php
class newelement extends WPBakeryShortCode {
# Construct ----------------
function __construct() {
add_action( 'init', [ $this, 'elementMapping' ] );
add_shortcode( 'element_Shortcode', [ $this, 'elementShortcode' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'elementCss' ]);
}
# Fields -------------------
public function elementMapping() {
if ( !defined( 'WPB_VC_VERSION' ) ) {
return;
}
vc_map(
[
"base" => "elementShortcode",
"params" => [
[
"type" => "colorpicker",
"param_name" => "elementcolor"
],
],
]
);
}
# Output Code ---------------------------------
public function elementShortcode () {
$atts = shortcode_atts([
"elementcolor" => "",
], $atts);
extract($atts);
ob_start();
?>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
# css ---------------------------------
public function elementCss() {
// this value $elementcolor = $atts["elementcolor"];
$css = "
.element{ color: {$elementcolor} ;}
";
wp_add_inline_style( 'main', $css);
}
}
new newelement();