In my custom plugin's php, trying to call the core wordpress function username_exists()
throws a 500 error which I think is caused by that function not being defined.
The line in my code that is failing is:
$unres = username_exists($unt);
I have verified that it is not a problem caused by a null argument, as the following works as expected: $unres = $unt;
How do I fix this?
I tried all the solutions throughout the answers and comments at all of the following:
'username_exists' function not working in Wordpress plugin
Function username_exists() can't be accessed without logging in to wordpress
WordPress plugin admin page - using WordPress function in linked php file
How do I call the basic WordPress header files?
wordpress plugin -> Call to undefined function wp_get_current_user()
I have successfully added the following php to include/require these files (but this did not help):
require realpath("../../../../../wp-includes/pluggable.php");
require realpath("../../../../../wp-includes/user.php");
require realpath("../../../../../wp-admin/includes/user.php");
If I include or require the following, it creates a fatal site error:
require realpath("../../../../../wp-load.php");
Is there now some other core file that I need to 'include' in my php by reference, other than those outlined above (for example, due to new WP versions since those questions were written)? (I'm on WP v5.5).
Do I need to contextualise the call? (e.g. reference namespace, call as public/global, etc?)
(Note: the site also uses the Ultimate Member plugin, not sure if that would override the core function name in any way?)
Thanks.