Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance user magictag #7153

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions includes/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,16 +685,22 @@ 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 ) ) {
$value = array_shift( $user->roles );
}
} else {
$value = get_user_meta( $user->ID, $var );
$value = '';
if ( isset( $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} ) ) {
$value = $user->{$var};
}
}

if ( is_array( $value ) && ! empty( $value ) ) {
Expand Down Expand Up @@ -1804,6 +1810,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 );
Expand Down
Loading