Content for Specific Users Shortcode
Adds a [wpide_for_users] shortcode that shows its content only to the user accounts you list, handy for private notes to one client on a shared page.
Opens WPIDE on
Code
add_shortcode( 'wpide_for_users', function ( $atts, $content = '' ) {
$atts = shortcode_atts( array( 'ids' => '' ), $atts, 'wpide_for_users' );
$user_id = get_current_user_id();
if ( ! $user_id ) {
return '';
}
$ids = array_filter( array_map( 'absint', explode( ',', $atts['ids'] ) ) );
if ( in_array( $user_id, $ids, true ) || current_user_can( 'manage_options' ) ) {
return do_shortcode( $content );
}
return '';
} );
Notes
Example: [wpide_for_users ids="12,45"]Your files are ready.[/wpide_for_users]. Administrators always see the content.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.