| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* Locks Users/Members out of admin panels. |
| 5 |
* |
| 6 |
* Copyright: © 2009-2011 |
| 7 |
* {@link http://websharks-inc.com/ WebSharks, Inc.} |
| 8 |
* (coded in the USA) |
| 9 |
* |
| 10 |
* Released under the terms of the GNU General Public License. |
| 11 |
* You should have received a copy of the GNU General Public License, |
| 12 |
* along with this software. In the main directory, see: /licensing/ |
| 13 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 14 |
* |
| 15 |
* @package s2Member\Admin_Lockouts |
| 16 |
* @since 3.5 |
| 17 |
*/ |
| 18 |
if(!defined('WPINC')) // MUST have WordPress. |
| 19 |
exit ('Do not access this file directly.'); |
| 20 |
|
| 21 |
if(!class_exists('c_ws_plugin__s2member_admin_lockouts')) |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Locks Users/Members out of admin panels. |
| 25 |
* |
| 26 |
* @package s2Member\Admin_Lockouts |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
class c_ws_plugin__s2member_admin_lockouts |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Locks Users/Members out of admin panels. |
| 33 |
* |
| 34 |
* @package s2Member\Admin_Lockouts |
| 35 |
* @since 3.5 |
| 36 |
* |
| 37 |
* @attaches-to ``add_action('admin_init');`` |
| 38 |
* |
| 39 |
* @return null Or exits script execution after redirection. |
| 40 |
*/ |
| 41 |
public static function admin_lockout() |
| 42 |
{ |
| 43 |
do_action('ws_plugin__s2member_before_admin_lockouts', get_defined_vars()); |
| 44 |
|
| 45 |
if(is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX) && !current_user_can('edit_posts') /* Give Filters a chance here too. */) |
| 46 |
if(apply_filters('ws_plugin__s2member_admin_lockout', $GLOBALS['WS_PLUGIN__']['s2member']['o']['force_admin_lockouts'], get_defined_vars())) |
| 47 |
{ |
| 48 |
if(($redirection_url = c_ws_plugin__s2member_login_redirects::login_redirection_url())) |
| 49 |
wp_redirect($redirection_url).exit ( /* Special Redirection. */); |
| 50 |
|
| 51 |
else // Else we use the Login Welcome Page configured for s2Member. |
| 52 |
wp_redirect(get_page_link($GLOBALS['WS_PLUGIN__']['s2member']['o']['login_welcome_page'])).exit (); |
| 53 |
} |
| 54 |
do_action('ws_plugin__s2member_after_admin_lockouts', get_defined_vars()); |
| 55 |
} |
| 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 WP_Admin_Bar $wp_admin_bar Expects the ``$wp_admin_bar``, by reference; passed in by the Action Hook. |
| 66 |
* |
| 67 |
* @return null After modifying ``$wp_admin_var``. |
| 68 |
*/ |
| 69 |
public static function filter_admin_menu_bar(&$wp_admin_bar) |
| 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('site-name')) |
| 78 |
{ |
| 79 |
$id = 's2-site-name'; // Give this a special/unique ID. |
| 80 |
$title = wp_html_excerpt(get_bloginfo('name'), 42); // A brief excerpt. |
| 81 |
$title = ($title !== get_bloginfo('name')) ? trim($title).'…' : $title; |
| 82 |
$href = home_url('/'); // Change to front page. |
| 83 |
|
| 84 |
$wp_admin_bar->add_node(array('id' => $id, 'title' => $title, 'href' => $href)); |
| 85 |
$wp_admin_bar->remove_node('site-name'); |
| 86 |
|
| 87 |
unset($id, $title, $href); // Housekeeping. |
| 88 |
} |
| 89 |
if($uses_nodes && $wp_admin_bar->get_node('wp-logo')) |
| 90 |
$wp_admin_bar->remove_node('wp-logo'); |
| 91 |
// ------- |
| 92 |
if(!$uses_nodes && isset ($wp_admin_bar->menu->{'dashboard'})) |
| 93 |
unset ($wp_admin_bar->menu->{'dashboard'}); |
| 94 |
|
| 95 |
if(!$uses_nodes && isset ($wp_admin_bar->menu->{'my-blogs'})) |
| 96 |
unset ($wp_admin_bar->menu->{'my-blogs'}); |
| 97 |
// ------- |
| 98 |
if($uses_nodes && $wp_admin_bar->get_node('my-sites')) |
| 99 |
$wp_admin_bar->remove_node('my-sites'); |
| 100 |
} |
| 101 |
if(is_object($wp_admin_bar) && !current_user_can('edit_posts') /* If locking Users/Members out of `/wp-admin/` areas. */) |
| 102 |
if(apply_filters('ws_plugin__s2member_admin_lockout', $GLOBALS['WS_PLUGIN__']['s2member']['o']['force_admin_lockouts'], get_defined_vars())) |
| 103 |
{ |
| 104 |
$lwp = c_ws_plugin__s2member_login_redirects::login_redirection_url(); |
| 105 |
$lwp = (!$lwp) ? get_page_link($GLOBALS['WS_PLUGIN__']['s2member']['o']['login_welcome_page']) : $lwp; |
| 106 |
|
| 107 |
if($uses_nodes && $wp_admin_bar->get_node('my-account')) |
| 108 |
$wp_admin_bar->add_node(array('id' => 'my-account', 'href' => $lwp)); |
| 109 |
|
| 110 |
if($uses_nodes && $wp_admin_bar->get_node('user-info')) |
| 111 |
$wp_admin_bar->add_node(array('id' => 'user-info', 'href' => $lwp)); |
| 112 |
|
| 113 |
if($uses_nodes && $wp_admin_bar->get_node('edit-profile')) |
| 114 |
$wp_admin_bar->add_node(array('id' => 'edit-profile', 'href' => $lwp)); |
| 115 |
// ------- |
| 116 |
if(!$uses_nodes && isset ($wp_admin_bar->menu->{'my-account'}['href'])) |
| 117 |
$wp_admin_bar->menu->{'my-account'}['href'] = $lwp; |
| 118 |
|
| 119 |
if(!$uses_nodes && isset ($wp_admin_bar->menu->{'my-account'}['children']->{'edit-profile'}['href'])) |
| 120 |
$wp_admin_bar->menu->{'my-account'}['children']->{'edit-profile'}['href'] = $lwp; |
| 121 |
|
| 122 |
if(!$uses_nodes && isset ($wp_admin_bar->menu->{'my-account'}['children']->{'user-info'}['href'])) |
| 123 |
$wp_admin_bar->menu->{'my-account'}['children']->{'user-info'}['href'] = $lwp; |
| 124 |
// ------- |
| 125 |
if(!$uses_nodes && isset ($wp_admin_bar->menu->{'my-account-with-avatar'}['href'])) |
| 126 |
$wp_admin_bar->menu->{'my-account-with-avatar'}['href'] = $lwp; |
| 127 |
|
| 128 |
if(!$uses_nodes && isset ($wp_admin_bar->menu->{'my-account-with-avatar'}['children']->{'user-info'}['href'])) |
| 129 |
$wp_admin_bar->menu->{'my-account-with-avatar'}['children']->{'user-info'}['href'] = $lwp; |
| 130 |
|
| 131 |
if(!$uses_nodes && isset ($wp_admin_bar->menu->{'my-account-with-avatar'}['children']->{'edit-profile'}['href'])) |
| 132 |
$wp_admin_bar->menu->{'my-account-with-avatar'}['children']->{'edit-profile'}['href'] = $lwp; |
| 133 |
} |
| 134 |
do_action('ws_plugin__s2member_after_filter_admin_menu_bar', get_defined_vars()); |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|