| 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 (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 |
wp_redirect ($redirection_url) . exit (); /* Special Redirection. */ |
| 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 |
/**/ |
| 54 |
do_action ("ws_plugin__s2member_after_admin_lockouts", get_defined_vars ()); |
| 55 |
/**/ |
| 56 |
return; /* Return for uniformity. */ |
| 57 |
} |
| 58 |
/** |
| 59 |
* Filters administrative menu bar for Users/Members. |
| 60 |
* |
| 61 |
* @package s2Member\Admin_Lockouts |
| 62 |
* @since 3.5 |
| 63 |
* |
| 64 |
* @attaches-to ``add_action("admin_bar_menu");`` |
| 65 |
* |
| 66 |
* @param obj $wp_admin_bar Expects the ``$wp_admin_bar``, by reference; passed in by the Action Hook. |
| 67 |
* @return null After modifying ``$wp_admin_var``. |
| 68 |
*/ |
| 69 |
public static function filter_admin_menu_bar (&$wp_admin_bar = FALSE) |
| 70 |
{ |
| 71 |
do_action ("ws_plugin__s2member_before_filter_admin_menu_bar", get_defined_vars ()); |
| 72 |
/**/ |
| 73 |
$uses_nodes = (version_compare (get_bloginfo ("version"), "3.3-RC1", ">=")) ? true : false; |
| 74 |
/**/ |
| 75 |
if (is_object ($wp_admin_bar) && !current_user_can ("edit_posts") /* Always for Users/Members. */) |
| 76 |
{ |
| 77 |
if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("site-name")) |
| 78 |
{ |
| 79 |
$id = /* Give this a special/unique ID. */ "s2-site-name"; |
| 80 |
$title = wp_html_excerpt /* A brief excerpt. */ (get_bloginfo ("name"), 42); |
| 81 |
$title = ($title !== get_bloginfo ("name")) ? trim ($title) . "…" : $title; |
| 82 |
$href = /* Change to front page. */ site_url ("/"); |
| 83 |
/**/ |
| 84 |
$wp_admin_bar->add_node (array ("id" => $id, "title" => $title, "href" => $href)); |
| 85 |
$wp_admin_bar->remove_node /* Ditch now, replacing this. */ ("site-name"); |
| 86 |
/**/ |
| 87 |
unset /* A little housekeeping. */ ($id, $title, $href); |
| 88 |
} |
| 89 |
if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("wp-logo")) |
| 90 |
$wp_admin_bar->remove_node /* Ditch this node. */ ("wp-logo"); |
| 91 |
/* ------- */ |
| 92 |
if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"dashboard"})) |
| 93 |
unset /* Ditch this item. */ ($wp_admin_bar->menu->{"dashboard"}); |
| 94 |
/**/ |
| 95 |
if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-blogs"})) |
| 96 |
unset /* Ditch this item. */ ($wp_admin_bar->menu->{"my-blogs"}); |
| 97 |
/* ------- */ |
| 98 |
if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("my-sites")) |
| 99 |
$wp_admin_bar->remove_node /* Ditch this node. */ ("my-sites"); |
| 100 |
} |
| 101 |
/**/ |
| 102 |
if (is_object ($wp_admin_bar) && !current_user_can ("edit_posts") /* If locking Users/Members out of `/wp-admin/` areas. */) |
| 103 |
if (apply_filters ("ws_plugin__s2member_admin_lockout", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"], get_defined_vars ())) |
| 104 |
{ |
| 105 |
$lwp = c_ws_plugin__s2member_login_redirects::login_redirection_url (); |
| 106 |
$lwp = (!$lwp) ? get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]) : $lwp; |
| 107 |
/**/ |
| 108 |
if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("my-account")) |
| 109 |
$wp_admin_bar->add_node /* Update this node. */ (array ("id" => "my-account", "href" => $lwp)); |
| 110 |
/**/ |
| 111 |
if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("user-info")) |
| 112 |
$wp_admin_bar->add_node /* Update this node. */ (array ("id" => "user-info", "href" => $lwp)); |
| 113 |
/**/ |
| 114 |
if ($uses_nodes && $wp_admin_bar->get_node /* We have this node? */ ("edit-profile")) |
| 115 |
$wp_admin_bar->add_node /* Update this node. */ (array ("id" => "edit-profile", "href" => $lwp)); |
| 116 |
/* ------- */ |
| 117 |
if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account"}["href"])) |
| 118 |
$wp_admin_bar->menu->{"my-account"}["href"] = /* Update this item. */ $lwp; |
| 119 |
/**/ |
| 120 |
if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account"}["children"]->{"edit-profile"}["href"])) |
| 121 |
$wp_admin_bar->menu->{"my-account"}["children"]->{"edit-profile"}["href"] = /* Update this item. */ $lwp; |
| 122 |
/**/ |
| 123 |
if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account"}["children"]->{"user-info"}["href"])) |
| 124 |
$wp_admin_bar->menu->{"my-account"}["children"]->{"user-info"}["href"] = /* Update this item. */ $lwp; |
| 125 |
/* ------- */ |
| 126 |
if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account-with-avatar"}["href"])) |
| 127 |
$wp_admin_bar->menu->{"my-account-with-avatar"}["href"] = /* Update this item. */ $lwp; |
| 128 |
/**/ |
| 129 |
if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"user-info"}["href"])) |
| 130 |
$wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"user-info"}["href"] = /* Update this item. */ $lwp; |
| 131 |
/**/ |
| 132 |
if (!$uses_nodes && isset /* Have this item? */ ($wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"edit-profile"}["href"])) |
| 133 |
$wp_admin_bar->menu->{"my-account-with-avatar"}["children"]->{"edit-profile"}["href"] = /* Update this item. */ $lwp; |
| 134 |
} |
| 135 |
/**/ |
| 136 |
do_action ("ws_plugin__s2member_after_filter_admin_menu_bar", get_defined_vars ()); |
| 137 |
/**/ |
| 138 |
return; /* Return for uniformity. */ |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
?> |