dominic-ks / bdvs-password-reset

WordPress - Allow users to reset their password using a random code via the REST API
GNU General Public License v3.0
9 stars 3 forks source link

Call to undefined function bdpwr_get_user() #16

Closed pesseyjulien closed 3 years ago

pesseyjulien commented 3 years ago

Hi,

Getting the following error in production while it’s working fine locally :

[03-Mar-2021 17:05:15 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function bdpwr_get_user() in /home/ffaerost/admin/wp-content/plugins/bdvs-password-reset/inc/api/api.route.reset-password.php:28
Stack trace:
#0 /home/ffaerost/admin/wp-includes/rest-api/class-wp-rest-server.php(1160): {closure}(Object(WP_REST_Request))
#1 /home/ffaerost/admin/wp-includes/rest-api/class-wp-rest-server.php(1007): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/bdpwr/v1/reset...', Array, NULL)
#2 /home/ffaerost/admin/wp-includes/rest-api/class-wp-rest-server.php(440): WP_REST_Server->dispatch(Object(WP_REST_Request))
#3 /home/ffaerost/admin/wp-includes/rest-api.php(354): WP_REST_Server->serve_request('/bdpwr/v1/reset...')
#4 /home/ffaerost/admin/wp-includes/class-wp-hook.php(287): rest_api_loaded(Object(WP))
#5 /home/ffaerost/admin/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
#6 /home/ffaerost/admin/wp-includes/plugin.php(551): WP_Hook->do_action(Array)
#7 /home/ffaerost/admin/wp-includes/class-wp.php(388): do_action_ref_a in /home/ffaerost/admin/wp-content/plugins/bdvs-password-reset/inc/api/api.route.reset-password.php on line 28

WordPress 5.6.2 and plugin v0.0.8

Tried to disabled 'JWT Authentication for WP-API' plugin but still the same issue.

Any idea what could be wrong ?

Thanks in advance, Julien

dominic-ks commented 3 years ago

Thanks will look into this shortly. The latest version is 0.0.11 though FYI.

Can you tell me what you're using locally and in prod? i.e. XAMP / WAMP? Linux / Windows? php version?

Cheers,

pesseyjulien commented 3 years ago

Thanks for the quick reply.

I updated to 0.0.11 and then I had to rename the 'functions.php' file and modify the include_once accordingly in the inc.php file and then it worked !

So i'm guessing there is a conflict somewhere but I do really know where :/

Best, Julien

dominic-ks commented 3 years ago

OK, weird, this version fixed a similar issue, I don't get why it's happening and haven't been able to reproduce it myself.

Would you mind letting me know about the environments you're using?

pesseyjulien commented 3 years ago

No pb, running a managed hosting server on OVH with php7.0.33 (need to update..)

And locally running through MAMP v6 and php7.4

Thanks, Julien

dominic-ks commented 3 years ago

Thanks @pesseyjulien, I can't reproduce this still, but I'm guessing that in some environments doing things like...

include_once( 'functions.php' );

...is failing to load the file if there is already one loaded with that name, even from another DIR.

Since I can't reproduce the error, would you mind testing this for me please? Looking at how other plugins include files it looks like they use the __DIR__ constant, so, could you please try updating the inc.php file to this:

<?php

include_once( __DIR__ . '/functions.php' );

include_once( __DIR__ . '/api/api.php' );
include_once( __DIR__ . '/class/class.php' );

With that functions.php file renamed back to functions.php of course. I think this should force php to include the file using it's full path, which should be unique...

Cheers,

pesseyjulien commented 3 years ago

Hi,

Yep it's working now :)

I guess specify the path helps to prevent any conflict. Good catch ;)

Just weird that locally there was no issue, but well, programming mystery !

Best, Julien

dominic-ks commented 3 years ago

Yeah it is weird, like I said, for me locally and on a few different servers and IDEs I don't get the issue. I will sort that and push a new version to wp.org in a mo.

dominic-ks commented 3 years ago

I've just pushed 0.0.12 to wp.org so will close this for now, but please do let me know of any further issues!

pesseyjulien commented 3 years ago

Hi again,

Quick suggestion, when the email is not found, the error code should be 404 and not 500 :)

{
    "code": "bad_email",
    "message": "No user found with this email address.",
    "data": {
        "status": 500
    }
}

Best, Julien

dominic-ks commented 3 years ago

Yes you're right have updated that on here and will go into the next version whenever that is!