Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 109
Messages
ОглавлениеWhen an action occurs in your plugin, such as saving settings, it's important to display a message to the user verifying whether the update was successful. WordPress features some different styles for displaying these messages.
<?php function pdev_styling_settings() { ?> <div class="notice notice-error is-dismissible"> <p>There has been an error.</p> </div> <div class="notice notice-warning is-dismissible"> <p>This is a warning message.</p> </div> <div class="notice notice-success is-dismissible"> <p>This is a success message.</p> </div> <div class="notice notice-info is-dismissible"> <p>This is some information.</p> </div> <?php } ?>
As you can see, there are four different types of notices supported: error, warning, success, and info. Notice the class, is‐dismissible
, included in the outer <div>
element. This class makes the admin notice “dismissable,” meaning a small x is displayed, and when it's clicked, the notice will disappear. When an admin notice is not dismissible, the only way to remove it is to reload the page.
These styles will generate the messages shown in Figure 3‐10.
FIGURE 3‐10: Dismissable notices