The require function cannot recognize and load the php file in the current folder.
P粉277824378
P粉277824378 2023-07-30 19:48:55
0
1
461
<p>My question may be a little strange, but it really confuses me! </p><p>In my child theme I used to be able to call and load files adjacent to the function.php file without any issues, but after deleting and reinserting all the files in the subfolder , the files are not recognized. I used the following command. </p><p>In the function.php file, I called its subsidiary file user_function.php, but even with the command, it was not recognized. </p><p><code></code><code></code></p> <pre class="brush:php;toolbar:false;">if (file_exists('user_function.php')) { require_once('user_function.php'); } else { echo "Please try back in 30 minutes...n"; die; }</pre> <p>The file cannot be recognized! and an error message appears! ! !

There are only these two files in: </p><p><br /></p> <ul> <li><code>function.php</code></li> <li><code>user_function.php</code></li> </ul> <p>What's the problem? (These instructions are not complicated or difficult, I have used these instructions many times before in different places, but now they are a challenge for me)</p><p>I have used them many times in other topics Switch between, even the parent template</p><p> Update:</p><p>I encountered a strange problem! Now, I want to load other files in function.php and user_function.php, I have to use __DIR__ to specify the path, I think the problem must be somewhere else! I submitted a hosting support request and they said there was an issue a few hours ago where the connection to the database was lost and they didn't explain what happened but I think it may have caused the problem and broke my WordPress path or address. Is this possible? </p><p><strong></strong><strong></strong><strong><code></code></strong></p>
P粉277824378
P粉277824378

reply all(1)
P粉736935587

It may be because the function.php file is called from another file in another directory.

To avoid ambiguity, you can use the full path by providing __DIR__ to return the directory of the current file, so that PHP will search for the user_function.php file in the same directory as the function.php file:

// in function.php
if (file_exists(__DIR__.'/user_function.php')) {
     require_once(__DIR__.'/user_function.php');
} else {
     echo "Please try back in 30 minutes...\n";
     die;
} 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template