2

I have got a WP website running version 4.8.2. I have created, in the root folder of my theme, a custom php page that includes Wordpress functions with the following code:

<?php
echo 'ralph';
clearstatcache();
echo file_exists('../../../wp-load.php');
require_once('../../../wp-load.php');
echo 'joe';
?>

The end result should be displaying on the page the string 'ralph1joe' (1 stands for the fact that wp-load.php actually exists).

Problem is: when I launch the custom page only the string 'ralph1' is visualized. Any instruction after the require_once line, is ignored. I cannot see any error both on the page and in the log files. The process of the page is simply interrupted.

Is there anything I can do for having the require_once line to work properly ?

Antelion
  • 155
  • 2
  • 14
  • Have you checked the HTML source to see if "joe" is nested in there somewhere? Also is error reporting turned on? – EM-Creations Oct 03 '17 at 10:38
  • I did check HTML source: it shows only 'ralph1'. The error reporting is active. – Antelion Oct 03 '17 at 10:41
  • To be more precise, I have actually a deferred error visualization (the website is on a shared hosting platform). This error: Uncaught Error: Call to undefined function is_user_logged_in() could in effect be caused by my custom page but I cannot be sure about that. – Antelion Oct 03 '17 at 10:47
  • What's the contents of the `wp-load.php` file? Any functions in there you could try to call to check that the file is being included correctly? – EM-Creations Oct 03 '17 at 10:50
  • 1
    Try `echo file_exists('../../../wp-load.php')? 'yes' : 'no';` so you can actually see if it's where you think it is. You could try something like `$uriParts = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] ); require_once( $uriParts[0] . 'wp-load.php' );` to get the right location, assuming your theme sits under than directory. – Daren Chandisingh Oct 03 '17 at 10:50
  • 1
    @Newcomsas The error might be coming from the file you're including (try and trace down the file it says it's in). Which is then crashing your script before it gets to `echo 'joe';`. – EM-Creations Oct 03 '17 at 10:52
  • @DarenChandisingh I modified the file_exists line; now the result is ralphyes so the file wp-load.php exists in the root location of WP. This file comes with the WP install anyway. – Antelion Oct 03 '17 at 11:02

3 Answers3

1

I think the problem is with wp_load.php or maybe you haven't read the wp_load.php file correctly.

Wp_load always requires wp_config.php If it doesn't get it it will die with an error. See the below code in wp_load.php file

$die  = __( "There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started." ) . '</p>';

With some more identical code like this and error associated with it.

so when you require_once 'wp_load.php' and It doesn't get wp_config.php It will die and stop the execution and you won't get any further print statement

Hope it clarifies you.

Saad Suri
  • 1,352
  • 1
  • 14
  • 26
0

I solved the problem. A plugin I had installed caused evidently a conflict. The plugin is called All 404 Redirect to Homepage Deactivating it caused my custom page to work properly again.

Antelion
  • 155
  • 2
  • 14
0

In my code this error was caused by the required line inside a function. I removed and placed this line at the main code.

Paulo Costa
  • 182
  • 3
  • 12