PluginProbe
Tag Groups is the Advanced Way to Display Your Taxonomy Terms / trunk
Tag Groups is the Advanced Way to Display Your Taxonomy Terms vtrunk
2.2.2 2.2.1 2.2.0 trunk 1.40.0 1.40.2 1.41.0 1.42.1 1.43.0 1.43.1 1.43.10 1.43.10.1 1.43.2 1.43.3 1.43.4 1.43.5 1.43.6 1.43.7 1.43.9 1.44.0 1.44.1 1.44.3 1.44.3.1 2.0.0 2.0.1 All 36 releases
tag-groups / include / admin / class.admin_notice.php

class.admin_notice.php in Tag Groups is the Advanced Way to Display Your Taxonomy Terms trunk, at include/admin/class.admin_notice.php

101 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Tag Groups Pro
5 *
6 * @package Tag Groups Pro
7 * @author Christoph Amthor
8 * @copyright 2017 Christoph Amthor (@ Chatty Mango, chattymango.com)
9 * @license see official vendor website
10 *
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18 * THE SOFTWARE.
19 *
20 */
21
22 if (! class_exists('TagGroups_Admin_Notice')) {
23 // phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps -- Legacy class structure
24 class TagGroups_Admin_Notice
25 {
26 public function __construct()
27 {
28 }
29
30 /**
31 * Add an admin notice to the queue
32 *
33 * @param string $type One of: error, info
34 * @param string $content with HTML
35 * @return void
36 */
37 public static function add($type, $content)
38 {
39
40 $notices = TagGroups_Options::get_option('tag_group_admin_notice', array());
41 /**
42 * Avoid duplicate entries
43 */
44 $found = false;
45 foreach ($notices as $notice) {
46 if ($notice['type'] == $type && $notice['content'] == $content) {
47 $found = true;
48 break;
49 }
50 }
51
52 if (! $found) {
53 $notices[] = array(
54 'type' => $type,
55 'content' => $content
56 );
57 TagGroups_Options::update_option('tag_group_admin_notice', $notices);
58 }
59 }
60
61
62 /**
63 * Check if an admin notice is pending and, if necessary, display it
64 *
65 * @param void
66 * @return void
67 */
68 public static function display()
69 {
70
71 $notices = TagGroups_Options::get_option('tag_group_admin_notice', array());
72 if (! empty($notices)) {
73 foreach ($notices as $notice) {
74 if ('cache' == $notice['type']) {
75 $notice['type'] = 'info';
76 $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
77 $ajax_link = admin_url('admin-ajax.php?', $protocol);
78 } else {
79 $ajax_link = '';
80 }
81
82 // wrap the message in <p></p> if not already a complex formatting
83 if (strpos('<p>', $notice['content']) === false) {
84 $notice['content'] = '<p>' . $notice['content'] . '</p>';
85 }
86
87 $view = new TagGroups_View('partials/admin_notice');
88 $view->set(array(
89 'ajax_link' => $ajax_link,
90 'notice' => $notice,
91 ));
92 $view->render();
93 }
94
95 update_option('tag_group_admin_notice', array());
96 }
97 }
98 }
99
100 }
101