helper-functions.php ➔ dnh_restore_notice()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * Dismissible Notices Handler.
4
 *
5
 * LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6
 * General Public License as published by the Free Software Foundation; either version 3 of the License, or (at
7
 * your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
8
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9
 * General Public License for more details. You should have received a copy of the GNU General Public License along
10
 * with this program. If not, see <http://opensource.org/licenses/gpl-license.php>
11
 *
12
 * @package   Dismissible Notices Handler/Helper Functions
13
 * @author    Julien Liabeuf <[email protected]>
14
 * @version   1.0
15
 * @license   GPL-2.0+
16
 * @link      https://julienliabeuf.com
17
 * @copyright 2016 Julien Liabeuf
18
 */
19
20
/**
21
 * The main function responsible for returning the unique Dismissible Notices Handler instance
22
 *
23
 * Use this function like you would a global variable, except without needing
24
 * to declare the global.
25
 *
26
 * @since 1.0
27
 * @return object Dismissible_Notices_Handler
28
 */
29
30
if ( ! function_exists( 'DNH' ) ) {
31
	function DNH() {
32
		return Dismissible_Notices_Handler::instance();
33
	}
34
}
35
36
if ( ! function_exists( 'dnh_register_notice' ) ) {
37
	/**
38
	 * Register a new notice
39
	 *
40
	 * @since 1.0
41
	 *
42
	 * @param string $id      Notice ID, used to identify it
43
	 * @param string $type    Type of notice to display
44
	 * @param string $content Notice content
45
	 * @param array  $args    Additional parameters
46
	 *
47
	 * @return bool
48
	 */
49
	function dnh_register_notice( $id, $type, $content, $args = array() ) {
50
51
		if ( ! function_exists( 'DNH' ) ) {
52
			return false;
53
		}
54
55
		/**
56
		 * Get the library running
57
		 */
58
		DNH();
59
60
		return DNH()->register_notice( $id, $type, $content, $args );
61
62
	}
63
}
64
65
if ( ! function_exists( 'dnh_restore_notice' ) ) {
66
	/**
67
	 * Restore a previously dismissed notice
68
	 *
69
	 * @since 1.0
70
	 *
71
	 * @param string $id ID of the notice to restore
72
	 *
73
	 * @return bool
74
	 */
75
	function dnh_restore_notice( $id ) {
76
77
		if ( ! function_exists( 'DNH' ) ) {
78
			return false;
79
		}
80
81
		/**
82
		 * Get the library running
83
		 */
84
		DNH();
85
86
		return DNH()->restore_notice( $id );
87
88
	}
89
}
90
91
if ( ! function_exists( 'dnh_is_dismissed' ) ) {
92
	/**
93
	 * Check if a notice has been dismissed
94
	 *
95
	 * @since 1.0
96
	 *
97
	 * @param string $id ID of the notice to check
98
	 *
99
	 * @return bool
100
	 */
101
	function dnh_is_dismissed( $id ) {
102
103
		if ( ! function_exists( 'DNH' ) ) {
104
			return false;
105
		}
106
107
		/**
108
		 * Get the library running
109
		 */
110
		DNH();
111
112
		return DNH()->is_dismissed( $id );
113
114
	}
115
}
116