PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110815
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110815
260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 All 188 releases
s2member / includes / classes / admin-notices.inc.php

admin-notices.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110815, at includes/classes/admin-notices.inc.php

172 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Enqueues/displays administrative notices.
4 *
5 * Copyright: © 2009-2011
6 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
7 * ( coded in the USA )
8 *
9 * Released under the terms of the GNU General Public License.
10 * You should have received a copy of the GNU General Public License,
11 * along with this software. In the main directory, see: /licensing/
12 * If not, see: {@link http://www.gnu.org/licenses/}.
13 *
14 * @package s2Member\Admin_Notices
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_admin_notices"))
21 {
22 /**
23 * Enqueues/displays administrative notices.
24 *
25 * @package s2Member\Admin_Notices
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_admin_notices
29 {
30 /**
31 * Enqueues administrative notices.
32 *
33 * @package s2Member\Admin_Notices
34 * @since 3.5
35 *
36 * @param str $notice String value of actual notice *( i.e. the message )*.
37 * @param str|array $on_pages Optional. Defaults to any page. String or array of pages to display this notice on.
38 * @param bool $error Optional. True if this notice is regarding an error. Defaults to false.
39 * @param int $time Optional. Unix timestamp indicating when this notice will be displayed.
40 * @param bool $dismiss Optional. If true, the notice will remain persistent, until dismissed. Defaults to false.
41 * @return null
42 */
43 public static function enqueue_admin_notice ($notice = FALSE, $on_pages = FALSE, $error = FALSE, $time = FALSE, $dismiss = FALSE)
44 {
45 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
46 do_action ("ws_plugin__s2member_before_enqueue_admin_notice", get_defined_vars ());
47 unset ($__refs, $__v); /* Unset defined __refs, __v. */
48 /**/
49 if (is_string ($notice) && $notice) /* If we have a valid string. */
50 {
51 $notices = (array)get_option ("ws_plugin__s2member_notices");
52 /**/
53 array_push ($notices, array ("notice" => $notice, "on_pages" => $on_pages, "error" => $error, "time" => $time, "dismiss" => $dismiss));
54 /**/
55 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
56 do_action ("ws_plugin__s2member_during_enqueue_admin_notice", get_defined_vars ());
57 unset ($__refs, $__v); /* Unset defined __refs, __v. */
58 /**/
59 update_option ("ws_plugin__s2member_notices", c_ws_plugin__s2member_utils_arrays::array_unique ($notices));
60 }
61 /**/
62 do_action ("ws_plugin__s2member_after_enqueue_admin_notice", get_defined_vars ());
63 /**/
64 return; /* Return for uniformity. */
65 }
66 /**
67 * Displays an administrative notice.
68 *
69 * @package s2Member\Admin_Notices
70 * @since 3.5
71 *
72 * @param str $notice String value of actual notice *( i.e. the message )*.
73 * @param bool $error Optional. True if this notice is regarding an error. Defaults to false.
74 * @param bool $dismiss Optional. If true, the notice will be displayed with a dismissal link. Defaults to false.
75 * @return null
76 */
77 public static function display_admin_notice ($notice = FALSE, $error = FALSE, $dismiss = FALSE)
78 {
79 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
80 do_action ("ws_plugin__s2member_before_display_admin_notice", get_defined_vars ());
81 unset ($__refs, $__v); /* Unset defined __refs, __v. */
82 /**/
83 if (is_string ($notice) && $notice && $error) /* Slightly different/special format for errors. */
84 {
85 $notice .= ($dismiss) ? ' [ <a href="' . add_query_arg ("ws-plugin--s2member-dismiss-admin-notice", urlencode (md5 ($notice)), $_SERVER["REQUEST_URI"]) . '">dismiss message</a> ]' : '';
86 /**/
87 echo '<div class="error fade"><p>' . $notice . '</p></div>'; /* Error. */
88 }
89 else if (is_string ($notice) && $notice)
90 {
91 $notice .= ($dismiss) ? ' [ <a href="' . add_query_arg ("ws-plugin--s2member-dismiss-admin-notice", urlencode (md5 ($notice)), $_SERVER["REQUEST_URI"]) . '">dismiss message</a> ]' : '';
92 /**/
93 echo '<div class="updated fade"><p>' . $notice . '</p></div>';
94 }
95 /**/
96 do_action ("ws_plugin__s2member_after_display_admin_notice", get_defined_vars ());
97 /**/
98 return; /* Return for uniformity. */
99 }
100 /**
101 * Processes all administrative notices.
102 *
103 * @package s2Member\Admin_Notices
104 * @since 3.5
105 *
106 * @attaches-to ``add_action("admin_notices");``
107 * @attaches-to ``add_action("user_admin_notices");``
108 * @attaches-to ``add_action("network_admin_notices");``
109 * @todo Update to ``add_action("all_admin_notices");``.
110 *
111 * @return null
112 */
113 public static function admin_notices ()
114 {
115 global $pagenow; /* This holds the current page filename. */
116 /**/
117 do_action ("ws_plugin__s2member_before_admin_notices", get_defined_vars ());
118 /**/
119 if (is_admin () && is_array ($notices = get_option ("ws_plugin__s2member_notices")) && !empty ($notices))
120 {
121 $a = (is_blog_admin ()) ? "blog" : $a;
122 $a = (is_user_admin ()) ? "user" : $a;
123 $a = (is_network_admin ()) ? "network" : $a;
124 $a = (!$a) ? "blog" : $a; /* Default Blog Admin. */
125 /**/
126 foreach ($notices as $i => $notice) /* Check several things about each Notice. */
127 foreach (((!$notice["on_pages"]) ? array ("*"): (array)$notice["on_pages"]) as $page)
128 {
129 if (!preg_match ("/^(.+?)\:/", $page)) /* NO prefix? */
130 $page = "blog:" . ltrim ($page, ":"); /* `blog:` */
131 /**/
132 $adms = preg_split ("/\|/", preg_replace ("/\:(.*)$/i", "", $page));
133 $page = preg_replace ("/^([^\:]*)\:/i", "", $page);
134 /**/
135 if (empty ($adms) || in_array ("*", $adms) || in_array ($a, $adms))
136 if (!$page || "*" === $page || $pagenow === $page || $_GET["page"] === $page)
137 {
138 if (strtotime ("now") >= (int)$notice["time"]) /* Time to show it? */
139 {
140 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
141 do_action ("ws_plugin__s2member_during_admin_notices_before_display", get_defined_vars ());
142 unset ($__refs, $__v); /* Unset defined __refs, __v. */
143 /**/
144 if (!$notice["dismiss"] || (!empty ($_GET["ws-plugin--s2member-dismiss-admin-notice"]) && $_GET["ws-plugin--s2member-dismiss-admin-notice"] === md5 ($notice["notice"])))
145 unset($notices[$i]); /* Clear this administrative notice now? */
146 /**/
147 if (!$notice["dismiss"] || empty ($_GET["ws-plugin--s2member-dismiss-admin-notice"]) || $_GET["ws-plugin--s2member-dismiss-admin-notice"] !== md5 ($notice["notice"]))
148 c_ws_plugin__s2member_admin_notices::display_admin_notice ($notice["notice"], $notice["error"], $notice["dismiss"]);
149 /**/
150 do_action ("ws_plugin__s2member_during_admin_notices_after_display", get_defined_vars ());
151 }
152 /**/
153 continue 2; /* This Notice processed; continue. */
154 }
155 }
156 /**/
157 $notices = array_merge ($notices); /* Re-index array. */
158 /**/
159 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
160 do_action ("ws_plugin__s2member_during_admin_notices", get_defined_vars ());
161 unset ($__refs, $__v); /* Unset defined __refs, __v. */
162 /**/
163 update_option ("ws_plugin__s2member_notices", $notices);
164 }
165 /**/
166 do_action ("ws_plugin__s2member_after_admin_notices", get_defined_vars ());
167 /**/
168 return; /* Return for uniformity. */
169 }
170 }
171 }
172 ?>