• Shannon Little

    (@enchiridion)


    Hi, I noticed that whenever the plugin is de/activated, it writes define( 'WP_CACHE', true/false ); to the top of wp-config.php, which is fine, however it also modifies the entire file by stripping all consecutive newlines, even inside of comments. So my nicely formatted file was completely mangled. Could you please fix this?

    Also it would be preferable if it could insert the constant right above /* That's all, stop editing! Happy blogging. */ instead of at the very top of the file. That’s where other plugins inject theirs.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author owaisalam

    (@owaisalam)

    Thank you for reaching out to us.

    We have verified this using WordPress PHP file formatting, and it functions correctly without any issues. It is possible that the formatting pattern you followed is not fully supported, which may have caused the file’s pattern to be modified.

    If you need further clarification or assistance, please let us know—we’d be happy to help!

    Thread Starter Shannon Little

    (@enchiridion)

    Hi,

    I checked your toggle_caching() code against an edited wp-config.php and untouched wp-config-sample.php. I found the difference is wp-config-sample.php is saved using CRLF line endings, while any edited files (on a Linux system or vscode) will convert the line endings to LF. Your function doesn’t take into account that different line endings could be used. Instead of trying to parse the lines yourself, you could update the line

    $config_file_string = $wp_filesystem->get_contents( $config_path );

    to use get_contents_array(), which handles the lines ending differences for you

    $config_file = $wp_filesystem->get_contents_array( $config_path );

    This would require an update to where your code rewrites the top of the file to set the WP_CACHE constant and further down implode( PHP_EOL, $config_file ) would need to be changed to implode( '', $config_file ).

    Thread Starter Shannon Little

    (@enchiridion)

    @owaisalam Bump

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Plugin stripping newlines from wp-config.php’ is closed to new replies.