From edd8a0e52bc100e74aae66bcef47b53d461e8ec3 Mon Sep 17 00:00:00 2001 From: Thomas Zwirner Date: Mon, 11 Nov 2024 20:52:27 +0100 Subject: [PATCH] fixed set capabilities on update (solves #46) --- app/Plugin/Update.php | 32 ++++++++++++++++++++++++++++---- readme.txt | 2 ++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/Plugin/Update.php b/app/Plugin/Update.php index 3920c17..5ad410d 100644 --- a/app/Plugin/Update.php +++ b/app/Plugin/Update.php @@ -78,6 +78,7 @@ function_exists( 'wp_is_development_mode' ) && false === wp_is_development_mode( define( 'EFML_UPDATE_RUNNING', 1 ); } $this->version200(); + $this->version201(); // save new plugin-version in DB. update_option( 'efmlVersion', $installed_plugin_version ); @@ -90,13 +91,36 @@ function_exists( 'wp_is_development_mode' ) && false === wp_is_development_mode( * @return void */ private function version200(): void { - // add option for version of this plugin. - add_option( 'efmlVersion', '', '', true ); + if ( ! get_option( 'efmlVersion', false ) ) { + // add option for version of this plugin. + add_option( 'efmlVersion', '', '', true ); + } // run the same tasks for all settings as if we activate the plugin. Settings::get_instance()->activation(); + } + + /** + * To run on update to version 2.0.1 or newer. + * + * @return void + */ + private function version201(): void { + // get actual capabilities. + $caps = get_option( 'eml_allowed_roles' ); + + // check for array. + if ( ! is_array( $caps ) ) { + $caps = array(); + } + + // if list is empty, set the defaults. + if ( empty( $caps ) ) { + $caps = array( 'administrator', 'editor' ); + update_option( 'eml_allowed_roles', $caps ); + } - // hide GPRD-hint for old installations. - update_option( 'eml_disable_gprd_warning', 1 ); + // set capabilities. + Helper::set_capabilities( $caps ); } } diff --git a/readme.txt b/readme.txt index 2d71b65..5887ced 100644 --- a/readme.txt +++ b/readme.txt @@ -195,5 +195,7 @@ Yes, there are many options on WP CLI, see [our documentation](https://github.co = 2.0.1 = * Small optimizations on texts for better translations +* GPRD-hint is now also shown for old installations if it is not disabled * Fixed update handler for WordPress 6.7 * Fixed setting of capabilities for Playground +* Fixed setting of capabilities on update