settings = Plugin::get_settings( 'security' ); add_filter( 'adminease_settings_fields', [ $this, 'adminease_settings_fields' ] ); add_action( 'adminease_settings_saved', [ $this, 'adminease_settings_saved' ] ); if( self::is_blocking_updates() ) { add_action( 'in_admin_header', [ $this, 'render_updates_warning' ] ); } add_action( 'admin_post_' . self::DISMISS_ACTION, [ $this, 'handle_dismiss' ] ); } /** * Whether WordPress is really blocked from installing and updating files right now. * * @return bool */ public static function is_blocking_updates(): bool { $settings = Plugin::get_settings( 'security' ); return !empty( $settings['disallow_file_mods'] ) && defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS; } /** * Shows a warning on the Dashboard and Updates screens while updates are blocked. * Each admin can hide it for 30 days. * * @return void */ public function render_updates_warning(): void { $screen = get_current_screen(); if( !$screen || !in_array( $screen->id, [ 'dashboard', 'update-core' ], true ) || !current_user_can( 'manage_options' ) ) { return; } $dismissed_at = (int) get_user_meta( get_current_user_id(), self::DISMISS_META, true ); if( $dismissed_at > 0 && ( time() - $dismissed_at ) < ( 30 * DAY_IN_SECONDS ) ) { return; } $dismiss_url = wp_nonce_url( add_query_arg( [ 'action' => self::DISMISS_ACTION ], admin_url( 'admin-post.php' ) ), self::DISMISS_ACTION ); ?>

|

'switch', 'id' => 'disallow-file-mods', 'name' => 'adminease[security][disallow_file_mods]', 'value' => $this->settings['disallow_file_mods'] ?? false, 'label_class' => 'pwp-switch', 'input_class' => 'pwp-field-input', 'label' => __( 'Disallow file modifications', 'adminease' ), 'risk' => 'careful', 'breaks' => __( 'Installing and updating plugins, themes and WordPress from the dashboard stops.', 'adminease' ), 'description' => __( "Stops WordPress from installing, updating or deleting plugins, themes and translations from the dashboard. This also stops automatic security updates. Only use it if you update the site another way, such as version control or a staging site. This is a more restrictive measure than disabling file editing alone.", 'adminease' ), ]; return $fields; } /** * Saves the settings for the Adminease plugin. * * @param array $sanitized_settings The settings array containing configuration options, including security settings for 'disallow_file_mods'. * * @return void */ public function adminease_settings_saved( array $sanitized_settings ): void { FileHandler::get_instance()->stack_wp_config_constant( 'DISALLOW_FILE_MODS', ! empty( $sanitized_settings['security']['disallow_file_mods'] ) ); } }