Skip to content

Commit

Permalink
add notice and exit if wp-config.php not writable
Browse files Browse the repository at this point in the history
better test for writable wp-config.php
  • Loading branch information
afragen committed Nov 6, 2019
1 parent e47243a commit 31caeba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
44 changes: 28 additions & 16 deletions src/WPBT/WPBT_Extras.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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' ),
)
);
}

}

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion wp-beta-tester.php
Expand Up @@ -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
Expand Down

0 comments on commit 31caeba

Please sign in to comment.