$match ) { $lines = str_replace( $match, $matches[1][ $k ], $lines ); } } /** * make sure debugging is actually off */ // split the lines up, set flag $split = preg_split( '/[\n\r]+/', $lines ); $its_off = false; // go through each one foreach ( $split as $k => $line ) { // do we have a true statement? if ( preg_match( '/^\s*define\(.*WP_DEBUG.*true.*\).*;/iU', $line, $matches ) ) { // make it false $lines = str_replace( $line, "define( 'WP_DEBUG', false );", $lines ); // it's off $its_off = true; break; } // do we have a false statement? if ( preg_match( '/^\s*define\(.*WP_DEBUG.*false.*\).*;/iU', $line, $matches ) ) { // it's off $its_off = true; break; } } // if it's not off, throw error and exit if ( ! $its_off ) { // add the error and exit add_action( 'admin_notices', 'wpsd_error_cannot_revert' ); return; } // write to the file if ( wpsd_write_config_file( $lines ) ) { // display success add_action( 'admin_notices', 'wpsd_notice_update_success' ); } else { // or display error add_action( 'admin_notices', 'wpsd_error_config_not_writable' ); } } register_deactivation_hook( __FILE__, 'wpsd_deactivate' ); register_uninstall_hook( __FILE__, 'wpsd_deactivate' ); /** * Function that will remove our settings block * * @param string : $lines - The content of the wp-config file. * @return string : The content with the block of settings removed * @since 0.0.1 */ function wpsd_remove_config_settings_section( $lines ) { // our regex $search = '|\/\*\*\*\* Begin WP Simple Debug.*End WP Simple Debug \*\*\*\*\/[\n\r]+|mis'; return preg_replace( $search, '', $lines ); } /** * Function that notifies user wp-config has been updated * * @since 0.0.1 */ function wpsd_notice_update_success() { echo '

WP Simple Debug: wp-config.php was successfully updated.

'; } /** * Function that notifies user wp-config cannot be reverted * * @since 0.0.1 */ function wpsd_error_cannot_revert() { echo '

WP Simple Debug: Not able to remove settings from wp-config.php file.

Please make sure the below lines are removed from your wp-config.php file:
/**** Begin WP Simple Debug ****/
define( \'WP_DEBUG\', true );
define( \'WP_DEBUG_LOG\', true );
define( \'WP_DEBUG_DISPLAY\', false );
/**** End WP Simple Debug ****/

You will also need to make sure this line is added after the debug section:
define( \'WP_DEBUG\', false );

'; } /** * Function that notifies user wp-config cannot be found * * @since 0.0.1 */ function wpsd_error_no_config_file() { echo '

WP Simple Debug: Not able to locate wp-config.php file.

Please make sure the below settings are added to your wp-config.php file, or else debugging will not work:
define( \'WP_DEBUG\', true );
define( \'WP_DEBUG_LOG\', true );
define( \'WP_DEBUG_DISPLAY\', false );

'; } /** * Function that notifies user wp-config cannot be updated * * @since 0.0.1 */ function wpsd_error_config_not_writable() { echo '

WP Simple Debug: It appears wp-config.php is not writable.

Please make sure the below settings are added to your wp-config.php file, or else debugging will not work:
define( \'WP_DEBUG\', true );
define( \'WP_DEBUG_LOG\', true );
define( \'WP_DEBUG_DISPLAY\', false );

'; }