← All changes
|
includes/frontend/dynamic-content/interpreters/user-info.php
+57
-0
2.7.6
→
2.14.0
View file →
| @@ -1,0 +1,57 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Frontend\DynamicContent\Interpreters; | |
| 3 | + | |
| 4 | +use ABlocks\Helper; | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | +class UserInfo extends Abstracts\Interpreter { | |
| 9 | + protected string $field; | |
| 10 | + protected string $pre; | |
| 11 | + protected string $post; | |
| 12 | + protected string $default; | |
| 13 | + | |
| 14 | + public function __construct( string $name, array $setting, bool $is_richtext = false ) { | |
| 15 | + parent::__construct( $name, $setting, $is_richtext ); | |
| 16 | + $this->field = strval( $this->setting[0] ?? '' ); | |
| 17 | + $this->pre = strval( $this->setting[3] ?? '' ); | |
| 18 | + $this->post = strval( $this->setting[4] ?? '' ); | |
| 19 | + $this->default = strval( $this->setting[5] ?? '' ); | |
| 20 | + } | |
| 21 | + public function content() : string { | |
| 22 | + if ( ! is_user_logged_in() ) { | |
| 23 | + return ''; | |
| 24 | + } | |
| 25 | + $current_user = wp_get_current_user(); | |
| 26 | + switch ( $this->field ) { | |
| 27 | + case 'id': | |
| 28 | + $this->content = $current_user->ID; | |
| 29 | + break; | |
| 30 | + case 'display-name': | |
| 31 | + $this->content = $current_user->display_name; | |
| 32 | + break; | |
| 33 | + case 'username': | |
| 34 | + $this->content = $current_user->user_login; | |
| 35 | + break; | |
| 36 | + case 'first-name': | |
| 37 | + $this->content = $current_user->first_name; | |
| 38 | + break; | |
| 39 | + case 'last-name': | |
| 40 | + $this->content = $current_user->last_name; | |
| 41 | + break; | |
| 42 | + case 'bio': | |
| 43 | + $this->content = $current_user->description; | |
| 44 | + break; | |
| 45 | + case 'email': | |
| 46 | + $this->content = $current_user->user_email; | |
| 47 | + break; | |
| 48 | + case 'website': | |
| 49 | + $this->content = $current_user->user_url; | |
| 50 | + break; | |
| 51 | + case 'user-meta': | |
| 52 | + $this->content = get_user_meta( $current_user->ID, $this->setting[1] ?? '', true ); | |
| 53 | + break; | |
| 54 | + }//end switch | |
| 55 | + return $this->pre . ( $this->content === '' ? $this->default : $this->content ) . $this->post; | |
| 56 | + } | |
| 57 | +} | |