Using Replacement Codes in PHP
Posted:
August 7th, 2011, 12:04 pm
by hugemonkey
Hi all,
I was wondering if you can help me....
Is it possible to use the s2 member replacement shortcodes in php scripts? I am trying to get the current users ID so that I can feed it into another database which I will run alongside wordpress. I want to reference the entries made by a user with their ID which is assigned to them when they are added into s2 member during registration...that way I can make mysql calls to the database like SELECT * WHERE Author = %%current_user_id%% etc.
Thanks a lot for your help.
Re: Using Replacement Codes in PHP
Posted:
August 7th, 2011, 1:10 pm
by Bruce C
Hey!
I'm pretty sure, but correct me if I'm wrong that if the code if outside of the WordPress database, then it won't work, as the the shortcodes most likely link to a constant set by s2Member itself. Therefore, I would imagine that you would have to keep your idea inside of WordPress itself... or perhaps there's a way to link to it?
Re: Using Replacement Codes in PHP
Posted:
August 8th, 2011, 4:48 am
by hugemonkey
Hey
Thanks for the reply.
I will only be running these scripts on wordpress pages once someone has logged in. That should be ok shouldnt it? I do similar things in my non wordpress sites by accessing the session information to personalise the content on a per user basis.
Thanks a lot.
Re: Using Replacement Codes in PHP
Posted:
August 8th, 2011, 5:35 am
by hugemonkey
Hey all,
I have the solution to what I was answering so thought I would share it here. I'm sure a lot of you know this but just in case, here is come php code to retrieve information about the current logged in user :
- Code: Select all
<?php
$current_user = wp_get_current_user();
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User email: ' . $current_user->user_email . '<br />';
echo 'User first name: ' . $current_user->user_firstname . '<br />';
echo 'User last name: ' . $current_user->user_lastname . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
echo 'User ID: ' . $current_user->ID . '<br />';
?>
Re: Using Replacement Codes in PHP
Posted:
August 8th, 2011, 3:00 pm
by Cristián Lávaque
Yeah, that should work. If you're in a WordPress page and have a PHP execution plugin, working with the HTML editor it should be possible to use PHP code as you would in a template. I'm pretty sure WP shortcode would still work outside the PHP tags.
These may be helpful:
https://codex.wordpress.org/Function_Reference/s2Member CodexWP Admin -> s2Member -> API / Scripting