diff --git a/CHANGES.md b/CHANGES.md index adc0395..e02490f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ [unreleased] * added support for updating to the _beta/RC offer_. Based on and with tons of help from @pbrion, thanks Paul 👏🏻 * fixed so a downgrade from 'unstable' to 'point' serves the correct download +* test and exit from **Extra Settings** if `wp-config.php` is not writeable #### 2.1.0 / 2019-09-17 * add extra setting to skip successful autoupdate emails diff --git a/src/WPBT/WPBT_Extras.php b/src/WPBT/WPBT_Extras.php index a62d2a7..b1ccc68 100644 --- a/src/WPBT/WPBT_Extras.php +++ b/src/WPBT/WPBT_Extras.php @@ -80,6 +80,15 @@ public function get_config_path() { return apply_filters( 'wp_beta_tester_config_path', $config_path ); } + /** + * Test to see if wp-config.php is writable. + * + * @return bool + */ + public function is_config_writable() { + return is_writable( self::$config_path ); + } + /** * Add class settings tab. * @@ -129,19 +138,22 @@ public function add_settings() { ) ); - // Example. - add_settings_field( - 'example', - null, - array( 'WPBT_Settings', 'checkbox_setting' ), - 'wp_beta_tester_extras', - 'wp_beta_tester_new_feature_testing', - array( - 'id' => 'example', - 'title' => esc_html__( 'Just an example.', 'wordpress-beta-tester' ), - 'description' => esc_html__( 'Look in `wp-config.php` for results.', 'wordpress-beta-tester' ), - ) - ); + if ( $this->is_config_writable() ) { + // Example. + add_settings_field( + 'example', + null, + array( 'WPBT_Settings', 'checkbox_setting' ), + 'wp_beta_tester_extras', + 'wp_beta_tester_new_feature_testing', + array( + 'id' => 'example', + 'title' => esc_html__( 'Just an example.', 'wordpress-beta-tester' ), + 'description' => esc_html__( 'Look in `wp-config.php` for results.', 'wordpress-beta-tester' ), + ) + ); + } + } /** @@ -241,7 +253,7 @@ private function update_constants( $old, $new ) { * @return void */ private function add_constants( $add ) { - if ( ! file_exists( self::$config_path ) ) { + if ( ! $this->is_config_writable() ) { return; } @@ -265,7 +277,7 @@ private function add_constants( $add ) { * @return void */ private function remove_constants( $remove ) { - if ( ! file_exists( self::$config_path ) ) { + if ( ! $this->is_config_writable() ) { return; } @@ -292,7 +304,7 @@ public function save_redirect_page( $option_page ) { * @return void */ public function print_new_feature_testing_top() { - esc_html_e( 'This area is for extra special beta testing. If nothing is present there are no additional features that need testing. Features will set constants in the `wp-config.php` file.', 'wordpress-beta-tester' ); + esc_html_e( 'This area is for extra special beta testing. If nothing is present there are no additional features that need testing or the `wp-config.php` file is not writable. Features will set constants in the `wp-config.php` file.', 'wordpress-beta-tester' ); } /** diff --git a/wp-beta-tester.php b/wp-beta-tester.php index 53964ad..261853c 100644 --- a/wp-beta-tester.php +++ b/wp-beta-tester.php @@ -13,7 +13,7 @@ * Plugin URI: https://wordpress.org/plugins/wordpress-beta-tester/ * Description: Allows you to easily upgrade to Beta releases. * Author: Peter Westwood, Andy Fragen - * Version: 2.1.0.4 + * Version: 2.1.0.5 * Network: true * Author URI: https://blog.ftwr.co.uk/ * Text Domain: wordpress-beta-tester