• 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://www.ads-software.com/plugins/s2member/

Viewing 9 replies - 1 through 9 (of 9 total)
  • 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

    (@preethamp08)

    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?

    Thread Starter Preethamp08

    (@preethamp08)

    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.

    Thread Starter Preethamp08

    (@preethamp08)

    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…

    Thread Starter Preethamp08

    (@preethamp08)

    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”…

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘API usage in different plugin’ is closed to new replies.