Changeset 3392566
- Timestamp:
- 11/10/2025 12:57:21 AM (5 months ago)
- Location:
- wp-user-profile-restriction/trunk
- Files:
-
- 2 edited
-
README.txt (modified) (1 diff)
-
wp-upr.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-user-profile-restriction/trunk/README.txt
r3056466 r3392566 1 === WP User Profile Restriction ===2 Contributors: shawon786 3 Tags: user profile restriction, disable editing user profile, disable updating my profile, my profile restriction, profile.php restriction, wp user profile 1 === WP User Profile Restriction === 2 Contributors: shawon786, innovs, theinnovs 3 Tags: user profile restriction, disable editing user profile, disable updating my profile, my profile restriction, profile.php restriction, wp user profile, role-based restrictions 4 4 Requires at least: 4.0.3 5 Tested up to: 6.4.3 5 Tested up to: 6.8.3 6 Stable tag: 2.0.0 6 7 License: GPLv2 or later 7 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 8 9 9 Restrict user profile so that an user can't update his profile if he is not an Admin, Editor, Author.10 Restrict user profile editing with granular role-based controls, custom redirects, and automatic menu hiding for enhanced WordPress security. 10 11 11 12 == Description == 12 13 13 A little plugin to restrict user profile so that an user can't update his profile if he is not Admin, Editor, Author. Secure your WordPress website or demo sites by disabling User Profile Updation for random and regular users. Now normal users won't be able to update or change anything of his profile like email, password etc. And in this way your website will remain fully secured.14 **WP User Profile Restriction** is a powerful yet simple plugin that allows you to restrict profile editing capabilities for specific user roles. Perfect for demo sites, membership websites, or any WordPress installation where you need to maintain control over user profile modifications. 14 15 15 > Just install > Activate & Enjoy! No additional setup required! 16 = Key Features = 16 17 18 * **Granular Role-Based Restrictions** - Choose exactly which user roles should be restricted from editing their profiles 19 * **Custom Redirect Options** - Redirect restricted users to a specific URL instead of showing an error message 20 * **Automatic Menu Hiding** - Profile links are automatically hidden from admin bar and dashboard menu for restricted users 21 * **Easy Settings Page** - Configure all options from a user-friendly settings page in WordPress admin 22 * **Backward Compatible** - Maintains default security by restricting Subscribers and Contributors by default 23 * **No Coding Required** - Simple checkbox interface for all configurations 24 * **Lightweight & Fast** - Minimal impact on site performance 25 26 = How It Works = 27 28 1. **Install and Activate** - The plugin works immediately with secure defaults 29 2. **Configure Settings** - Go to Settings > Profile Restriction to customize 30 3. **Select Roles** - Check which user roles should be restricted 31 4. **Optional Redirect** - Set a custom redirect URL if desired 32 5. **Done!** - Restricted users can no longer edit their profiles 33 34 = Default Behavior = 35 36 By default, the plugin restricts **Subscribers** and **Contributors** from editing their profiles. This maintains security while allowing Editors, Authors, and Administrators full access. You can customize this behavior at any time from the settings page. 37 38 = Perfect For = 39 40 * Demo and staging websites 41 * Membership sites 42 * Multi-author blogs 43 * Educational institutions 44 * Client websites 45 * Any site requiring profile editing restrictions 46 47 = What Gets Restricted = 48 49 * Direct access to profile.php page 50 * Profile link in admin bar 51 * Profile submenu in dashboard 52 * All profile editing capabilities for selected roles 53 54 = Administrator Protection = 55 56 Administrators always retain full access to edit any profile, regardless of plugin settings. This ensures you never lock yourself out of critical functionality. 17 57 18 58 == Installation == 19 59 20 ### Direct Install From WordPress Dashboard 60 = Automatic Installation (Recommended) = 21 61 22 1. Go to Plugins page 23 2. Add New and search for 'WP User Profile Restriction' 24 3. You will see the plugin in the search list. 25 4. Install and activate the plugin. That's all. 62 1. Log in to your WordPress dashboard 63 2. Navigate to Plugins > Add New 64 3. Search for "WP User Profile Restriction" 65 4. Click "Install Now" and then "Activate" 66 5. Go to Settings > Profile Restriction to configure 26 67 68 = Manual Installation = 27 69 28 ### Manual Install From WordPress Dashboard 70 1. Download the plugin ZIP file 71 2. Log in to your WordPress dashboard 72 3. Navigate to Plugins > Add New > Upload Plugin 73 4. Choose the downloaded ZIP file and click "Install Now" 74 5. Activate the plugin 75 6. Go to Settings > Profile Restriction to configure 29 76 30 If your server is not connected to the Internet, then you can use this method- 77 = FTP Installation = 31 78 32 1. Download the plugin. A ZIP file will be downloaded. 33 2. Login to your site’s admin panel and navigate to Plugins -> Add New -> Upload. 34 3. Click choose file, select the plugin file and click install 35 36 ###Install Using FTP 37 38 If you are unable to use any of the methods due to internet connectivity and file permission issues, then you can use this method- 39 40 1. Download the plugin by clicking on the blue button above.A ZIP file will be downloaded. 41 2. Unzip the file. 42 3. Launch your favorite FTP client. Such as FileZilla, FireFTP, CyberDuck etc. If you are a more advanced user, then you can use SSH too. 43 4. Upload the folder to wp-content/plugins/ 44 5. Log in to your WordPress dashboard. 45 6. Navigate to Plugins -> Installed 46 7. Activate the plugin 47 48 79 1. Download and unzip the plugin file 80 2. Upload the `wp-user-profile-restriction` folder to `/wp-content/plugins/` directory 81 3. Activate the plugin through the Plugins menu in WordPress 82 4. Go to Settings > Profile Restriction to configure 49 83 50 84 == Frequently Asked Questions == 51 85 52 = Is this plugin needs any additional settings? = 53 No, this plugin does not need any additional settings. 86 = Does this plugin require any configuration? = 54 87 88 No! The plugin works immediately upon activation with secure defaults (Subscribers and Contributors are restricted). However, you can customize the behavior from Settings > Profile Restriction. 55 89 90 = Which user roles are restricted by default? = 91 92 By default, **Subscribers** and **Contributors** are restricted from editing their profiles. This provides security while maintaining backward compatibility with version 1.0.6. 93 94 = Can I choose which roles to restrict? = 95 96 Yes! Version 2.0 introduces a settings page where you can select exactly which user roles should be restricted using simple checkboxes. 97 98 = Can administrators still edit profiles? = 99 100 Yes, administrators always have full access to edit any profile, regardless of plugin settings. 101 102 = What happens when a restricted user tries to access their profile? = 103 104 By default, they see an error message. Optionally, you can enable custom redirect to send them to a specific page (like the homepage or a custom access denied page). 105 106 = Will restricted users see the Profile menu? = 107 108 No, the Profile link is automatically hidden from both the admin bar and the dashboard sidebar menu for all restricted users. 109 110 = Can I redirect restricted users to a custom page? = 111 112 Yes! In the settings page, you can enable custom redirect and specify any URL where restricted users should be redirected. 113 114 = Is this plugin compatible with the latest WordPress version? = 115 116 Yes, the plugin is regularly tested and updated to ensure compatibility with the latest WordPress releases. 117 118 = Will this affect my existing users? = 119 120 If you're upgrading from version 1.0.6, the plugin maintains the same default behavior (restricting Subscribers and Contributors). Your existing security settings remain intact. 121 122 = Can I restrict Editors or Authors? = 123 124 Yes, you can select any combination of user roles to restrict from the settings page. 125 126 = Does this work with custom user roles? = 127 128 Yes, the plugin automatically detects all user roles on your site, including custom roles created by other plugins. 129 130 == Screenshots == 131 132 1. Settings page with role-based restriction options 133 2. Custom redirect configuration 134 3. Restricted user attempting to access profile 135 4. Admin bar with profile menu hidden for restricted users 56 136 57 137 == Changelog == 58 138 139 = 2.0.0 (2024-11-09) = 140 * **Major Update** - Complete rewrite with new features 141 * Added: Settings page for easy configuration 142 * Added: Granular role-based restriction controls 143 * Added: Custom redirect option for restricted users 144 * Added: Automatic hiding of Profile menu for restricted users 145 * Added: Checkbox interface for selecting restricted roles 146 * Improved: Code structure using OOP approach 147 * Improved: Security with proper sanitization and validation 148 * Improved: User experience with informative settings page 149 * Maintained: Backward compatibility with default restrictions 150 * Updated: Tested with WordPress 6.8.3 151 152 = 2.0.0 = 153 Major update with new settings page, granular role controls, custom redirect options, and automatic menu hiding. Fully backward compatible with default security settings maintained. 154 59 155 = 1.0.6 = 60 * [Fix] - Compatibility with the latest WP156 * Fix: Compatibility with the latest WordPress version 61 157 62 158 = 1.0.5 = 63 * Compatib lity Fix with the latest WP5.8.2159 * Compatibility fix with WordPress 5.8.2 64 160 65 161 = 1.0.4 = 66 * Compatib lity Fix with the latest WP162 * Compatibility fix with latest WordPress 67 163 68 164 = 1.0.3 = 69 * Compatib lity Check165 * Compatibility check 70 166 71 167 = 1.0.2 = 72 * Compatib lity with5.3.2168 * Compatibility with WordPress 5.3.2 73 169 74 170 = 1.0.1 = 75 * Compatib lity with5.1171 * Compatibility with WordPress 5.1 76 172 77 173 = 1.0.0 = 78 * Initial Release174 * Initial release 79 175 80 176 177 == Additional Information == 178 179 = Support = 180 181 For support, feature requests, or bug reports, please visit the plugin's support forum on WordPress.org. 182 183 = Privacy = 184 185 This plugin does not collect, store, or transmit any user data. All settings are stored locally in your WordPress database. 186 187 = Credits = 188 189 Developed by Shawon C for TheInnovs LLC -
wp-user-profile-restriction/trunk/wp-upr.php
r3056466 r3392566 3 3 Plugin Name: WP User Profile Restriction 4 4 Plugin URI: https://wordpress.org/plugins/wp-user-profile-restriction/ 5 Description: Disallow users to edit their own profile if he is not an Admin/Editor/Author. 6 Author: Shawon 7 Version: 1.0.6 8 Author URI: http://shawon.co 5 Description: Disallow users to edit their own profile if he is not an Admin/Editor/Author. Now with granular role-based restrictions and custom redirect options. 6 Author: Shawon, theinnovs, innovs 7 Version: 2.0.0 8 Author URI: https://theinnovs.com 9 Text Domain: wp-user-profile-restriction 10 Domain Path: /languages 9 11 */ 10 11 12 12 13 // don't call the file directly 13 14 if ( ! defined( 'ABSPATH' ) ) exit; 14 15 15 16 function wpupr_disable_editing_my_profile () { 17 $user = wp_get_current_user(); 18 $allowed_roles = array('editor', 'administrator', 'author'); 19 20 if( !array_intersect($allowed_roles, $user->roles ) ) 21 22 { 23 wp_die( 'You are not permitted to change your Profile information. Please contact Site Admin to update your profile if necessary.' ); 24 } 16 /** 17 * WP User Profile Restriction Class 18 */ 19 class WP_User_Profile_Restriction { 20 21 /** 22 * Plugin version 23 */ 24 const VERSION = '2.0.0'; 25 26 /** 27 * Option name for settings 28 */ 29 const OPTION_NAME = 'wpupr_settings'; 30 31 /** 32 * Constructor 33 */ 34 public function __construct() { 35 // Initialize plugin 36 add_action( 'admin_init', array( $this, 'init_settings' ) ); 37 add_action( 'admin_menu', array( $this, 'add_settings_page' ) ); 38 add_action( 'load-profile.php', array( $this, 'restrict_profile_access' ) ); 39 // Note: Menu hiding removed - menus remain visible, restriction happens on profile.php load 40 41 // Set default options on activation 42 register_activation_hook( __FILE__, array( $this, 'activate' ) ); 43 44 // Hook: After plugin initialization 45 do_action( 'wpupr_init', $this ); 46 } 47 48 /** 49 * Plugin activation 50 */ 51 public function activate() { 52 // Set default options if not exists 53 if ( false === get_option( self::OPTION_NAME ) ) { 54 $default_options = array( 55 'restricted_roles' => array( 'subscriber', 'contributor' ), 56 'redirect_url' => '', 57 'redirect_enabled' => '0' 58 ); 59 60 // Filter: Modify default options on activation 61 $default_options = apply_filters( 'wpupr_default_options', $default_options ); 62 63 update_option( self::OPTION_NAME, $default_options ); 64 } 65 66 // Action: After plugin activation 67 do_action( 'wpupr_activated' ); 68 } 69 70 /** 71 * Get plugin settings 72 */ 73 public function get_settings() { 74 $defaults = array( 75 'restricted_roles' => array( 'subscriber', 'contributor' ), 76 'redirect_url' => '', 77 'redirect_enabled' => '0' 78 ); 79 80 $settings = get_option( self::OPTION_NAME, $defaults ); 81 82 // Ensure restricted_roles is always an array 83 if ( ! isset( $settings['restricted_roles'] ) || ! is_array( $settings['restricted_roles'] ) ) { 84 $settings['restricted_roles'] = $defaults['restricted_roles']; 85 } 86 87 // Filter: Modify retrieved settings 88 return apply_filters( 'wpupr_get_settings', $settings ); 89 } 90 91 /** 92 * Check if current user role is restricted 93 */ 94 public function is_user_restricted() { 95 $user = wp_get_current_user(); 96 $settings = $this->get_settings(); 97 $restricted_roles = $settings['restricted_roles']; 98 99 // Filter: Modify restricted roles list 100 $restricted_roles = apply_filters( 'wpupr_restricted_roles', $restricted_roles, $user ); 101 102 // Check if user has any restricted role 103 $is_restricted = (bool) array_intersect( $restricted_roles, $user->roles ); 104 105 // Filter: Override restriction check 106 return apply_filters( 'wpupr_is_user_restricted', $is_restricted, $user ); 107 } 108 109 /** 110 * Restrict profile access 111 */ 112 public function restrict_profile_access() { 113 // Action: Before restriction check 114 do_action( 'wpupr_before_restrict_profile' ); 115 116 if ( ! $this->is_user_restricted() ) { 117 // Action: User is not restricted 118 do_action( 'wpupr_user_not_restricted' ); 119 return; 120 } 121 122 // Action: User is restricted 123 do_action( 'wpupr_user_restricted' ); 124 125 $settings = $this->get_settings(); 126 127 // Check if custom redirect is enabled 128 if ( $settings['redirect_enabled'] === '1' ) { 129 $redirect_url = ! empty( $settings['redirect_url'] ) ? $settings['redirect_url'] : home_url(); 130 131 // Filter: Modify redirect URL 132 $redirect_url = apply_filters( 'wpupr_redirect_url', $redirect_url, wp_get_current_user() ); 133 134 // Action: Before redirect 135 do_action( 'wpupr_before_redirect', $redirect_url ); 136 137 // Use wp_redirect instead of wp_safe_redirect for external URLs 138 wp_redirect( esc_url_raw( $redirect_url ) ); 139 exit; 140 } else { 141 // Default wp_die message 142 $message = __( 'You are not permitted to change your Profile information. Please contact Site Admin to update your profile if necessary.', 'wp-user-profile-restriction' ); 143 $title = __( 'Access Denied', 'wp-user-profile-restriction' ); 144 $args = array( 'response' => 403 ); 145 146 // Filter: Modify wp_die message 147 $message = apply_filters( 'wpupr_access_denied_message', $message, wp_get_current_user() ); 148 149 // Filter: Modify wp_die title 150 $title = apply_filters( 'wpupr_access_denied_title', $title, wp_get_current_user() ); 151 152 // Filter: Modify wp_die args 153 $args = apply_filters( 'wpupr_access_denied_args', $args, wp_get_current_user() ); 154 155 // Action: Before wp_die 156 do_action( 'wpupr_before_access_denied', $message, $title, $args ); 157 158 wp_die( $message, $title, $args ); 159 } 160 } 161 162 /** 163 * Remove profile link from admin bar 164 * NOTE: This method is kept for backward compatibility with hooks but is not called by default. 165 * Menus remain visible; restriction happens when user tries to access profile.php 166 */ 167 public function remove_profile_menu( $wp_admin_bar ) { 168 // Method kept for backward compatibility with hooks 169 // Not called by default - menus remain visible 170 171 if ( ! $this->is_user_restricted() ) { 172 return; 173 } 174 175 // Action: Before removing admin bar menu 176 do_action( 'wpupr_before_remove_admin_bar_menu', $wp_admin_bar ); 177 178 // Filter: Which admin bar nodes to remove 179 $nodes_to_remove = apply_filters( 'wpupr_admin_bar_nodes_to_remove', array( 'user-info', 'edit-profile' ) ); 180 181 // Remove nodes 182 foreach ( $nodes_to_remove as $node ) { 183 $wp_admin_bar->remove_node( $node ); 184 } 185 186 // Action: After removing admin bar menu 187 do_action( 'wpupr_after_remove_admin_bar_menu', $wp_admin_bar ); 188 } 189 190 /** 191 * Remove profile submenu from dashboard 192 * NOTE: This method is kept for backward compatibility with hooks but is not called by default. 193 * Menus remain visible; restriction happens when user tries to access profile.php 194 */ 195 public function remove_profile_submenu() { 196 // Method kept for backward compatibility with hooks 197 // Not called by default - menus remain visible 198 if ( ! $this->is_user_restricted() ) { 199 return; 200 } 201 202 // Action: Before removing submenu 203 do_action( 'wpupr_before_remove_submenu' ); 204 205 // Filter: Which submenus to remove (parent_slug => menu_slug) 206 $submenus_to_remove = apply_filters( 'wpupr_submenus_to_remove', array( 207 'users.php' => 'profile.php' 208 ) ); 209 210 // Remove submenus 211 foreach ( $submenus_to_remove as $parent_slug => $menu_slug ) { 212 remove_submenu_page( $parent_slug, $menu_slug ); 213 } 214 215 // Action: After removing submenu 216 do_action( 'wpupr_after_remove_submenu' ); 217 } 218 219 /** 220 * Add settings page to admin menu 221 */ 222 public function add_settings_page() { 223 $page_title = __( 'User Profile Restriction Settings', 'wp-user-profile-restriction' ); 224 $menu_title = __( 'Profile Restriction', 'wp-user-profile-restriction' ); 225 $capability = 'manage_options'; 226 $menu_slug = 'wpupr-settings'; 227 228 // Filter: Modify settings page parameters 229 $page_title = apply_filters( 'wpupr_settings_page_title', $page_title ); 230 $menu_title = apply_filters( 'wpupr_settings_menu_title', $menu_title ); 231 $capability = apply_filters( 'wpupr_settings_capability', $capability ); 232 233 add_options_page( 234 $page_title, 235 $menu_title, 236 $capability, 237 $menu_slug, 238 array( $this, 'render_settings_page' ) 239 ); 240 } 241 242 /** 243 * Initialize settings 244 */ 245 public function init_settings() { 246 register_setting( 247 'wpupr_settings_group', 248 self::OPTION_NAME, 249 array( $this, 'sanitize_settings' ) 250 ); 251 252 // Role Restrictions Section 253 add_settings_section( 254 'wpupr_role_section', 255 __( 'Role-Based Restrictions', 'wp-user-profile-restriction' ), 256 array( $this, 'role_section_callback' ), 257 'wpupr-settings' 258 ); 259 260 add_settings_field( 261 'wpupr_restricted_roles', 262 __( 'Restrict Profile Editing for:', 'wp-user-profile-restriction' ), 263 array( $this, 'restricted_roles_callback' ), 264 'wpupr-settings', 265 'wpupr_role_section' 266 ); 267 268 // Redirect Section 269 add_settings_section( 270 'wpupr_redirect_section', 271 __( 'Custom Redirect Settings', 'wp-user-profile-restriction' ), 272 array( $this, 'redirect_section_callback' ), 273 'wpupr-settings' 274 ); 275 276 add_settings_field( 277 'wpupr_redirect_enabled', 278 __( 'Enable Custom Redirect', 'wp-user-profile-restriction' ), 279 array( $this, 'redirect_enabled_callback' ), 280 'wpupr-settings', 281 'wpupr_redirect_section' 282 ); 283 284 add_settings_field( 285 'wpupr_redirect_url', 286 __( 'Redirect URL', 'wp-user-profile-restriction' ), 287 array( $this, 'redirect_url_callback' ), 288 'wpupr-settings', 289 'wpupr_redirect_section' 290 ); 291 292 // Action: After settings initialization (for adding custom sections/fields) 293 do_action( 'wpupr_settings_init' ); 294 } 295 296 /** 297 * Sanitize settings 298 */ 299 public function sanitize_settings( $input ) { 300 $sanitized = array(); 301 302 // Sanitize restricted roles 303 if ( isset( $input['restricted_roles'] ) && is_array( $input['restricted_roles'] ) ) { 304 $sanitized['restricted_roles'] = array_map( 'sanitize_text_field', $input['restricted_roles'] ); 305 } else { 306 $sanitized['restricted_roles'] = array(); 307 } 308 309 // Sanitize redirect enabled 310 $sanitized['redirect_enabled'] = isset( $input['redirect_enabled'] ) ? '1' : '0'; 311 312 // Sanitize redirect URL 313 $sanitized['redirect_url'] = isset( $input['redirect_url'] ) ? esc_url_raw( $input['redirect_url'] ) : ''; 314 315 // Filter: Modify sanitized settings 316 $sanitized = apply_filters( 'wpupr_sanitize_settings', $sanitized, $input ); 317 318 // Action: After settings sanitization 319 do_action( 'wpupr_settings_saved', $sanitized, $input ); 320 321 return $sanitized; 322 } 323 324 /** 325 * Role section callback 326 */ 327 public function role_section_callback() { 328 $description = __( 'Select which user roles should be restricted from editing their profiles. By default, Subscribers and Contributors are restricted to maintain security.', 'wp-user-profile-restriction' ); 329 330 // Filter: Modify section description 331 $description = apply_filters( 'wpupr_role_section_description', $description ); 332 333 echo '<p>' . esc_html( $description ) . '</p>'; 334 335 // Action: After role section description 336 do_action( 'wpupr_after_role_section_description' ); 337 } 338 339 /** 340 * Restricted roles callback 341 */ 342 public function restricted_roles_callback() { 343 $settings = $this->get_settings(); 344 $restricted_roles = $settings['restricted_roles']; 345 346 // Get all WordPress roles 347 global $wp_roles; 348 $all_roles = $wp_roles->roles; 349 350 // Filter: Modify available roles list 351 $all_roles = apply_filters( 'wpupr_available_roles', $all_roles ); 352 353 echo '<fieldset>'; 354 echo '<legend class="screen-reader-text"><span>' . __( 'Restricted Roles', 'wp-user-profile-restriction' ) . '</span></legend>'; 355 356 // Action: Before role checkboxes 357 do_action( 'wpupr_before_role_checkboxes', $restricted_roles ); 358 359 foreach ( $all_roles as $role_slug => $role_info ) { 360 $checked = in_array( $role_slug, $restricted_roles ) ? 'checked="checked"' : ''; 361 $role_name = translate_user_role( $role_info['name'] ); 362 363 // Filter: Modify individual role display 364 $role_display = apply_filters( 'wpupr_role_checkbox_display', true, $role_slug, $role_info ); 365 366 if ( ! $role_display ) { 367 continue; 368 } 369 370 echo '<label style="display: block; margin-bottom: 8px;">'; 371 echo '<input type="checkbox" name="' . self::OPTION_NAME . '[restricted_roles][]" value="' . esc_attr( $role_slug ) . '" ' . $checked . '> '; 372 echo esc_html( $role_name ); 373 374 // Action: After individual role checkbox 375 do_action( 'wpupr_after_role_checkbox', $role_slug, $role_info ); 376 377 echo '</label>'; 378 } 379 380 // Action: After role checkboxes 381 do_action( 'wpupr_after_role_checkboxes', $restricted_roles ); 382 383 echo '</fieldset>'; 384 echo '<p class="description">' . __( 'Users with checked roles will not be able to edit their profiles.', 'wp-user-profile-restriction' ) . '</p>'; 385 } 386 387 /** 388 * Redirect section callback 389 */ 390 public function redirect_section_callback() { 391 $description = __( 'Configure where restricted users should be redirected when they try to access the profile editing page.', 'wp-user-profile-restriction' ); 392 393 // Filter: Modify redirect section description 394 $description = apply_filters( 'wpupr_redirect_section_description', $description ); 395 396 echo '<p>' . esc_html( $description ) . '</p>'; 397 398 // Action: After redirect section description 399 do_action( 'wpupr_after_redirect_section_description' ); 400 } 401 402 /** 403 * Redirect enabled callback 404 */ 405 public function redirect_enabled_callback() { 406 $settings = $this->get_settings(); 407 $redirect_enabled = $settings['redirect_enabled']; 408 409 echo '<label>'; 410 echo '<input type="checkbox" name="' . self::OPTION_NAME . '[redirect_enabled]" value="1" ' . checked( $redirect_enabled, '1', false ) . '> '; 411 echo __( 'Enable custom redirect instead of showing error message', 'wp-user-profile-restriction' ); 412 echo '</label>'; 413 echo '<p class="description">' . __( 'If disabled, users will see an error message when trying to access their profile.', 'wp-user-profile-restriction' ) . '</p>'; 414 } 415 416 /** 417 * Redirect URL callback 418 */ 419 public function redirect_url_callback() { 420 $settings = $this->get_settings(); 421 $redirect_url = $settings['redirect_url']; 422 423 echo '<input type="url" name="' . self::OPTION_NAME . '[redirect_url]" value="' . esc_attr( $redirect_url ) . '" class="regular-text" placeholder="' . esc_attr( home_url() ) . '">'; 424 echo '<p class="description">' . __( 'Enter the full URL where restricted users should be redirected (e.g., homepage or custom access denied page). Leave empty to use homepage.', 'wp-user-profile-restriction' ) . '</p>'; 425 } 426 427 /** 428 * Render settings page 429 */ 430 public function render_settings_page() { 431 if ( ! current_user_can( 'manage_options' ) ) { 432 return; 433 } 434 435 // Check if settings were saved 436 if ( isset( $_GET['settings-updated'] ) ) { 437 add_settings_error( 438 'wpupr_messages', 439 'wpupr_message', 440 __( 'Settings Saved Successfully!', 'wp-user-profile-restriction' ), 441 'updated' 442 ); 443 } 444 445 settings_errors( 'wpupr_messages' ); 446 447 // Action: Before settings page render 448 do_action( 'wpupr_before_settings_page' ); 449 ?> 450 <div class="wrap"> 451 <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> 452 453 <?php 454 // Action: After settings page title 455 do_action( 'wpupr_after_settings_page_title' ); 456 ?> 457 458 <div class="notice notice-info" style="margin-top: 20px;"> 459 <p><strong><?php _e( 'Important:', 'wp-user-profile-restriction' ); ?></strong> <?php _e( 'Administrators always have full access to edit profiles regardless of these settings.', 'wp-user-profile-restriction' ); ?></p> 460 </div> 461 462 <?php 463 // Action: Before settings form 464 do_action( 'wpupr_before_settings_form' ); 465 ?> 466 467 <form action="options.php" method="post"> 468 <?php 469 settings_fields( 'wpupr_settings_group' ); 470 do_settings_sections( 'wpupr-settings' ); 471 472 // Action: Before submit button 473 do_action( 'wpupr_before_submit_button' ); 474 475 submit_button( __( 'Save Settings', 'wp-user-profile-restriction' ) ); 476 ?> 477 </form> 478 479 <?php 480 // Action: After settings form 481 do_action( 'wpupr_after_settings_form' ); 482 ?> 483 484 <hr style="margin: 30px 0;"> 485 486 <div class="wpupr-info-box" style="background: #fff; border: 1px solid #ccd0d4; padding: 20px; max-width: 800px;"> 487 <h2><?php _e( 'How It Works', 'wp-user-profile-restriction' ); ?></h2> 488 <ul style="list-style: disc; margin-left: 20px;"> 489 <li><?php _e( '<strong>Role-Based Restrictions:</strong> Select which user roles cannot edit their profiles.', 'wp-user-profile-restriction' ); ?></li> 490 <li><?php _e( '<strong>Profile Access:</strong> The "Profile" menu remains visible, but restricted users are blocked when they try to access it.', 'wp-user-profile-restriction' ); ?></li> 491 <li><?php _e( '<strong>Custom Redirect:</strong> Optionally redirect restricted users to a specific page instead of showing an error message.', 'wp-user-profile-restriction' ); ?></li> 492 <li><?php _e( '<strong>Security:</strong> Administrators always retain full access regardless of settings.', 'wp-user-profile-restriction' ); ?></li> 493 </ul> 494 495 <?php 496 // Action: In info box (for adding premium features info) 497 do_action( 'wpupr_settings_info_box' ); 498 ?> 499 500 <h3 style="margin-top: 20px;"><?php _e( 'Default Behavior', 'wp-user-profile-restriction' ); ?></h3> 501 <p><?php _e( 'By default, Subscribers and Contributors are restricted to maintain backward compatibility and security. You can customize this behavior using the settings above.', 'wp-user-profile-restriction' ); ?></p> 502 </div> 503 504 <?php 505 // Action: Before plugin info 506 do_action( 'wpupr_before_plugin_info' ); 507 ?> 508 509 <div style="margin-top: 20px; padding: 15px; background: #f0f0f1; border-left: 4px solid #2271b1;"> 510 <p style="margin: 0;"> 511 <strong><?php _e( 'Plugin Version:', 'wp-user-profile-restriction' ); ?></strong> <?php echo self::VERSION; ?> | 512 <strong><?php _e( 'Author:', 'wp-user-profile-restriction' ); ?></strong> Shawon 513 </p> 514 </div> 515 516 <?php 517 // Action: After settings page render 518 do_action( 'wpupr_after_settings_page' ); 519 ?> 520 </div> 521 <?php 522 } 25 523 } 26 524 27 add_action( 'load-profile.php', 'wpupr_disable_editing_my_profile' ); 525 // Initialize the plugin 526 new WP_User_Profile_Restriction();
Note: See TracChangeset
for help on using the changeset viewer.