PluginProbe
QuadMenu – Mega Menu / 1.8.9
QuadMenu – Mega Menu v1.8.9
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 / lib / ReduxCore / inc / class.redux_admin_notices.php

class.redux_admin_notices.php in QuadMenu – Mega Menu 1.8.9, at lib/ReduxCore/inc/class.redux_admin_notices.php

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