| 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 () /* Prevents admin access. */ |
| 41 |
{ |
| 42 |
do_action ("ws_plugin__s2member_before_admin_lockouts", get_defined_vars ()); |
| 43 |
/**/ |
| 44 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"] /* Now check for these WordPress® functionality Constants too. */ |
| 45 |
&& (!defined ("XMLRPC_REQUEST") || !XMLRPC_REQUEST) && (!defined ("APP_REQUEST") || !APP_REQUEST) && (!defined ("DOING_AJAX") || !DOING_AJAX)/**/ |
| 46 |
&& !current_user_can ("edit_posts")) /* And only if the current User is unable to edit Posts; otherwise we allow them in. */ |
| 47 |
if (apply_filters ("ws_plugin__s2member_admin_lockout", true, get_defined_vars ())) /* Give Filters a chance too. */ |
| 48 |
{ |
| 49 |
if ($special_redirection_url = c_ws_plugin__s2member_login_redirects::login_redirection_url ()) |
| 50 |
wp_redirect ($special_redirection_url); /* Special Redirection. */ |
| 51 |
/**/ |
| 52 |
else /* Else we use the Login Welcome Page configured for s2Member. */ |
| 53 |
wp_redirect (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"])); |
| 54 |
/**/ |
| 55 |
exit (); /* Clean exit. */ |
| 56 |
} |
| 57 |
/**/ |
| 58 |
do_action ("ws_plugin__s2member_after_admin_lockouts", get_defined_vars ()); |
| 59 |
/**/ |
| 60 |
return; /* Return for uniformity. */ |
| 61 |
} |
| 62 |
/** |
| 63 |
* Filters administrative menu bars. |
| 64 |
* |
| 65 |
* @package s2Member\Admin_Lockouts |
| 66 |
* @since 3.5 |
| 67 |
* |
| 68 |
* @attaches-to ``add_action("admin_bar_menu");`` |
| 69 |
* |
| 70 |
* @param obj $wp_admin_bar Expects the ``$wp_admin_bar``, by reference; passed in by the Action Hook. |
| 71 |
* @return null After modifying ``$wp_admin_var``. |
| 72 |
*/ |
| 73 |
public static function filter_admin_menu_bar (&$wp_admin_bar = FALSE) |
| 74 |
{ |
| 75 |
do_action ("ws_plugin__s2member_before_filter_admin_menu_bar", get_defined_vars ()); |
| 76 |
/**/ |
| 77 |
if (is_object ($wp_admin_bar) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"] /* Now check functionality Constants too. */ |
| 78 |
&& (!defined ("XMLRPC_REQUEST") || !XMLRPC_REQUEST) && (!defined ("APP_REQUEST") || !APP_REQUEST) && (!defined ("DOING_AJAX") || !DOING_AJAX)/**/ |
| 79 |
&& !current_user_can ("edit_posts")) /* And only if the current User is unable to edit Posts; otherwise we allow them in. */ |
| 80 |
if (apply_filters ("ws_plugin__s2member_admin_lockout", true, get_defined_vars ())) /* Give Filters a chance too. */ |
| 81 |
{ |
| 82 |
if ($special_redirection_url = c_ws_plugin__s2member_login_redirects::login_redirection_url ()) |
| 83 |
$lwp = $special_redirection_url; /* Use Special Redirection URL. */ |
| 84 |
/**/ |
| 85 |
else /* Else we use the Login Welcome Page configured for s2Member. */ |
| 86 |
$lwp = get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]); |
| 87 |
/**/ |
| 88 |
if (isset ($wp_admin_bar->menu->{"my-account-with-avatar"}["href"]) && isset ($wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"edit-my-profile"}["href"])) |
| 89 |
{ |
| 90 |
$wp_admin_bar->menu->{"my-account-with-avatar"}["href"] = $lwp; |
| 91 |
$wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"edit-my-profile"}["href"] = $lwp; |
| 92 |
unset ($wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"dashboard"}); |
| 93 |
} |
| 94 |
/**/ |
| 95 |
if (isset ($wp_admin_bar->menu->{"my-blogs"}["href"]) && isset ($wp_admin_bar->menu->{"my-blogs"}["children"]) && is_object ($wp_admin_bar->menu->{"my-blogs"}["children"])) |
| 96 |
{ |
| 97 |
$wp_admin_bar->menu->{"my-blogs"}["href"] = "#"; /* Void this link by converting to #. */ |
| 98 |
/**/ |
| 99 |
foreach ($wp_admin_bar->menu->{"my-blogs"}["children"] as &$blog) |
| 100 |
if (is_array ($blog) && isset ($blog["href"]) && isset ($blog["children"]) && is_object ($blog["children"])) |
| 101 |
{ |
| 102 |
$blog["href"] = preg_replace ("/\/wp-admin/", "", $blog["href"]); |
| 103 |
unset ($blog["children"]); /* Cause all we need is the link. */ |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
/**/ |
| 108 |
do_action ("ws_plugin__s2member_after_filter_admin_menu_bar", get_defined_vars ()); |
| 109 |
/**/ |
| 110 |
return; /* Return for uniformity. */ |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
?> |