wordpress plugin error handling

WordPress have WP_Error class for checking WordPress errors and error messages since version 2.1.0. WordPress use object of WP_Error class for reporting error from several WP function. However, we can use this object in plugin or theme to handle error within WordPress. This class containing verious useful method for managing error. All methods <?php //Creating … Read more

Showing error “Function create_function() is deprecated”

Problem lies in your theme. It’s not compatible with PHP 7.2. In this version the create_function is deprecated and you should use Anonymous Functions instead. So for example instead of something like this: $callback = create_function(”, ‘echo “‘.str_replace(‘”‘, ‘\”‘, $section[‘desc’]).'”;’); You should use this: $callback = function() { echo str_replace(‘”‘, ‘\”‘, $section[‘desc’]); };

Changing the Database Connection Error Message

Basically, if you create a PHP file named db-error.php and put under /wp-content/, you’ll get what db-error.php will have. Here is my template on CodePen. This is example : <?php header(‘HTTP/1.1 503 Service Temporarily Unavailable’); header(‘Status: 503 Service Temporarily Unavailable’); header(‘Retry-After: 3600’); // 1 hour = 3600 seconds mail(“[email protected]”, “Database Error”, “There is a problem … Read more

How to throw error to user when saving post

You can use admin_notices hook http://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices For example: function ravs_admin_notice() { ?> <div class=”error”> <p><?php _e( ‘Article with this title is not found!’, ‘my-text-domain’ ); ?></p> </div> <?php } on publish_{your_custom_post_type} hook http://codex.wordpress.org/Post_Status_Transitions function on_post_publish( $ID, $post ) { // A function to perform actions when a {your_custom_post_type} is published. $post_exists = $wpdb->get_row(“SELECT post_name FROM … Read more