Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 65051

Call to undefined function when calling WP functions from outside

$
0
0

Replies: 0

Hi,

I’m developing a plugin that consists of a normal part that runs inside WP and a very small external part, that can be directly accessed and runs not inside WP but uses parts of WP.

At the beginning of the “external” code, let’s call it external.php, there is:

define('ABSPATH', $_SERVER['DOCUMENT_ROOT'].'/');
require($_SERVER['DOCUMENT_ROOT'].'/wp-content/plugins/troubleshoot/troubleshoot.inc.php');

In troubleshoot.inc.php there is:

if ( ! defined( 'ABSPATH' ) ) exit; // This is a library file that may not accessed directly
require($_SERVER['DOCUMENT_ROOT']."/wp-includes/user.php");
require($_SERVER['DOCUMENT_ROOT']."/wp-includes/pluggable.php");
//[...]
class WpSite
{
  public function Authenticate($username, $password)
  {
    $authObject = wp_authenticate($username, $password);
    //[...]

If external.php calls $wpSite->Authenticate($_get_user, $_get_password), WordPress’ wp_authenticate fails:
PHP message: PHP Fatal error: Call to undefined function sanitize_user() in /var/www/devel/htdocs/wp-includes/pluggable.php on line 572″ while reading response header from upstream, client: xx.xx.xx.xx, server: devel.domain.tld, request: “GET /wp-content/plugins/troubleshoot/external.php?format=json HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php5-fpm-devel.sock:”, host: “devel.domain.tld”
On the devel environment is WordPress 4.4.2 so the file numbers may vary a bit.

Why can’t function wp_authenticate in pluggable.php not find function sanitize_user in user.php? Can a required file not access other required files?

Thank you a lot,
Josef


Viewing all articles
Browse latest Browse all 65051

Trending Articles