checkbox.php
3 weeks ago
date.php
3 weeks ago
datetime.php
3 weeks ago
field.php
3 weeks ago
gallery.php
3 weeks ago
media.php
3 weeks ago
number.php
3 weeks ago
post.php
3 weeks ago
radio.php
3 weeks ago
repeater.php
3 weeks ago
select.php
3 weeks ago
switcher.php
3 weeks ago
text.php
3 weeks ago
time.php
3 weeks ago
toggle.php
3 weeks ago
user.php
3 weeks ago
user.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\AddonAPI; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 | |
| 7 | class PMXE_Addon_User_Field extends PMXE_Addon_Field { |
| 8 | |
| 9 | public function getEmail( $value ) { |
| 10 | $user = get_user_by( 'id', $value ); |
| 11 | |
| 12 | if ( $user ) { |
| 13 | $email = $user->user_email; |
| 14 | } |
| 15 | |
| 16 | return $email ?? ''; |
| 17 | } |
| 18 | |
| 19 | public function getLogin( $value ) { |
| 20 | $user = get_user_by( 'id', $value ); |
| 21 | |
| 22 | if ( $user ) { |
| 23 | $login = $user->user_login; |
| 24 | } |
| 25 | |
| 26 | return $login ?? ''; |
| 27 | } |
| 28 | |
| 29 | public function toString() { |
| 30 | $format = $this->settings['user_value_format'] ?? 'id'; |
| 31 | |
| 32 | $return_value = []; |
| 33 | |
| 34 | if ( ! is_array( $this->value ) ) { |
| 35 | $value = [ $this->value ]; |
| 36 | } else { |
| 37 | $value = $this->value; |
| 38 | } |
| 39 | |
| 40 | foreach ( $value as $current_value ) { |
| 41 | switch ( $format ) { |
| 42 | case 'id': |
| 43 | $return_value[] = $current_value; |
| 44 | break; |
| 45 | case 'email': |
| 46 | $return_value[] = $this->getEmail( $current_value ); |
| 47 | break; |
| 48 | default: |
| 49 | $return_value[] = $this->getLogin( $current_value ); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return implode( $this->getImplode(), $return_value ); |
| 54 | } |
| 55 | } |
| 56 |