-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser-id-shortcode.php
More file actions
52 lines (43 loc) · 1.72 KB
/
user-id-shortcode.php
File metadata and controls
52 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Plugin Name: User ID shortcode
* Plugin URI: https://github.com/patrickfreitasdev/wp-user-id-shortcode
* Description: This Plugin shows the USER ID number using a shortcode. It had been developed to help wordpress developers who are needs to show this information anywhere.
* Version: 1.0
* Author: Patrick de Freitas
* Author URI: https://github.com/patrickfreitasdev
* License: GPLv3 or later
* Text Domain: user-id-shortcode
*/
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
//Using this to protect the plugin
defined('ABSPATH') or die('What are you looking for?');
//Starting the function to show ID user by shortcode
function show(){
ob_start();
//Get the ID using as Codex site is indicating to do.
$current_user = wp_get_current_user();
//Verify if is there any user logged
if($current_user->ID == 0){
echo "<span class='usr-id'>No logged user</span>";
}else{
?>
<span class="usr-id"><?php
//This <span> can be used to style the number
echo $current_user->ID ?>
</span>
<?php
}
return ob_get_clean();
}add_shortcode('show-me-id','show');