PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.1
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.1
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 5 years ago include.settings-page.php 5 years ago index.php 5 years ago
Init.php
194 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 extends AbstractSettingsPage
9 {
10 public function __construct()
11 {
12 add_filter('show_admin_bar', [$this, 'admin_bar_control'], 9999999999999999999999999999999999999999);
13 add_filter('admin_init', [$this, 'dashboard_access_control'], 9999999999999999999999999999999999999999);
14
15 add_filter('ppress_settings_page_tabs', [$this, 'menu_tab']);
16
17 add_filter('ppress_general_settings_admin_page_short_circuit', [$this, 'settings_page_callback']);
18 add_filter('ppress_general_settings_admin_page_title', [$this, 'change_page_title']);
19 }
20
21 public function db_options()
22 {
23 return get_option('ppress_abdc_options', []);
24 }
25
26 public function menu_tab($tabs)
27 {
28 $tabs[50] = [
29 'url' => add_query_arg('view', 'admin-bar-dashboard', PPRESS_SETTINGS_SETTING_PAGE),
30 'label' => esc_html__('Admin Bar & Dashboard', 'wp-user-avatar')
31 ];
32
33 return $tabs;
34 }
35
36 public function change_page_title($title)
37 {
38 if (isset($_GET['view']) && $_GET['view'] == 'admin-bar-dashboard') {
39 $title = esc_html__('Admin Bar & Dashboard Access', 'wp-user-avatar');
40 }
41
42 return $title;
43 }
44
45 public function settings_page_callback($page)
46 {
47 if (isset($_GET['view']) && $_GET['view'] == 'admin-bar-dashboard') {
48
49 // call to save the setting options
50 self::save_options();
51
52 add_filter('wp_cspa_main_content_area', function () {
53 ob_start();
54 require dirname(__FILE__) . '/include.settings-page.php';
55
56 return ob_get_clean();
57 });
58
59 $instance = Custom_Settings_Page_Api::instance();
60 $instance->option_name('ppress_abdc_options');
61 $instance->page_header(esc_html__('Admin Bar & Dashboard Access', 'wp-user-avatar'));
62 $this->register_core_settings($instance);
63 $instance->tab($this->settings_tab_args());
64 $instance->build();
65
66 return true;
67 }
68
69 return $page;
70 }
71
72
73 public static function save_options()
74 {
75 if (isset($_POST['settings_submit'])) {
76
77 check_admin_referer('ppress_abc_settings_nonce', '_wpnonce');
78
79 if ( ! current_user_can('manage_options')) return;
80
81 $saved_options = self::sanitize_data($_POST['ppress_abdc_options']);
82
83 update_option('ppress_abdc_options', $saved_options);
84
85 wp_safe_redirect(add_query_arg(['view' => 'admin-bar-dashboard', 'settings-updated' => 'true'], PPRESS_SETTINGS_SETTING_PAGE));
86 exit;
87 }
88 }
89
90 /**
91 * Helper function to recursively sanitize POSTed data.
92 *
93 * @param $data
94 *
95 * @return string|array
96 */
97 public static function sanitize_data($data)
98 {
99 if (is_string($data)) return sanitize_text_field($data);
100 $sanitized_data = array();
101 foreach ($data as $key => $value) {
102 if (is_array($data[$key])) {
103 $sanitized_data[$key] = self::sanitize_data($data[$key]);
104 } else {
105 $sanitized_data[$key] = sanitize_text_field($data[$key]);
106 }
107 }
108
109 return $sanitized_data;
110 }
111
112 /**
113 * Callback to disable admin bar.
114 *
115 * @return bool
116 */
117 public function admin_bar_control()
118 {
119 $current_user = wp_get_current_user();
120 $current_user_roles = $current_user->roles;
121
122 $is_admin_bar_disabled = ppress_var($this->db_options(), 'disable_admin_bar', '', true);
123 $disable_admin_bar_roles = ppress_var($this->db_options(), 'disable_admin_bar_roles', [], true);
124
125 // get current user's admin_bar_front preference
126 // if value is true, $user_option will has a boolen true value or false otherwise.
127 $user_option = get_user_option('show_admin_bar_front', $current_user->ID) == 'true';
128
129 // bail if the disable admin bar checkbox isn't checked.
130 if ($is_admin_bar_disabled != 'yes') return $user_option;
131
132 if (is_super_admin($current_user->ID)) return $user_option;
133
134 // if no role is selected, disable for everyone by return false.
135 if (empty($disable_admin_bar_roles)) return false;
136
137 $intersect = array_intersect($current_user_roles, $disable_admin_bar_roles);
138
139 return empty($intersect);
140 }
141
142 /**
143 * Disable dashboard access.
144 *
145 * @return bool|void
146 */
147 public function dashboard_access_control()
148 {
149 $current_user = wp_get_current_user();
150 $current_user_roles = $current_user->roles;
151
152 $is_dashboard_access_disabled = ppress_var($this->db_options(), 'disable_dashboard_access', '', true);
153 $disable_dashboard_access_roles = ppress_var($this->db_options(), 'disable_dashboard_access_roles', [], true);
154
155 if (defined('DOING_AJAX') && DOING_AJAX) return;
156
157 if (basename(sanitize_text_field(wp_unslash($_SERVER['SCRIPT_FILENAME']))) == 'admin-post.php') return;
158
159 if ($is_dashboard_access_disabled != 'yes') return;
160
161 if (is_super_admin($current_user->ID)) return;
162
163 // if no role is selected, disable for everyone by return false.
164 if (empty($disable_dashboard_access_roles)) return $this->disable_dashboard_access();
165
166 $intersect = array_intersect($current_user_roles, $disable_dashboard_access_roles);
167
168 if ( ! empty($intersect)) $this->disable_dashboard_access();
169 }
170
171 /**
172 * Call to disable dashboard access.
173 */
174 public function disable_dashboard_access()
175 {
176 $dashboard_redirect_url = ppress_var($this->db_options(), 'dashboard_redirect_url', home_url(), true);
177
178 if (is_admin()) {
179 wp_safe_redirect(esc_url_raw($dashboard_redirect_url));
180 exit;
181 }
182 }
183
184 public static function get_instance()
185 {
186 static $instance = null;
187
188 if (is_null($instance)) {
189 $instance = new self();
190 }
191
192 return $instance;
193 }
194 }