I’ve re-edited this question: is possible to before to show the output in point 2 pass a variable to global color (point 3) like a global variable or something?
class myclass
{
public function init()
{
global $shortcode_tags;
add_shortcode( MYSHORTCODE, array( 'myclass', 'shortcode' ) );
// * point 1
return;
}
public function shortcode( )
{
// *point2
}
function globalcolor($color)
{
echo '<style>body{color:' .$color . '}</style>' . "\n";
// * point 3
}
}
add_action( 'wphead', array( 'myclass', 'globalcolor' ) );
add_action( 'init', array( 'myclass', 'init' ) );
PS. right now im reading about custom fields.enter code here
do_action()is called by WordPress, you wantadd_action().The action
initcomes way too early. You call the class now even for the backend, for AJAX requests etc. Use the hooktemplate_redirectwhich is called on the frontend only.You cannot send the color value the way you tried. See the sample code for a working example.
Sample code:
I strongly recommend https://wordpress.stackexchange.com/ to ask more questions on WordPress. 🙂