Completed
Pull Request — master (#8)
by
unknown
01:29
created

helper-functions.php ➔ DNH()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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
function DNH() {
30
	return Dismissible_Notices_Handler::instance();
31
}
32
33
/**
34
 * Register a new notice
35
 *
36
 * @since 1.0
37
 *
38
 * @param string $id      Notice ID, used to identify it
39
 * @param string $type    Type of notice to display
40
 * @param string $content Notice content
41
 * @param array  $args    Additional parameters
42
 *
43
 * @return bool
44
 */
45
function dnh_register_notice( $id, $type, $content, $args = array() ) {
46
47
	if ( ! function_exists( 'DNH' ) ) {
48
		return false;
49
	}
50
51
	/**
52
	 * Get the library running
53
	 */
54
	DNH();
55
56
	return DNH()->register_notice( $id, $type, $content, $args );
57
58
}
59
60
/**
61
 * Restore a previously dismissed notice
62
 *
63
 * @since 1.0
64
 *
65
 * @param string $id ID of the notice to restore
66
 *
67
 * @return bool
68
 */
69
function dnh_restore_notice( $id ) {
70
71
	if ( ! function_exists( 'DNH' ) ) {
72
		return false;
73
	}
74
75
	/**
76
	 * Get the library running
77
	 */
78
	DNH();
79
80
	return DNH()->restore_notice( $id );
81
82
}
83
84
/**
85
 * Check if a notice has been dismissed
86
 *
87
 * @since 1.0
88
 *
89
 * @param string $id ID of the notice to check
90
 *
91
 * @return bool
92
 */
93
function dnh_is_dismissed( $id ) {
94
95
	if ( ! function_exists( 'DNH' ) ) {
96
		return false;
97
	}
98
99
	/**
100
	 * Get the library running
101
	 */
102
	DNH();
103
104
	return DNH()->is_dismissed( $id );
105
106
}
107