Fix: use fileperms() instead of stat() and fix escaping#1023
Conversation
There was a problem hiding this comment.
Pull request overview
Updates WP Super Cache admin error checks to simplify permission detection and harden/clean up the “mobile rewrite rules” warning output.
Changes:
- Replace
stat()usage withfileperms()when checkingWP_CONTENT_DIRpermissions. - Improve escaping for translatable strings/variables in the rewrite-rules warning notice.
- Adjust markup in the warning notice (attempting to fix paragraph tag structure).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <li> <?php printf( __( 'Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?></li> | ||
| <li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?></p> | ||
| <li> <?php printf( __( 'Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), esc_html( $home_path ) ); ?></li> | ||
| <li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), esc_html( $home_path ), esc_html( wpsc_get_logged_in_cookie() ) ); ?></p> |
There was a problem hiding this comment.
There’s an extra closing </p> at the end of this printf() line, but the paragraph was already closed on line 673. This results in invalid HTML markup in the notice (and the <div>/<pre> that follows cannot be inside a <p> anyway). Remove the stray </p> (or restructure the list item markup so tags are properly nested).
| <li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), esc_html( $home_path ), esc_html( wpsc_get_logged_in_cookie() ) ); ?></p> | |
| <li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), esc_html( $home_path ), esc_html( wpsc_get_logged_in_cookie() ) ); ?> |
| <li> <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></li> | ||
| <li> <?php printf( __( 'Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?></li> | ||
| <li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?></p> | ||
| <li> <?php printf( __( 'Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), esc_html( $home_path ) ); ?></li> | ||
| <li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), esc_html( $home_path ), esc_html( wpsc_get_logged_in_cookie() ) ); ?></p> |
There was a problem hiding this comment.
These list items output translated strings that include HTML (<strong>, <code>, etc.) via _e() / printf( __( ... ) ) without sanitizing the final output. To follow WordPress output-escaping guidance while keeping the intended markup, sanitize the rendered string (e.g., wp_kses_post() or a stricter allowed-tags list) and continue escaping interpolated variables separately.
4b194d8 to
1ccd866
Compare
donnchawp
left a comment
There was a problem hiding this comment.
Looks good! Thumbs up from me!
Summary
stat()withfileperms()for retrieving directory permissions inwp-cache.php.fileperms()returns the mode directly, removing the need for array access on thestat()result.esc_html_e()for plain-text translatable strings andesc_html()for variables passed toprintf().<p>tag in the same block.Originally proposed by @stodorovic in #607.
See #607