Title: API usage in different plugin
Last modified: August 22, 2016

---

# API usage in different plugin

 *  [Preethamp08](https://wordpress.org/support/users/preethamp08/)
 * (@preethamp08)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/)
 * I want to use API’s provided by s2 member in different plugins I have installed
   under word press.
    When I use the short code say for example, [s2Get user_field
   =”user_login” /] in 1 of the plugin php file; I get the error “Parse error: syntax
   error, unexpected ‘user_field’ (T_STRING), expecting ‘]'”. If used in word press
   page, this works smoothly.
 * Can I use s2 member API in the plugin php files?
    If yes, should I configure 
   any setting or add header file in php file?
 * Thanks for your time!!
 * [https://wordpress.org/plugins/s2member/](https://wordpress.org/plugins/s2member/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [krumch](https://wordpress.org/support/users/krumch/)
 * (@krumch)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392251)
 * 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.
 *  Thread Starter [Preethamp08](https://wordpress.org/support/users/preethamp08/)
 * (@preethamp08)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392376)
 * 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.
 *  [krumch](https://wordpress.org/support/users/krumch/)
 * (@krumch)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392387)
 * 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?
 *  Thread Starter [Preethamp08](https://wordpress.org/support/users/preethamp08/)
 * (@preethamp08)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392394)
 * 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.
 *  [krumch](https://wordpress.org/support/users/krumch/)
 * (@krumch)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392424)
 * 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](http://codex.wordpress.org/Class_Reference/WP_User).
 *  Thread Starter [Preethamp08](https://wordpress.org/support/users/preethamp08/)
 * (@preethamp08)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392453)
 * 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?
 *  [krumch](https://wordpress.org/support/users/krumch/)
 * (@krumch)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392469)
 * 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…
 *  Thread Starter [Preethamp08](https://wordpress.org/support/users/preethamp08/)
 * (@preethamp08)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392470)
 * 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!!!
 *  [krumch](https://wordpress.org/support/users/krumch/)
 * (@krumch)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392483)
 * 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”…

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘API usage in different plugin’ is closed to new replies.

 * ![](https://ps.w.org/s2member/assets/icon-256x256.png?rev=980067)
 * [s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions](https://wordpress.org/plugins/s2member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/s2member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/s2member/)
 * [Active Topics](https://wordpress.org/support/plugin/s2member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/s2member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/s2member/reviews/)

## Tags

 * [API Usage](https://wordpress.org/support/topic-tag/api-usage/)

 * 9 replies
 * 2 participants
 * Last reply from: [krumch](https://wordpress.org/support/users/krumch/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/api-usage-in-different-plugin/#post-5392483)
 * Status: not resolved