AI Verified

Name

Shortcode for user first and last name

About

Display current user display name with shortcode

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

User_fields : user_login user_email user_firstname user_lastname display_name # In template echo do_shortcode( '[current_user_data metakey="nickname"]' ); echo do_shortcode( '[current_user_data user_field="user_email"]' ); #in content [current_user_data metakey="first_name"] [current_user_data user_field="user_email"]

Codevault

ipang

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Snippet Source:

https://ipang.net

History

Last modified:

16/06/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Potential vulnerability found : Cross Site Scripting
Found on line : 15
Code : echo($value)
Vulnerable line : 15
Code : $value = get_user_meta( $c_user_id, $metakey, true));

Found 1 vulnerabilities

Shortcode for user first and last name

 
                    
1function current_user_data_func( $atts ) {
2 
3 extract( shortcode_atts( array(
4 'metakey' => '',
5 'user_field' => '',
6 ), $atts) );
7 ob_start();
8 if(is_user_logged_in())
9 {
10 $current_user = wp_get_current_user();
11 
12 $c_user_id = $current_user->ID;
13 if(!empty($metakey))
14 {
15 $value = get_user_meta( $c_user_id, $metakey, true);
16 echo $value;
17 }
18 
19 if(!empty($user_field))
20 {
21 echo $current_user->{"$user_field"};
22 
23 }
24 
25 }
26 else
27 {
28 echo "User Not Logged In";
29 }
30 return ob_get_clean();
31}
32add_shortcode( 'current_user_data', 'current_user_data_func' );

0

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

1

Ensure webfont is loaded

Added: 10 months ago

Last Updated: 8 months ago

General

AI Verified

0

Make Gravity Forms Available to Editor Role

Added: 11 months ago

Last Updated: 11 months ago

General

Unverified

1

Convert to WebP

Added: 6 days ago

Last Updated: 22 hours ago

This WordPress code snippet automatically converts uploaded images (JPEG, PNG, GIF) to WebP format during the upload process.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

0

Shortcode for user first and last name

Added: 1 year ago

Last Updated: 1 year ago

Display current user display name with shortcode