Ruft den Shortcode-Attributwert für eine andere function ab

Ich versuche, shortcode Attributwert zu einer anderen function zu erhalten, um Inline-Stil hinzuzufügen. Ich möchte den Wert von $color zu einer anderen function verwenden.

Hier ist mein Code

  '#000000', ), $atts) ); $this->color = $section_color; $output = 'First LIne'; $output .= 'Second Line'; return $output; } public function inlinestyle(){ wp_enqueue_style( 'custom-style', get_template_directory_uri() . '/css/style.css' ); $custom_css = " div[data-id=289374].post-block-post-left.active, div[data-id=289374].post-block-post-right.active{ background : {$this->color}; border-color : {$this->color}; }"; wp_add_inline_style( 'custom-style', $custom_css ); } } $test = new MakeShortcode(); 

Aber background und Rahmenfarbe werden leer. Das bedeutet, dass ich $this->color in dieser function nicht $this->color kann ich das bekommen?

Solutions Collecting From Web of "Ruft den Shortcode-Attributwert für eine andere function ab"

 < ?php class MakeShortcode { public $color; public function __construct() { add_action( 'init', array($this, 'PostBLock') ); add_shortcode( 'PostBLock', array($this, 'getpostblock') ); add_action( 'wp_enqueue_scripts', array( $this, 'inlinestyle') ); } public function getpostblock( $atts ){ extract( shortcode_atts( array( 'section_color' => '#000000', ), $atts) ); return $section_color; } public function inlinestyle(){ $color = $this->getpostblock(); wp_enqueue_style( 'custom-style', get_template_directory_uri() . '/css/style.css' ); $custom_css = " div[data-id=289374].post-block-post-left.active, div[data-id=289374].post-block-post-right.active{ background : {$color}; border-color : {$color}; }"; wp_add_inline_style( 'custom-style', $custom_css ); } } $test = new MakeShortcode();