PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Using Replacement Codes in PHP

s2Member Plugin. A Membership plugin for WordPress®.

Using Replacement Codes in PHP

Postby hugemonkey » August 7th, 2011, 12:04 pm

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.
User avatar
hugemonkey
Registered User
Registered User
 
Posts: 3
Joined: August 7, 2011

Re: Using Replacement Codes in PHP

Postby Bruce C » August 7th, 2011, 1:10 pm

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?
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Using Replacement Codes in PHP

Postby hugemonkey » August 8th, 2011, 4:48 am

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.
User avatar
hugemonkey
Registered User
Registered User
 
Posts: 3
Joined: August 7, 2011

Re: Using Replacement Codes in PHP

Postby hugemonkey » August 8th, 2011, 5:35 am

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 />';
?>
Last edited by Cristián Lávaque on August 8th, 2011, 2:56 pm, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
hugemonkey
Registered User
Registered User
 
Posts: 3
Joined: August 7, 2011

Re: Using Replacement Codes in PHP

Postby Bruce C » August 8th, 2011, 10:50 am

Seems to work for me.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Using Replacement Codes in PHP

Postby Cristián Lávaque » August 8th, 2011, 3:00 pm

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 Codex
WP Admin -> s2Member -> API / Scripting
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 3 guests

cron