From e51204989b79e97ac70034562e88cbab472a0513 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Mon, 4 Sep 2023 12:48:52 +0200 Subject: [PATCH 1/3] Fix getting user metadata with pods_v WP_User class implements magic methods which also handles metadata, though it it forced as single values which is incompatible with our intent for pods_v(). --- includes/data.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/includes/data.php b/includes/data.php index f5381d7dd2..e3d4b7fbc3 100644 --- a/includes/data.php +++ b/includes/data.php @@ -683,8 +683,6 @@ function pods_v( $var = null, $type = 'get', $default = null, $strict = false, $ if ( 'user_pass' === $var || 'user_activation_key' === $var ) { $value = ''; - } elseif ( isset( $user->{$var} ) ) { - $value = $user->{$var}; } elseif ( 'role' === $var ) { $value = ''; @@ -692,7 +690,14 @@ function pods_v( $var = null, $type = 'get', $default = null, $strict = false, $ $value = array_shift( $user->roles ); } } else { - $value = get_user_meta( $user->ID, $var ); + $value = ''; + if ( isset( $user->data->{$var} ) ) { + $value = $user->data->{$var}; + } elseif ( metadata_exists( 'user', $user->ID, $var ) ) { + $value = get_user_meta( $user->ID, $var ); + } elseif ( isset( $user->{$var} ) ) { + $value = $user->{$var}; + } } if ( is_array( $value ) && ! empty( $value ) ) { From 48cbadacaf4d6a7312cf6d1f7d1f5fa306df9398 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Mon, 4 Sep 2023 14:19:18 +0200 Subject: [PATCH 2/3] Parse user magic tag through Pods if it exists --- includes/data.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/includes/data.php b/includes/data.php index e3d4b7fbc3..e84725e80d 100644 --- a/includes/data.php +++ b/includes/data.php @@ -1799,6 +1799,23 @@ function pods_evaluate_tag( $tag, $args = array() ) { return $value; } + // User special magic tag. + if ( 0 === strpos( $tag, 'user.' ) ) { + $pod = pods( 'user', get_current_user_id() ); + if ( $pod->is_valid() && $pod->exists() ) { + $value = $pod->do_magic_tags( '{@' . substr( $tag, 5 ) . '}' ); + + if ( $value ) { + + if ( $sanitize ) { + $value = pods_sanitize( $value ); + } + + return $value; + } + } + } + $tag = trim( $tag, ' {@}' ); $tag = explode( ',', $tag ); $tag = pods_trim( $tag ); From 0792cb4fd511d751e1b274514dab01ac29931d01 Mon Sep 17 00:00:00 2001 From: Jory Hogeveen Date: Thu, 22 Feb 2024 15:53:39 +0100 Subject: [PATCH 3/3] Update getting bleeped metadata since Pods 3.1 --- includes/data.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/data.php b/includes/data.php index 3e61c0ccd4..726cede167 100644 --- a/includes/data.php +++ b/includes/data.php @@ -685,9 +685,7 @@ function pods_v( $var = null, $type = 'get', $default = null, $strict = false, $ $user = pods_access_bleep_data( $user ); - if ( isset( $user->{$var} ) ) { - $value = $user->{$var}; - } elseif ( 'role' === $var ) { + if ( 'role' === $var ) { $value = ''; if ( ! empty( $user->roles ) ) { @@ -696,7 +694,8 @@ function pods_v( $var = null, $type = 'get', $default = null, $strict = false, $ } else { $value = ''; if ( isset( $user->data->{$var} ) ) { - $value = $user->data->{$var}; + $user_data = pods_access_bleep_data( $user->data ); + $value = $user_data->{$var}; } elseif ( metadata_exists( 'user', $user->ID, $var ) ) { $value = get_user_meta( $user->ID, $var ); } elseif ( isset( $user->{$var} ) ) {