plugins – Shortcode don’t work ? An idea?

Question

I want to create a shortcode where content is displayed if user meta is equal to a value

But i want multiple values possible

show content if usermeta firstname is cory or jeff or boris…

Exemple [usermeta_value usermeta=”firstname” uservalue=”Cory,Jeff,Boris”] show content [/usermeta_value]

function func_usermeta_value( $atts, $content = null )
if ( is_user_logged_in() ) { 
$user_meta = $atts['usermeta'];
    $user_value = $atts['uservalue'];
$allowed_value = explode(',', $user_value);

   
    $user_id = get_current_user_id(); 
    $user_data = get_userdata( $user_id ); 
    if ( strtolower($user_data->$user_meta) == strtolower($allowed_value) ) { 
        return do_shortcode($content); /* show content from shortcode */
    }
}
return '';
}
add_shortcode( 'usermeta_value', 'func_usermeta_value' );

Thx for your help

0
Olivier 2 months 2021-03-24T05:44:39-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse