If nothing has been placed into your shortcode “wpv-current-user”, you won’t see anything in any of your output.
You should use the built-in function wp_get_current_user()
for this.
Just beware that the Codex page warning. This may need to be called within an action that fires with or after the ‘init’ hook.
I have modified your code so you should get results from both error_log() and from placing your shortcode [show_css_code_conditionally]
in a post/page.
add_shortcode('show_css_code_conditionally', 'show_css_code_conditionally_fn');
function show_css_code_conditionally_fn($atts) {
ob_start(); ?>
<!--- CSS code to show the button conditionally -->
<style type="text/css">
.special-button {
display: block !important;
}
</style>
<?php
$CSS_output = ob_get_clean();
$current_user = wp_get_current_user();
error_log($current_user->ID!==0 ? $current_user->user_email : 'User not logged in',0);
<?php
if ($current_user->ID!==0) {
// this is confirmed that the user is logged in
return $CSS_output;
} else {
return "\n<!-- No valid user currently logged in -->\n\n";
}
}
Since I don’t know what the shortcode [wpv-current-user]
refers to, I just left it out. Usually, you would just do_shortcodes()
to execute all applicable shortcodes, especially when you are already in a shortcode function.