From f3c041e64eded765e93b7be2a5b949639756aae0 Mon Sep 17 00:00:00 2001 From: maheraldous <41970874+maheraldous@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:21:53 +0200 Subject: [PATCH] Update README.md 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. --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e93ee50..e8e2597 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,18 @@ add_action( 'after_setup_theme', 'register_navwalker' ); If you encounter errors with the above code use a check like this to return clean errors to help diagnose the problem. ```php -if ( ! file_exists( get_template_directory() . '/class-wp-bootstrap-navwalker.php' ) ) { - // File does not exist... return an error. - return new WP_Error( 'class-wp-bootstrap-navwalker-missing', __( 'It appears the class-wp-bootstrap-navwalker.php file may be missing.', 'wp-bootstrap-navwalker' ) ); +if ( !file_exists( get_template_directory() . '/class-wp-bootstrap-navwalker.php' ) ) { + // file does not exist, return an error. + function our_error() { + return new WP_Error( 'broke', __( 'class-wp-bootstrap-navwalker.php file may be missing', 'wp-bootstrap-navwalker' ) ); + } + $return = our_error(); + if( is_wp_error( $return ) ) { + echo $return->get_error_message(); + } } else { - // File exists... require it. - require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php'; + // file exists, require it. + require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php'; } ```