- Notifications
You must be signed in to change notification settings - Fork1.9k
Update README.md#495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Update README.md#495
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Your code didn't work for me but it worked somehow when I added the code in a funcation and then used the if statement to process the error.
mikaykun commentedOct 18, 2020
This sounds wrong. What changes have you done to your functions.php? |
@mikaykun I pasted the code which is in the README.md but I got errors so I did some search and found that code I wrote to you and it worked for me. There is no need to update the README.md but put it in case someone like me needed. |
mikaykun commentedOct 19, 2020
Can you provide a example code so that we can fixed this issue or create a better solution for others and add it to the Readme. That would be nice. |
I think@maheraldous is right. With if ( !file_exists(get_template_directory() .'/class-wp-bootstrap-navwalker.php' ) ) {// File does not exist... return an error.returnnewWP_Error('class-wp-bootstrap-navwalker-missing',__('It appears the class-wp-bootstrap-navwalker.php file may be missing.','wp-bootstrap-navwalker' ) );}else {// File exists... require it.require_onceget_template_directory() .'/class-wp-bootstrap-navwalker.php';} you simply return an instance of the WP_Error class holding the error code @maheraldous solution is a complicated way to echo the error message onevery page (admin and non-admin pages for logged in and logged out users). My proposal is $file =get_template_directory() .'/class-wp-bootstap-navwalker.php';if ( !file_exists($file ) ) {// Files does not exist, add admin notice.add_action('admin_notices',function() {$message =sprintf(/* translators: path to file */__('The file class-wp-bootstap-navwalker.php cannot be found at %s.','wp-bootstrap-navwalker' ),get_template_directory());printf('<div><p>%s</p></div>',esc_html($message ) );} );}else {// File exists, require it.require_once$file;} which adds an admin notice on admin pages if the file does not exist. |
Your code didn't work for me but it worked somehow when I added the code in a funcation and then used the if statement to process the error.