/00-pods-form.txt Secret
Last active
February 27, 2019 16:56
Star
You must be signed in to star a gist
[WordPress] Use the Current User ID with Pods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[pods-form name="user" fields="first_name, last_name" where="current_user_id = user_id" label="Update"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[pods-form name="user" fields="first_name, last_name" where="id = 100" label="Update"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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"]