Below, you’ll find a detailed guide on how to add the Hide Dashboard Notifications Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Hide Dashboard Notifications Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Hide Dashboard Notifications Plugin and the shortcodes it provides:
"Hide Dashboard Notifications is a WordPress plugin designed to create a cleaner, distraction-free admin area by removing unwanted backend notices."
- [warning_notices_settings]
Hide Dashboard Notifications [warning_notices_settings] Shortcode
The WP-Hide-Backend-Notices plugin shortcode enables users to manage warning notices settings. It allows you to hide dashboard warnings and update notices based on user roles.
Shortcode: [warning_notices_settings]
Examples and Usage
Basic example – Allows you to manage warning notices settings in your WordPress dashboard using the shortcode.
[warning_notices_settings /]
PHP Function Code
In case you have difficulties debugging what causing issues with [warning_notices_settings]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('warning_notices_settings', array($this, 'warning_notices_settings'));
Shortcode PHP function:
function warning_notices_settings() {
if (isset($_POST['save_notice_box'])) {
$roles = wp_roles()->get_names();
foreach ($roles as $role_val => $role) {
if (empty($_POST['hide_notice'][$role_val])) {
$_POST['hide_notice'][$role_val] = "All Users";
}
}
$manage_warnings_notice = serialize($_POST['hide_notice']);
update_option('manage_warnings_notice', $manage_warnings_notice);
echo "<meta http-equiv='refresh' content='0'>";
}
$custom_post_data = get_option('manage_warnings_notice');
if (!empty($custom_post_data)) {
$posts_from_db = unserialize($custom_post_data);
}
?>
<div class="main-wrap setting-top-wrap">
<div class="tab">
<?php
$settings = '';
$settings_dis = 'none';
if (empty($_GET['tab']) || $_GET['tab'] == 'settings') {
$settings = 'active';
$settings_dis = 'block';
}
?>
<button class="hide-tablinks-notices <?php echo $settings; ?>" onclick="openSettings(event, 'Settings', 'settings')" id="defaultOpen">
<img src="<?php echo plugin_dir_url(__FILE__) . 'images/hide-setting-white.png' ?>">
Settings
</button>
<?php
$roles = '';
$roles_dis = 'none';
if ($_GET['tab'] == 'roles') {
$roles = 'active';
$roles_dis = 'block';
}
?>
<button class="hide-tablinks-notices <?php echo $roles; ?>" onclick="openSettings(event, 'User-roles', 'roles')">
<img src="<?php echo plugin_dir_url(__FILE__) . 'images/hide-setting-white.png' ?>">
User roles
</button>
<?php
$notifications = '';
$notifications_dis = 'none';
if ($_GET['tab'] == 'notifications') {
$notifications = 'active';
$notifications_dis = 'block';
}
?>
<button class="hide-tablinks-notices <?php echo $notifications; ?>" onclick="openSettings(event, 'Notifications', 'notifications')">
<img src="<?php echo plugin_dir_url(__FILE__) . 'images/dash-hide-white.png' ?>">
Notifications
</button>
</div>
<form method="POST" class="gallery_meta_form" id="gallery_meta_form_id">
<div id="Settings" class="hide-tabcontent-notices" style="display: <?php echo $settings_dis; ?>;">
<h3>Select what you want to hide</h3>
<div class="outer-gallery-box">
<div class="checkboxes-manage" style="margin-top: 10px;">
<?php
$checked_notice = '';
if (!empty($posts_from_db) && $posts_from_db != '') {
if (in_array('Hide Notices', $posts_from_db)) {
$checked_notice = 'checked';
} else {
$checked_notice = '';
}
}
?>
<h4>Hide Dashboard Notices and Warnings</h4>
<label class="switch">
<input class="styled-checkbox" <?php echo $checked_notice; ?> id="Hide-Notices" name="hide_notice[Hide_Notices]" type="checkbox" value="Hide Notices">
<span class="slider round"></span>
</label>
<?php
$checked_update = '';
if (!empty($posts_from_db) && $posts_from_db != '') {
if (in_array('Hide Updates', $posts_from_db)) {
$checked_update = 'checked';
} else {
$checked_update = '';
}
}
?>
<h4>Hide WordPress Update Notices</h4>
<label class="switch">
<input class="styled-checkbox" <?php echo $checked_update; ?> id="Hide-Updates" name="hide_notice[Hide_Updates]" type="checkbox" value="Hide Updates">
<span class="slider round"></span>
</label>
<?php
$checked_update = '';
if (!empty($posts_from_db) && $posts_from_db != '') {
if (in_array('Hide PHP Updates', $posts_from_db)) {
$checked_update = 'checked';
} else {
$checked_update = '';
}
}
?>
<h4> Hide PHP Update Required Notice</h4>
<label class="switch">
<input class="styled-checkbox" <?php echo $checked_update; ?> id="hide-php-updates" name="hide_notice[Hide_PHP_Updates]" type="checkbox" value="Hide PHP Updates">
<span class="slider round"></span>
</label>
</div>
<div class="save_btn_wrapper">
<input type="submit" name="save_notice_box" id="save_post_gallery_box_id" class="save_post_gallery_box_cls" value="Save">
</div>
</div>
</div>
<!--User Role Tab-->
<div id="User-roles" class="hide-tabcontent-notices" style="display: <?php echo $roles_dis; ?>;">
<h3>Select user role for whome you want to hide notifications.</h3>
<div class="outer-gallery-box">
<div class="checkboxes-manage" style="margin-top: 10px;">
<!-- for adminstrators -->
<?php
$roles = wp_roles()->get_names();
foreach ($roles as $role_val => $role) {
$AccessedBy = '';
if (!empty($posts_from_db) && $posts_from_db != '') {
if (in_array($role_val, $posts_from_db)) {
$AccessedBy = 'checked';
} else {
$AccessedBy = '';
}
}
?>
<h4>Enable for <b><?php echo $role; ?></b> role</h4>
<label class="switch">
<input class="styled-checkbox" <?php echo $AccessedBy; ?> class="Hide-Accesse" name="hide_notice[<?php echo $role_val; ?>]" type="checkbox" value="<?php echo $role_val; ?>">
<span class="slider round"></span>
</label>
<?php
}
?>
<!-- end roles -->
</div>
<div class="save_btn_wrapper">
<input type="submit" name="save_notice_box" id="save_post_gallery_box_id" class="save_post_gallery_box_cls" value="Save">
</div>
</div>
</div>
</form>
<!--Notification Tab-->
<div id="Notifications" class="hide-tabcontent-notices" style="display: <?php echo $notifications_dis; ?>;">
<h3>Dashboard notifications</h3>
<?php
if (!empty($posts_from_db) && $posts_from_db != '') {
if (in_array('Hide Notices', $posts_from_db)) {
do_action('admin_notices');
}
}
?>
</div>
<!-- end -->
</div>
<?php
}
Code file location:
wp-hide-backed-notices/wp-hide-backed-notices/admin/class-wp-hide-backed-notices-admin.php
Conclusion
Now that you’ve learned how to embed the Hide Dashboard Notifications Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply