Changeset 3463674
- Timestamp:
- 02/17/2026 04:31:42 PM (6 weeks ago)
- Location:
- grabwp-tenancy/trunk
- Files:
-
- 1 added
- 5 edited
-
admin/views/settings.php (modified) (1 diff)
-
grabwp-tenancy.php (modified) (6 diffs)
-
includes/class-grabwp-tenancy-admin.php (modified) (2 diffs)
-
includes/class-grabwp-tenancy-settings.php (added)
-
includes/class-grabwp-tenancy-tenant.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
grabwp-tenancy/trunk/admin/views/settings.php
r3370567 r3463674 17 17 <p><?php esc_html_e( 'Configure your multi-tenant WordPress setup.', 'grabwp-tenancy' ); ?></p> 18 18 19 <?php 20 // Success notice after saving settings. 21 if ( isset( $_GET['message'] ) && 'settings_saved' === $_GET['message'] 22 && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'grabwp_tenancy_notice' ) ) : 23 ?> 24 <div class="notice notice-success is-dismissible"> 25 <p><?php esc_html_e( 'Settings saved successfully.', 'grabwp-tenancy' ); ?></p> 26 </div> 27 <?php endif; ?> 28 19 29 <div class="grabwp-tenancy-content"> 30 31 <div class="grabwp-tenancy-form"> 32 <h3><?php esc_html_e( 'Tenant Capabilities', 'grabwp-tenancy' ); ?></h3> 33 <p class="description"><?php esc_html_e( 'Control what tenant site administrators are allowed to do.', 'grabwp-tenancy' ); ?></p> 34 35 <form method="post" action=""> 36 <?php wp_nonce_field( 'grabwp_tenancy_save_settings' ); ?> 37 <input type="hidden" name="action" value="save_settings" /> 38 39 <table class="form-table"> 40 <tr> 41 <th scope="row"><?php esc_html_e( 'Install Plugins & Themes', 'grabwp-tenancy' ); ?></th> 42 <td> 43 <label> 44 <input type="checkbox" name="disallow_file_mods" value="1" <?php checked( ! empty( $settings['disallow_file_mods'] ) ); ?> /> 45 <?php esc_html_e( 'Disallow tenant admins to install, update, and delete plugins/themes (DISALLOW_FILE_MODS)', 'grabwp-tenancy' ); ?> 46 </label> 47 </td> 48 </tr> 49 <tr> 50 <th scope="row"><?php esc_html_e( 'Edit Plugins & Themes', 'grabwp-tenancy' ); ?></th> 51 <td> 52 <label> 53 <input type="checkbox" name="disallow_file_edit" value="1" <?php checked( ! empty( $settings['disallow_file_edit'] ) ); ?> /> 54 <?php esc_html_e( 'Disallow tenant admins to use the built-in plugin/theme file editor (DISALLOW_FILE_EDIT)', 'grabwp-tenancy' ); ?> 55 </label> 56 </td> 57 </tr> 58 <tr> 59 <th scope="row"><?php esc_html_e( 'Hide Plugin Management', 'grabwp-tenancy' ); ?></th> 60 <td> 61 <label> 62 <input type="checkbox" name="hide_plugin_management" value="1" <?php checked( ! empty( $settings['hide_plugin_management'] ) ); ?> /> 63 <?php esc_html_e( 'Hide the Plugins menu entirely from tenant admin dashboards', 'grabwp-tenancy' ); ?> 64 </label> 65 </td> 66 </tr> 67 <tr> 68 <th scope="row"><?php esc_html_e( 'Hide Theme Management', 'grabwp-tenancy' ); ?></th> 69 <td> 70 <label> 71 <input type="checkbox" name="hide_theme_management" value="1" <?php checked( ! empty( $settings['hide_theme_management'] ) ); ?> /> 72 <?php esc_html_e( 'Hide the Appearance menu entirely from tenant admin dashboards', 'grabwp-tenancy' ); ?> 73 </label> 74 </td> 75 </tr> 76 <tr> 77 <th scope="row"><?php esc_html_e( 'Hide GrabWP Plugins', 'grabwp-tenancy' ); ?></th> 78 <td> 79 <label> 80 <input type="checkbox" name="hide_grabwp_plugins" value="1" <?php checked( ! empty( $settings['hide_grabwp_plugins'] ) ); ?> /> 81 <?php esc_html_e( 'Hide GrabWP plugins from the plugin list on tenant sites', 'grabwp-tenancy' ); ?> 82 </label> 83 </td> 84 </tr> 85 </table> 86 87 <?php submit_button( __( 'Save Settings', 'grabwp-tenancy' ) ); ?> 88 </form> 89 </div> 90 91 <hr /> 20 92 <?php 21 93 // Show migration warning if using legacy path structure -
grabwp-tenancy/trunk/grabwp-tenancy.php
r3370567 r3463674 4 4 * Plugin URI: https://grabwp.com/tenancy 5 5 * Description: Foundation multi-tenant WordPress solution with shared MySQL database and separated uploads. Designed to be extended by GrabWP Tenancy Pro for advanced features. 6 * Version: 1.0. 46 * Version: 1.0.5 7 7 * Author: GrabWP 8 8 * Author URI: https://grabwp.com … … 25 25 26 26 // Define plugin constants 27 define( 'GRABWP_TENANCY_VERSION', '1.0. 4' );27 define( 'GRABWP_TENANCY_VERSION', '1.0.5' ); 28 28 define( 'GRABWP_TENANCY_PLUGIN_FILE', __FILE__ ); 29 29 define( 'GRABWP_TENANCY_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); … … 147 147 require_once $this->plugin_dir . 'includes/class-grabwp-tenancy-loader.php'; 148 148 require_once $this->plugin_dir . 'includes/class-grabwp-tenancy-tenant.php'; 149 require_once $this->plugin_dir . 'includes/class-grabwp-tenancy-settings.php'; 149 150 require_once $this->plugin_dir . 'includes/class-grabwp-tenancy-admin.php'; 150 151 require_once $this->plugin_dir . 'includes/class-grabwp-tenancy-admin-notice.php'; … … 187 188 } 188 189 190 // Apply tenant capability restrictions from settings. 191 $this->apply_tenant_settings(); 192 189 193 // Hide Pro plugin from tenant admin dashboards 190 194 $this->hide_pro_plugin_from_tenant_admin(); 191 195 196 // Hide GrabWP base plugin from tenant admin dashboards 197 $this->hide_grabwp_plugin_from_tenant_admin(); 198 192 199 // Allow pro plugin to extend tenant functionality 193 200 do_action( 'grabwp_tenancy_init_tenant_only', $this ); 201 202 } 203 204 /** 205 * Apply tenant capability settings. 206 * 207 * Defines WordPress constants and hooks menus based on saved settings. 208 * 209 * @since 1.1.0 210 */ 211 private function apply_tenant_settings() { 212 $settings = GrabWP_Tenancy_Settings::get_instance(); 213 214 // DISALLOW_FILE_MODS — controls plugin/theme install, update, and deletion. 215 if ( ! defined( 'DISALLOW_FILE_MODS' ) ) { 216 define( 'DISALLOW_FILE_MODS', $settings->get( 'disallow_file_mods' ) ); 217 } 218 219 // DISALLOW_FILE_EDIT — controls the built-in theme/plugin editor. 220 if ( ! defined( 'DISALLOW_FILE_EDIT' ) ) { 221 define( 'DISALLOW_FILE_EDIT', $settings->get( 'disallow_file_edit' ) ); 222 } 223 224 // Remove admin menus for plugin/theme management if configured. 225 if ( $settings->get( 'hide_plugin_management' ) || $settings->get( 'hide_theme_management' ) ) { 226 add_action( 'admin_menu', array( $this, 'remove_tenant_admin_menus' ), 999 ); 227 } 228 } 229 230 /** 231 * Remove plugin and theme admin menus from tenant dashboards. 232 * 233 * @since 1.1.0 234 */ 235 public function remove_tenant_admin_menus() { 236 $settings = GrabWP_Tenancy_Settings::get_instance(); 237 238 if ( $settings->get( 'hide_plugin_management' ) ) { 239 remove_menu_page( 'plugins.php' ); 240 } 241 242 if ( $settings->get( 'hide_theme_management' ) ) { 243 remove_menu_page( 'themes.php' ); 244 } 194 245 } 195 246 … … 243 294 */ 244 295 private function hide_pro_plugin_from_tenant_admin() { 245 // Hide Pro plugin from the plugins list 246 add_filter( 'all_plugins', array( $this, 'filter_pro_plugin_from_list' ) ); 247 } 248 296 $settings = GrabWP_Tenancy_Settings::get_instance(); 297 if ( $settings->get( 'hide_grabwp_plugins' ) ) { 298 add_filter( 'all_plugins', array( $this, 'filter_pro_plugin_from_list' ) ); 299 } 300 } 301 302 303 /** 304 * Hide GrabWP base plugin from tenant admin dashboards 305 * 306 * @since 1.0.0 307 */ 308 private function hide_grabwp_plugin_from_tenant_admin() { 309 $settings = GrabWP_Tenancy_Settings::get_instance(); 310 if ( $settings->get( 'hide_grabwp_plugins' ) ) { 311 add_filter( 'all_plugins', array( $this, 'filter_grabwp_plugin_from_list' ) ); 312 } 313 } 314 249 315 /** 250 316 * Filter plugins list to hide Pro plugin on tenant sites … … 259 325 if ( isset( $plugins[ $pro_plugin_file ] ) ) { 260 326 unset( $plugins[ $pro_plugin_file ] ); 327 } 328 329 return $plugins; 330 } 331 332 /** 333 * Filter plugins list to hide GrabWP base plugin on tenant sites 334 * 335 * @since 1.0.0 336 * @param array $plugins All plugins list 337 * @return array Filtered plugins list 338 */ 339 public function filter_grabwp_plugin_from_list( $plugins ) { 340 // Hide Pro plugin 341 $grabwp_plugin_file = 'grabwp-tenancy/grabwp-tenancy.php'; 342 if ( isset( $plugins[ $grabwp_plugin_file ] ) ) { 343 unset( $plugins[ $grabwp_plugin_file ] ); 261 344 } 262 345 -
grabwp-tenancy/trunk/includes/class-grabwp-tenancy-admin.php
r3370567 r3463674 187 187 break; 188 188 189 case 'save_settings': 190 if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'grabwp_tenancy_save_settings' ) ) { 191 $settings_instance = GrabWP_Tenancy_Settings::get_instance(); 192 193 // Collect checkbox values from POST — unchecked checkboxes are absent from POST. 194 $raw_settings = array(); 195 foreach ( array_keys( GrabWP_Tenancy_Settings::get_defaults() ) as $key ) { 196 $raw_settings[ $key ] = isset( $_POST[ $key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $key ] ) ) : ''; 197 } 198 199 $result = $settings_instance->save( $raw_settings ); 200 201 if ( $result ) { 202 $success_nonce = wp_create_nonce( 'grabwp_tenancy_notice' ); 203 wp_safe_redirect( admin_url( 'admin.php?page=grabwp-tenancy-settings&message=settings_saved&_wpnonce=' . urlencode( $success_nonce ) ) ); 204 exit; 205 } else { 206 set_transient( 'grabwp_tenancy_error', __( 'Failed to save settings. Please check file permissions.', 'grabwp-tenancy' ), 60 ); 207 $error_nonce = wp_create_nonce( 'grabwp_tenancy_error' ); 208 wp_safe_redirect( admin_url( 'admin.php?page=grabwp-tenancy-settings&error=1&_wpnonce=' . urlencode( $error_nonce ) ) ); 209 exit; 210 } 211 } 212 break; 213 189 214 default: 190 215 /** … … 353 378 /** 354 379 * Settings page 380 * 381 * @since 1.1.0 Added tenant capability settings. 355 382 */ 356 383 public function settings_page() { 357 $this->render_admin_page( 'settings' ); 384 $settings = GrabWP_Tenancy_Settings::get_instance(); 385 $this->render_admin_page( 'settings', array( 'settings' => $settings->get_all() ) ); 358 386 } 359 387 -
grabwp-tenancy/trunk/includes/class-grabwp-tenancy-tenant.php
r3370567 r3463674 76 76 */ 77 77 public static function generate_id() { 78 $characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; 78 $letters = 'abcdefghijklmnopqrstuvwxyz'; 79 $alphanumeric = 'abcdefghijklmnopqrstuvwxyz0123456789'; 79 80 $id = ''; 80 81 81 for ( $i = 0; $i < 6; $i++ ) { 82 $id .= $characters[ wp_rand( 0, strlen( $characters ) - 1 ) ]; 83 } 82 for ( $i = 0; $i < 5; $i++ ) { 83 $id .= $alphanumeric[ wp_rand( 0, strlen( $alphanumeric ) - 1 ) ]; 84 } 85 $id = $letters[ wp_rand( 0, strlen( $letters ) - 1 ) ] . $id; 84 86 85 87 return $id; -
grabwp-tenancy/trunk/readme.txt
r3432960 r3463674 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 1.0. 47 Stable tag: 1.0.5 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 74 74 == Changelog == 75 75 76 = 1.0.5 = 77 - Fix: Tenant ID start with number cause SQLite error 78 76 79 = 1.0.4 = 77 80 - Enhance tenant management with a new list table for admin
Note: See TracChangeset
for help on using the changeset viewer.