Source Code Documentation


s2member\includes\classes\admin-notices.inc.php


  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. 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 /* Unset defined __refs, __v. */ ($__refs, $__v);
  48.  
  49. if /* If we have a valid string. */(is_string ($notice) && $notice)
  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. 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 /* Unset defined __refs, __v. */ ($__refs, $__v);
  58.  
  59. update_option ("ws_plugin__s2member_notices", c_ws_plugin__s2member_utils_arrays::array_unique ($notices));
  60. }
  61. do_action ("ws_plugin__s2member_after_enqueue_admin_notice", get_defined_vars ());
  62.  
  63. return /* Return for uniformity. */;
  64. }
  65. /**
  66. * Displays an administrative notice.
  67. *
  68. * @package s2Member\Admin_Notices
  69. * @since 3.5
  70. *
  71. * @param str $notice String value of actual notice *(i.e. the message)*.
  72. * @param bool $error Optional. True if this notice is regarding an error. Defaults to false.
  73. * @param bool $dismiss Optional. If true, the notice will be displayed with a dismissal link. Defaults to false.
  74. * @return null
  75. */
  76. public static function display_admin_notice ($notice = FALSE, $error = FALSE, $dismiss = FALSE)
  77. {
  78. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  79. do_action ("ws_plugin__s2member_before_display_admin_notice", get_defined_vars ());
  80. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  81.  
  82. if /* Slightly different/special format for errors. */ (is_string ($notice) && $notice && $error)
  83. {
  84. $notice .= ($dismiss) ? ' [ <a href="' . esc_attr(add_query_arg ("ws-plugin--s2member-dismiss-admin-notice", urlencode (md5 ($notice)), $_SERVER["REQUEST_URI"])) . '">dismiss message</a> ]' : '';
  85.  
  86. echo /* Error. */ '<div class="error fade"><p>' . $notice . '</p></div>';
  87. }
  88. else if (is_string ($notice) && $notice)
  89. {
  90. $notice .= ($dismiss) ? ' [ <a href="' . esc_attr(add_query_arg ("ws-plugin--s2member-dismiss-admin-notice", urlencode (md5 ($notice)), $_SERVER["REQUEST_URI"])) . '">dismiss message</a> ]' : '';
  91.  
  92. echo '<div class="updated fade"><p>' . $notice . '</p></div>';
  93. }
  94. do_action ("ws_plugin__s2member_after_display_admin_notice", get_defined_vars ());
  95.  
  96. return /* Return for uniformity. */;
  97. }
  98. /**
  99. * Processes all administrative notices.
  100. *
  101. * @package s2Member\Admin_Notices
  102. * @since 3.5
  103. *
  104. * @attaches-to ``add_action("admin_notices");``
  105. * @attaches-to ``add_action("user_admin_notices");``
  106. * @attaches-to ``add_action("network_admin_notices");``
  107. * @todo Update to ``add_action("all_admin_notices");``.
  108. *
  109. * @return null
  110. */
  111. public static function admin_notices ()
  112. {
  113. global /* This holds the current page filename. */ $pagenow;
  114.  
  115. do_action ("ws_plugin__s2member_before_admin_notices", get_defined_vars ());
  116.  
  117. if (is_admin () && is_array ($notices = get_option ("ws_plugin__s2member_notices")) && !empty ($notices))
  118. {
  119. $a = (is_blog_admin ()) ? "blog" : $a;
  120. $a = (is_user_admin ()) ? "user" : $a;
  121. $a = (is_network_admin ()) ? "network" : $a;
  122. $a = /* Default Blog Admin. */(!$a) ? "blog" : $a;
  123.  
  124. foreach /* Check several things about each Notice. */ ($notices as $i => $notice)
  125. foreach (((!$notice["on_pages"]) ? array ("*"): (array)$notice["on_pages"]) as $page)
  126. {
  127. if /* NO prefix? */ (!preg_match ("/^(.+?)\:/", $page))
  128. $page = /* `blog:` */ "blog:" . ltrim ($page, ":");
  129.  
  130. $adms = preg_split ("/\|/", preg_replace ("/\:(.*)$/i", "", $page));
  131. $page = preg_replace ("/^([^\:]*)\:/i", "", $page);
  132.  
  133. if (empty ($adms) || in_array ("*", $adms) || in_array ($a, $adms))
  134. if (!$page || "*" === $page || $pagenow === $page || $_GET["page"] === $page)
  135. {
  136. if /* Time to show it? */ (strtotime ("now") >= (int)$notice["time"])
  137. {
  138. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  139. do_action ("ws_plugin__s2member_during_admin_notices_before_display", get_defined_vars ());
  140. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  141.  
  142. if (!$notice["dismiss"] || (!empty ($_GET["ws-plugin--s2member-dismiss-admin-notice"]) && $_GET["ws-plugin--s2member-dismiss-admin-notice"] === md5 ($notice["notice"])))
  143. unset /* Clear this administrative notice now? */($notices[$i]);
  144.  
  145. if (!$notice["dismiss"] || empty ($_GET["ws-plugin--s2member-dismiss-admin-notice"]) || $_GET["ws-plugin--s2member-dismiss-admin-notice"] !== md5 ($notice["notice"]))
  146. c_ws_plugin__s2member_admin_notices::display_admin_notice ($notice["notice"], $notice["error"], $notice["dismiss"]);
  147.  
  148. do_action ("ws_plugin__s2member_during_admin_notices_after_display", get_defined_vars ());
  149. }
  150. continue /* This Notice processed; continue. */ 2;
  151. }
  152. }
  153. $notices = /* Re-index array. */array_merge ($notices);
  154.  
  155. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  156. do_action ("ws_plugin__s2member_during_admin_notices", get_defined_vars ());
  157. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  158.  
  159. update_option ("ws_plugin__s2member_notices", $notices);
  160. }
  161. do_action ("ws_plugin__s2member_after_admin_notices", get_defined_vars ());
  162.  
  163. return /* Return for uniformity. */;
  164. }
  165. }
  166. }
  167. ?>

s2member\includes\classes\admin-notices.inc.php

Source Code Documentation