PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.16.19
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.16.19
4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / AdminBarDashboardAccess / Init.php
wp-user-avatar / src / AdminBarDashboardAccess Last commit date
Init.php 3 years ago include.settings-page.php 5 years ago index.php 3 years ago
Init.php
193 lines
1 <?php
2
3 namespace ProfilePress\Core\AdminBarDashboardAccess;
4
5 use ProfilePress\Core\Admin\SettingsPages\AbstractSettingsPage;
6 use ProfilePress\Custom_Settings_Page_Api;
7
8 class Init
9 {
10 public function __construct()
11 {
12 add_filter('show_admin_bar', [$this, 'admin_bar_control'], PHP_INT_MAX - 1);
13 add_action('admin_init', [$this, 'dashboard_access_control'], 1);
14
15 add_action('admin_init', [$this, 'save_options']);
16 add_filter('ppress_settings_page_submenus_tabs', [$this, 'menu_tab']);
17
18 add_action('ppress_admin_settings_submenu_page_general_admin-bar-dashboard', [$this, 'settings_page_callback']);
19 add_filter('ppress_general_settings_admin_page_title', [$this, 'change_page_title']);
20 }
21
22 public function db_options()
23 {
24 return get_option('ppress_abdc_options', []);
25 }
26
27 public function menu_tab($tabs)
28 {
29 $tabs[50] = [
30 'parent' => 'general',
31 'id' => 'admin-bar-dashboard',
32 'label' => esc_html__('Admin Bar & Dashboard', 'wp-user-avatar')
33 ];
34
35 return $tabs;
36 }
37
38 public function change_page_title($title)
39 {
40 if (isset($_GET['section']) && $_GET['section'] == 'admin-bar-dashboard') {
41 $title = esc_html__('Admin Bar & Dashboard Access', 'wp-user-avatar');
42 }
43
44 return $title;
45 }
46
47 public function settings_page_callback()
48 {
49 add_filter('wp_cspa_main_content_area', function () {
50 ob_start();
51 require dirname(__FILE__) . '/include.settings-page.php';
52
53 return ob_get_clean();
54 });
55
56 $instance = Custom_Settings_Page_Api::instance();
57 $instance->option_name('ppress_abdc_options');
58 $instance->page_header(esc_html__('Admin Bar & Dashboard Access', 'wp-user-avatar'));
59 AbstractSettingsPage::register_core_settings($instance);
60 $instance->build();
61 }
62
63 public static function save_options()
64 {
65 if (isset($_GET['section']) && $_GET['section'] == 'admin-bar-dashboard' && isset($_POST['settings_submit'])) {
66
67 check_admin_referer('ppress_abc_settings_nonce', '_wpnonce');
68
69 if ( ! current_user_can('manage_options')) return;
70
71 $saved_options = self::sanitize_data($_POST['ppress_abdc_options']);
72
73 update_option('ppress_abdc_options', $saved_options);
74
75 wp_safe_redirect(esc_url_raw(add_query_arg(['settings-updated' => 'true'])));
76 exit;
77 }
78 }
79
80 /**
81 * Helper function to recursively sanitize POSTed data.
82 *
83 * @param $data
84 *
85 * @return string|array
86 */
87 public static function sanitize_data($data)
88 {
89 if (is_string($data)) return sanitize_text_field($data);
90 $sanitized_data = array();
91 foreach ($data as $key => $value) {
92 if (is_array($data[$key])) {
93 $sanitized_data[$key] = self::sanitize_data($data[$key]);
94 } else {
95 $sanitized_data[$key] = sanitize_text_field($data[$key]);
96 }
97 }
98
99 return $sanitized_data;
100 }
101
102 /**
103 * Callback to disable admin bar.
104 *
105 * @param $show_admin_bar
106 *
107 * @return bool
108 */
109 public function admin_bar_control($show_admin_bar)
110 {
111 $is_admin_bar_disabled = ppress_var($this->db_options(), 'disable_admin_bar', '', true);
112
113 // bail if the disable admin bar checkbox isn't checked or we oxygen builder
114 if ($is_admin_bar_disabled != 'yes' | defined("SHOW_CT_BUILDER")) return $show_admin_bar;
115
116 if (is_user_logged_in()) {
117
118 $disable_admin_bar_roles = ppress_var($this->db_options(), 'disable_admin_bar_roles', [], true);
119
120 $current_user = wp_get_current_user();
121 $current_user_roles = $current_user->roles;
122
123 // get current user's admin_bar_front preference
124 // if value is true, $user_option will has a boolen true value or false otherwise.
125 $user_option = (get_user_option('show_admin_bar_front', $current_user->ID) == 'true');
126
127 if (is_super_admin($current_user->ID)) return $user_option;
128
129 // if no role is selected, disable for everyone by return false.
130 if (empty($disable_admin_bar_roles)) return false;
131
132 $intersect = array_intersect($current_user_roles, $disable_admin_bar_roles);
133
134 return empty($intersect);
135 }
136
137 return false;
138 }
139
140 /**
141 * Disable dashboard access.
142 *
143 * @return bool|void
144 */
145 public function dashboard_access_control()
146 {
147 $current_user = wp_get_current_user();
148 $current_user_roles = $current_user->roles;
149
150 $is_dashboard_access_disabled = ppress_var($this->db_options(), 'disable_dashboard_access', '', true);
151 $disable_dashboard_access_roles = ppress_var($this->db_options(), 'disable_dashboard_access_roles', [], true);
152
153 if (defined('DOING_AJAX') && DOING_AJAX) return;
154
155 if (basename(sanitize_text_field(wp_unslash($_SERVER['SCRIPT_FILENAME']))) == 'admin-post.php') return;
156
157 if ($is_dashboard_access_disabled != 'yes') return;
158
159 if (is_super_admin($current_user->ID)) return;
160
161 // if no role is selected, disable for everyone by return false.
162 if (empty($disable_dashboard_access_roles)) return $this->disable_dashboard_access();
163
164 $intersect = array_intersect($current_user_roles, $disable_dashboard_access_roles);
165
166 if ( ! empty($intersect)) $this->disable_dashboard_access();
167 }
168
169 /**
170 * Call to disable dashboard access.
171 */
172 public function disable_dashboard_access()
173 {
174 $dashboard_redirect_url = ppress_var($this->db_options(), 'dashboard_redirect_url', home_url(), true);
175
176 if (is_admin()) {
177 nocache_headers();
178 wp_safe_redirect(esc_url_raw($dashboard_redirect_url));
179 exit;
180 }
181 }
182
183 public static function get_instance()
184 {
185 static $instance = null;
186
187 if (is_null($instance)) {
188 $instance = new self();
189 }
190
191 return $instance;
192 }
193 }