PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / redux / ReduxCore / inc / class.redux_admin_notices.php

class.redux_admin_notices.php in QuadMenu – Mega Menu 3.3.8, at redux/ReduxCore/inc/class.redux_admin_notices.php

203 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Redux Framework Admin Notice Class
5 * Makes instantiating a Redux object an absolute piece of cake.
6 *
7 * @package Redux_Framework
8 * @author Kevin Provance
9 * @author Dovy Paukstys
10 * @subpackage Core
11 */
12
13 // Exit if accessed directly
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 // Don't duplicate me!
19 if ( ! class_exists( 'ReduxLegacy_Admin_Notices' ) ) {
20
21 /**
22 * Redux API Class
23 * Simple API for Redux Framework
24 *
25 * @since 1.0.0
26 */
27 class ReduxLegacy_Admin_Notices {
28
29 public static $_parent;
30
31 public static function load() {
32 add_action(
33 'wp_ajax_redux_hide_admin_notice',
34 array(
35 'ReduxLegacy_Admin_Notices',
36 'dismissAdminNoticeAJAX',
37 )
38 );
39 }
40
41 public static function set_notice( $data ) {
42 extract( $data );
43
44 $parent->admin_notices[ $parent->args['page_slug'] ][] = array(
45 'type' => $type,
46 'msg' => $msg,
47 'id' => $id . '_' . $parent->args['opt_name'],
48 'dismiss' => $dismiss,
49 'color' => isset( $color ) ? $color : '#00A2E3',
50 );
51 }
52
53 /**
54 * adminNotices - Evaluates user dismiss option for displaying admin notices
55 *
56 * @since 3.2.0
57 * @access public
58 * @return void
59 */
60 public static function adminNotices( $parent, $notices = array() ) {
61 global $current_user, $pagenow, $wp_version;
62
63 // Check for an active admin notice array
64 if ( ! empty( $notices ) ) {
65
66 if ( isset( $_GET ) && isset( $_GET['page'] ) && $_GET['page'] == $parent->args['page_slug'] ) {
67
68 // Enum admin notices
69 foreach ( $notices[ $parent->args['page_slug'] ] as $notice ) {
70
71 $add_style = '';
72 if ( strpos( $notice['type'], 'redux-message' ) != false ) {
73 $add_style = 'style="border-left: 4px solid ' . esc_attr( $notice['color'] ) . '!important;"';
74 }
75
76 if ( true == $notice['dismiss'] ) {
77
78 // Get user ID
79 $userid = $current_user->ID;
80
81 if ( ! get_user_meta( $userid, 'ignore_' . $notice['id'] ) ) {
82
83 // Check if we are on admin.php. If we are, we have
84 // to get the current page slug and tab, so we can
85 // feed it back to WordPress. Why> admin.php cannot
86 // be accessed without the page parameter. We add the
87 // tab to return the user to the last panel they were
88 // on.
89 $pageName = '';
90 $curTab = '';
91
92 if ( $pagenow == 'admin.php' || $pagenow == 'themes.php' ) {
93
94 // Get the current page. To avoid errors, we'll set
95 // the redux page slug if the GET is empty.
96 $pageName = empty( $_GET['page'] ) ? '&amp;page=' . $parent->args['page_slug'] : '&amp;page=' . esc_attr( $_GET['page'] );
97
98 // Ditto for the current tab.
99 $curTab = empty( $_GET['tab'] ) ? '&amp;tab=0' : '&amp;tab=' . esc_attr( $_GET['tab'] );
100 }
101
102 // Print the notice with the dismiss link
103 if ( version_compare( $wp_version, '4.2', '>' ) ) {
104 $output = '';
105 $css_id = esc_attr( $notice['id'] ) . $pageName . $curTab;
106 $css_class = esc_attr( $notice['type'] ) . ' redux-notice notice is-dismissible redux-notice';
107 $output .= "<div {$add_style} id='$css_id' class='$css_class'> \n";
108 $nonce = wp_create_nonce( $notice['id'] . $userid . 'nonce' );
109 $output .= "<input type='hidden' class='dismiss_data' id='" . esc_attr( $notice['id'] ) . $pageName . $curTab . "' value='{$nonce}'> \n";
110 $output .= '<p>' . wp_kses_post( $notice['msg'] ) . '</p>';
111 $output .= "</div> \n";
112 echo $output;
113 } else {
114 echo '<div ' . $add_style . ' class="' . esc_attr( $notice['type'] ) . ' notice is-dismissable"><p>' . wp_kses_post( $notice['msg'] ) . '&nbsp;&nbsp;<a href="?dismiss=true&amp;id=' . esc_attr( $notice['id'] ) . $pageName . $curTab . '">' . esc_html__( 'Dismiss', 'redux-framework' ) . '</a>.</p></div>';
115 }
116 }
117 } else {
118 // Standard notice
119 echo '<div ' . $add_style . ' class="' . esc_attr( $notice['type'] ) . ' notice"><p>' . wp_kses_post( $notice['msg'] ) . '</a>.</p></div>';
120 }
121 ?>
122 <script>
123 jQuery( document ).ready(
124 function( $ ) {
125 $( 'body' ).on(
126 'click', '.redux-notice.is-dismissible .notice-dismiss', function( event ) {
127 var $data = $( this ).parent().find( '.dismiss_data' );
128 $.post(
129 ajaxurl, {
130 action: 'redux_hide_admin_notice',
131 id: $data.attr( 'id' ),
132 nonce: $data.val()
133 }
134 );
135 }
136 );
137 }
138 );
139 </script>
140 <?php
141 }
142 }
143
144 // Clear the admin notice array
145 $parent->admin_notices[ $parent->args['opt_name'] ] = array();
146 }
147 }
148
149 /**
150 * dismissAdminNotice - Updates user meta to store dismiss notice preference
151 *
152 * @since 3.2.0
153 * @access public
154 * @return void
155 */
156 public static function dismissAdminNotice() {
157 global $current_user;
158
159 // Verify the dismiss and id parameters are present.
160 if ( isset( $_GET['dismiss'] ) && isset( $_GET['id'] ) ) {
161 if ( 'true' == $_GET['dismiss'] || 'false' == $_GET['dismiss'] ) {
162
163 // Get the user id
164 $userid = $current_user->ID;
165
166 // Get the notice id
167 $id = esc_attr( $_GET['id'] );
168 $val = esc_attr( $_GET['dismiss'] );
169
170 // Add the dismiss request to the user meta.
171 update_user_meta( $userid, 'ignore_' . $id, $val );
172 }
173 }
174 }
175
176 /**
177 * dismissAdminNotice - Updates user meta to store dismiss notice preference
178 *
179 * @since 3.2.0
180 * @access public
181 * @return void
182 */
183 public static function dismissAdminNoticeAJAX() {
184 global $current_user;
185
186 // Get the notice id
187 $id = explode( '&', $_POST['id'] );
188 $id = $id[0];
189 // Get the user id
190 $userid = $current_user->ID;
191
192 if ( ! wp_verify_nonce( $_POST['nonce'], $id . $userid . 'nonce' ) ) {
193 die( 0 );
194 } else {
195 // Add the dismiss request to the user meta.
196 update_user_meta( $userid, 'ignore_' . $id, true );
197 }
198 }
199 }
200
201 ReduxLegacy_Admin_Notices::load();
202 }
203