• Mark Howells-Mead

    (@markhowellsmead)


    Using the following code, I want to be able to get the user to which the current IP address is assigned, and then get user meta from that user. Is there a function I can use for this? wp_get_current_user() is not returning a valid user.

    public function isAllowed(): bool
    {

    if (!is_plugin_active('ip-based-login/ip-based-login.php') || !function_exists('is_logged_in_using_ipbl')) {
    return false;
    }

    $logged_in = is_logged_in_using_ipbl();

    if (!$logged_in) {
    return false;
    }

    var_dump('IPBL is active and the user is logged in.');

    exit;

    //$current_user = ?????

    return true;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author brijeshk89

    (@brijeshk89)

    Hi,

    Which filter are you using to call your isAllowed() function ?

    I tried to use wp_footer filter and I am able to get the user details from wp_get_current_user() function. I used the following sample code :

    function your_function() {

    $logged_in = is_logged_in_using_ipbl();

    if (!$logged_in) {
    return false;
    }

    var_dump('IPBL is active and the user is logged in.');
    var_dump(wp_get_current_user());

    exit;

    return true;
    }
    add_action( 'wp_footer', 'your_function' );

    Can you try using another filter and check ? If you still face the issue please let me know which filter you are using so I can try with the same.

    Thread Starter Mark Howells-Mead

    (@markhowellsmead)

    I’m trying to use it in a permission_callback callback on register_rest_route (for a custom REST API endpoint. I can also see that it works in the wp_footer hook, so I can only imagine that the plugin doesn’t fire somehow during REST endpoint requests.

    Plugin Author brijeshk89

    (@brijeshk89)

    Hi,

    I have not tested the plugin with Rest API endpoint yet.

    Thread Starter Mark Howells-Mead

    (@markhowellsmead)

    Are you intending to, or would it be better for me to search out an alternative solution?

    Plugin Author brijeshk89

    (@brijeshk89)

    I do intend do check this but I cannot give an ETA. I think it is something related to the action used. The plugin uses “init” WordPress action to trigger login. Maybe that is being triggered at a later time when using REST API.

    If you happen to find a solution to share it here so I can include it as a patch.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.