PluginProbe
My WP Customize Admin/Frontend / 1.14
My WP Customize Admin/Frontend v1.14
1.27.4 1.27.3 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.10 1.10.1 1.10.2 1.11 1.12 1.12.1 1.12.2 1.13 1.13.1 1.13.2 1.14 1.15.0 1.16 1.17.0 All 76 releases
my-wp / shortcode / modules / mywp.shortcode.module.user.php

mywp.shortcode.module.user.php in My WP Customize Admin/Frontend 1.14, at shortcode/modules/mywp.shortcode.module.user.php

110 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if( ! class_exists( 'MywpShortcodeAbstractModule' ) ) {
8 return false;
9 }
10
11 if ( ! class_exists( 'MywpShortcodeModuleUser' ) ) :
12
13 final class MywpShortcodeModuleUser extends MywpShortcodeAbstractModule {
14
15 protected static $id = 'mywp_user';
16
17 public static function do_shortcode( $atts , $content = false , $tag ) {
18
19 if( empty( $atts['field'] ) ) {
20
21 MywpHelper::error_not_found_message( '$atts["field"]' , sprintf( '[%s] shortcode' , self::$id ) );
22
23 return $content;
24
25 }
26
27 $field = strip_tags( $atts['field'] );
28
29 if( empty( $atts['user_id'] ) ) {
30
31 $user_id = get_current_user_id();
32
33 } else {
34
35 $user_id = intval( $atts['user_id'] );
36
37 }
38
39 $mywp_user = new MywpUser( $user_id );
40
41 if( empty( $mywp_user ) ) {
42
43 return $content;
44
45 }
46
47 if( $field === 'id' ) {
48
49 $content = $user_id;
50
51 } elseif( $field === 'name' ) {
52
53 $content = $mywp_user->get_name();
54
55 } elseif( $field === 'fname' ) {
56
57 $content = $mywp_user->get_fname();
58
59 } elseif( $field === 'lname' ) {
60
61 $content = $mywp_user->get_lname();
62
63 } elseif( $field === 'nickname' ) {
64
65 $content = $mywp_user->get_nickname();
66
67 } elseif( $field === 'displayname' ) {
68
69 $content = $mywp_user->get_displayname();
70
71 } elseif( $field === 'user_login' ) {
72
73 $content = $mywp_user->get_user_login();
74
75 } elseif( $field === 'user_role' ) {
76
77 $content = $mywp_user->get_user_role();
78
79 } elseif( $field === 'avatar' ) {
80
81 $size = false;
82
83 if( ! empty( $atts['size'] ) ) {
84
85 $size = $atts['size'];
86
87 }
88
89 $content = $mywp_user->get_avatar_tag( $size );
90
91 } else {
92
93 MywpHelper::error_not_found_message( '$atts["field"]' , sprintf( '[%s] shortcode' , self::$id ) );
94
95 return $content;
96
97 }
98
99 $content = apply_filters( 'mywp_shortcode_user' , $content , $atts );
100
101 return $content;
102
103 }
104
105 }
106
107 MywpShortcodeModuleUser::init();
108
109 endif;
110