Source Code Documentation


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


  1. <?php
  2. /**
  3. * Locks Users/Members out of admin panels.
  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_Lockouts
  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_lockouts"))
  21. {
  22. /**
  23. * Locks Users/Members out of admin panels.
  24. *
  25. * @package s2Member\Admin_Lockouts
  26. * @since 3.5
  27. */
  28. class c_ws_plugin__s2member_admin_lockouts
  29. {
  30. /**
  31. * Locks Users/Members out of admin panels.
  32. *
  33. * @package s2Member\Admin_Lockouts
  34. * @since 3.5
  35. *
  36. * @attaches-to ``add_action("admin_init");``
  37. *
  38. * @return null Or exits script execution after redirection.
  39. */
  40. public static function admin_lockout ()
  41. {
  42. do_action ("ws_plugin__s2member_before_admin_lockouts", get_defined_vars ());
  43.  
  44. if (is_admin () && (!defined ("DOING_AJAX") || !DOING_AJAX) && !current_user_can ("edit_posts") /* Give Filters a chance here too. */)
  45. if (apply_filters ("ws_plugin__s2member_admin_lockout", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"], get_defined_vars ()))
  46. {
  47. if ($redirection_url = c_ws_plugin__s2member_login_redirects::login_redirection_url ())
  48. /* Special Redirection. */wp_redirect ($redirection_url) . exit ();
  49.  
  50. else // Else we use the Login Welcome Page configured for s2Member.
  51. wp_redirect (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"])) . exit ();
  52. }
  53. do_action ("ws_plugin__s2member_after_admin_lockouts", get_defined_vars ());
  54.  
  55. return /* Return for uniformity. */;
  56. }
  57. /**
  58. * Filters administrative menu bar for Users/Members.
  59. *
  60. * @package s2Member\Admin_Lockouts
  61. * @since 3.5
  62. *
  63. * @attaches-to ``add_action("admin_bar_menu");``
  64. *
  65. * @param obj $wp_admin_bar Expects the ``$wp_admin_bar``, by reference; passed in by the Action Hook.
  66. * @return null After modifying ``$wp_admin_var``.
  67. */
  68. public static function filter_admin_menu_bar (&$wp_admin_bar = FALSE)
  69. {
  70. do_action ("ws_plugin__s2member_before_filter_admin_menu_bar", get_defined_vars ());
  71.  
  72. $uses_nodes = (version_compare (get_bloginfo ("version"), "3.3-RC1", ">=")) ? true : false;
  73.  
  74. if (is_object ($wp_admin_bar) && !current_user_can ("edit_posts") /* Always for Users/Members. */)
  75. {
  76. if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("site-name"))
  77. {
  78. $id = /* Give this a special/unique ID. */ "s2-site-name";
  79. $title = wp_html_excerpt /* A brief excerpt. */ (get_bloginfo ("name"), 42);
  80. $title = ($title !== get_bloginfo ("name")) ? trim ($title) . "&hellip;" : $title;
  81. $href = /* Change to front page. */ site_url ("/");
  82.  
  83. $wp_admin_bar->add_node (array ("id" => $id, "title" => $title, "href" => $href));
  84. $wp_admin_bar->remove_node /* Ditch now, replacing this. */ ("site-name");
  85.  
  86. unset /* A little housekeeping. */ ($id, $title, $href);
  87. }
  88. if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("wp-logo"))
  89. $wp_admin_bar->remove_node /* Ditch this node. */ ("wp-logo");
  90. // -------
  91. if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"dashboard"}))
  92. unset /* Ditch this item. */ ($wp_admin_bar->menu->{"dashboard"});
  93.  
  94. if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-blogs"}))
  95. unset /* Ditch this item. */ ($wp_admin_bar->menu->{"my-blogs"});
  96. // -------
  97. if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("my-sites"))
  98. $wp_admin_bar->remove_node /* Ditch this node. */ ("my-sites");
  99. }
  100. if (is_object ($wp_admin_bar) && !current_user_can ("edit_posts") /* If locking Users/Members out of `/wp-admin/` areas. */)
  101. if (apply_filters ("ws_plugin__s2member_admin_lockout", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"], get_defined_vars ()))
  102. {
  103. $lwp = c_ws_plugin__s2member_login_redirects::login_redirection_url ();
  104. $lwp = (!$lwp) ? get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]) : $lwp;
  105.  
  106. if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("my-account"))
  107. $wp_admin_bar->add_node /* Update this node. */ (array ("id" => "my-account", "href" => $lwp));
  108.  
  109. if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("user-info"))
  110. $wp_admin_bar->add_node /* Update this node. */ (array ("id" => "user-info", "href" => $lwp));
  111.  
  112. if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("edit-profile"))
  113. $wp_admin_bar->add_node /* Update this node. */ (array ("id" => "edit-profile", "href" => $lwp));
  114. // -------
  115. if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account"}["href"]))
  116. $wp_admin_bar->menu->{"my-account"}["href"] = /* Update this item. */ $lwp;
  117.  
  118. if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account"}["children"]->{"edit-profile"}["href"]))
  119. $wp_admin_bar->menu->{"my-account"}["children"]->{"edit-profile"}["href"] = /* Update this item. */ $lwp;
  120.  
  121. if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account"}["children"]->{"user-info"}["href"]))
  122. $wp_admin_bar->menu->{"my-account"}["children"]->{"user-info"}["href"] = /* Update this item. */ $lwp;
  123. // -------
  124. if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account-with-avatar"}["href"]))
  125. $wp_admin_bar->menu->{"my-account-with-avatar"}["href"] = /* Update this item. */ $lwp;
  126.  
  127. if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"user-info"}["href"]))
  128. $wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"user-info"}["href"] = /* Update this item. */ $lwp;
  129.  
  130. if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"edit-profile"}["href"]))
  131. $wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"edit-profile"}["href"] = /* Update this item. */ $lwp;
  132. }
  133. do_action ("ws_plugin__s2member_after_filter_admin_menu_bar", get_defined_vars ());
  134.  
  135. return /* Return for uniformity. */;
  136. }
  137. }
  138. }
  139. ?>

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

Source Code Documentation