| 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 |
|