Try this:
echo do_shortcode('[s2Get user_field="user_login" /]');
There also is descriptions and examples how to use API in PHP, look in s2M backend.
Thanks for the reply Krumch, I tried the above suggestion but this time the error was for do_shortcode function. Error: ‘Fatal error: Call to undefined function do_shortcode()’.
Here is the code I have used:
<? php
$user_id = do_shortcode(‘[s2Get user_field=”user_login” /]’);
?>
PS: I have used this code in one of the php file in a custom plugin.
If you are inside WP, why not to use this:
global $current_user;
$user_id = $current_user->ID;
But inside WP the “do_shortcode” function should works, so what plugin you run/create? How it is related to WP/s2M?
I have a plugin implemented where I need to use the logged in user name.
I have added s2 member to WP and went through the API’s supported. So i thought i can use these in my plugin.
I’m new to WP and PHP, kindly bear with me if I have missed the basics.
It’s $current_user->name. Also do echo print_r($current_user); to see all user’s info and fields. Also good to review WP_User class.
Krumch,
I googled few articles and basics of usage and I’m stuck at this place
Error:
Fatal error: Call to undefined function apply_filters() in C:\wamp\www\wordpress\wp-includes\pluggable.php on line 118
Code:
<?php
include ‘C:\wamp\www\wordpress\wp-includes\pluggable.php’;
$current_user = wp_get_current_user();
echo ‘Username: ‘ . $current_user->user_login;
?>
I haven’t modified pluggable.php file.
Am I still missing any include or require file?
You not need to modify core files when you build a plugin… And not need to “include” or “require” any WP library too, as plugin works “inside” WP, after WP is fully loaded… So you have some big capital errors. I can see two: 1) your file have a hard coded path in your “include” row, which is bad for portability; 2) you not need to include that file, WP will include it. RTFM…
Thanks for guiding me through this.
I tried the below snippet and it worked!!
<?php
require_once(‘../../../wp-load.php’);
require_once(ABSPATH.’wp-includes/pluggable.php’);
$current_user = wp_get_current_user();
$usr_name = $current_user->user_login;
?>
Thanks again
Cheers!!!
You are welcome 🙂 Note that you fix my 1) above. There is no reason to include any code to find current user’s info in a plugin. If we have same definition about “plugin”…