Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active February 27, 2019 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/c8d786d7ca5871a7178e7e7a8ef8443d to your computer and use it in GitHub Desktop.
Save tommcfarlin/c8d786d7ca5871a7178e7e7a8ef8443d to your computer and use it in GitHub Desktop.
[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
Copy link

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