Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Kim Swenson
Kim Swenson
6,379 Points

Installing a patch for local WordPress files

I'm having trouble installing a patch for the latest version of Wordpress (4.9). There is a known issue with the new ajax code. Basically, you can't edit the CSS files if you are using Windows computer for your local server. There is a patch in place until this is fixed, but I'm getting confused trying to install it.

Here is the ticket with the patch and description of the issue: https://core.trac.wordpress.org/ticket/42609

At the bottom of the description area, it says that "Replacing validate_file with validate_file_to_edit in wp_edit_theme_plugin_file() should fix the issue." Where do I replace this?

Thank you in advance!

1 Answer

Liam Maclachlan
Liam Maclachlan
22,805 Points

Hi Kim,

I had a look in the .patch and .diff files and it shows the folowing:

Index: wp-admin/includes/file.php
===================================================================
--- wp-admin/includes/file.php  (revision 42032)
+++ wp-admin/includes/file.php  (working copy)
@@ -385,7 +385,7 @@
            return new WP_Error( 'invalid_plugin' );
        }

-       if ( 0 !== validate_file( $file, get_plugin_files( $plugin ) ) ) {
+       if ( ! in_array( validate_file( $file, get_plugin_files( $plugin ) ), array( 0, 2 ) ) ) {
            return new WP_Error( 'bad_plugin_file_path', __( 'Sorry, that file cannot be edited.' ) );
        }

@@ -445,7 +445,7 @@
            }
        }

-       if ( 0 !== validate_file( $real_file, $allowed_files ) ) {
+       if ( ! in_array( validate_file( $real_file, $allowed_files ), array( 0, 2 ) ) ) {
            return new WP_Error( 'disallowed_theme_file', __( 'Sorry, that file cannot be edited.' ) );
        }

and .diff:

Index: src/wp-admin/includes/file.php
===================================================================
--- src/wp-admin/includes/file.php  (revision 42224)
+++ src/wp-admin/includes/file.php  (working copy)
@@ -433,31 +433,31 @@ function wp_edit_theme_plugin_file( $arg
            switch ( $type ) {
                case 'php':
                    $allowed_files = array_merge( $allowed_files, $theme->get_files( 'php', -1 ) );
                    break;
                case 'css':
                    $style_files = $theme->get_files( 'css', -1 );
                    $allowed_files['style.css'] = $style_files['style.css'];
                    $allowed_files = array_merge( $allowed_files, $style_files );
                    break;
                default:
                    $allowed_files = array_merge( $allowed_files, $theme->get_files( $type, -1 ) );
                    break;
            }
        }

-       if ( 0 !== validate_file( $real_file, $allowed_files ) ) {
+       if ( 0 !== validate_file( $file, array_keys( $allowed_files ) ) ) {
            return new WP_Error( 'disallowed_theme_file', __( 'Sorry, that file cannot be edited.' ) );
        }

        $is_active = ( get_stylesheet() === $stylesheet || get_template() === $stylesheet );
    } else {
        return new WP_Error( 'missing_theme_or_plugin' );
    }

    // Ensure file is real.
    if ( ! is_file( $real_file ) ) {
        return new WP_Error( 'file_does_not_exist', __( 'No such file exists! Double check the name and try again.' ) );
    }

    // Ensure file extension is allowed.
    $extension = null;

You need to go in to the files (wp-admin/includes/file.php) and replace the lines with the '-' sign at the start with the lines below that has the '+' sign at the start.

Hope this helps. Let me know if you have any further issues.

Cheers :)