Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show warning/error to user without using wp_die

Tags:

php

wordpress

I'm currently developing a Wordpress plugin. For my plugin to work I need some info te be filled in on the settings page.

  1. Is there a way to warn/throw an error so the blog admin can see this message on his/her dashboard?
  2. Is there another function to show errors other than wp_die()? Just in case my plugin (or someone else) screws up and I want to notify that in a nicely fashion. ;)
like image 215
Tuxified Avatar asked Jun 17 '26 13:06

Tuxified


1 Answers

I would recommend using the admin_notices action. This lets you display warnings and errors and direct your users to a page:

add_action('admin_notices','my_custom_warning');
function my_custom_warning() {
  if( true == true ) {
    echo '<div id="my-custom-warning" class="error fade"><p>This is a test</p></div>';
  }
}

This method makes sure your users can still use WordPress but will let them know where they can get information on and fix a potential problem.

like image 183
nickohrn Avatar answered Jun 19 '26 05:06

nickohrn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!