Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin tommcfarlin/00-pods-form.txt Secret
Last active Feb 27, 2019

Embed
What would you like to do?
[WordPress] Use the Current User ID with Pods
[pods-form name="user" fields="first_name, last_name" where="current_user_id = user_id" label="Update"]
<?php
add_filter('the_content', __NAMESPACE__ . '\\filter_pods_by_current_user');
/**
* Replaces the current_user_id = user_id with the current user ID in the
* incoming content (which includes the Pods shortcode).
*
* @param string $content the content of the shortcode.
* @return string the result of the parsed shortcode.
*/
function filter_pods_by_current_user($content)
{
$user = wp_get_current_user();
return str_ireplace(
'current_user_id = user_id',
"id='" . $user->ID . "'",
$content
);
}
[pods-form name="user" fields="first_name, last_name" where="id = 100" label="Update"]
@sc0ttkclark

This comment has been minimized.

Copy link

sc0ttkclark commented Feb 27, 2019

There should be an is_user_logged_in() check here.

Also, the below is available if you set this in wp-config.php define( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS', true );

[pods-form name="user" fields="first_name,last_name" id="{@user.ID}" label="Update"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.