Skip to content

Fix: use fileperms() instead of stat() and fix escaping#1023

Merged
donnchawp merged 3 commits into
trunkfrom
cherry-pick/607-fileperms-stat
Apr 14, 2026
Merged

Fix: use fileperms() instead of stat() and fix escaping#1023
donnchawp merged 3 commits into
trunkfrom
cherry-pick/607-fileperms-stat

Conversation

@kraftbj
Copy link
Copy Markdown
Contributor

@kraftbj kraftbj commented Apr 7, 2026

Summary

  • Replace stat() with fileperms() for retrieving directory permissions in wp-cache.php. fileperms() returns the mode directly, removing the need for array access on the stat() result.
  • Fix escaping in the mobile rewrite rules warning block: use esc_html_e() for plain-text translatable strings and esc_html() for variables passed to printf().
  • Fix an unclosed <p> tag in the same block.

Originally proposed by @stodorovic in #607.

See #607

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with fileperms() when checking WP_CONTENT_DIR permissions.
  • 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.

Comment thread wp-cache.php Outdated
<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>
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
<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() ) ); ?>

Copilot uses AI. Check for mistakes.
Comment thread wp-cache.php Outdated
Comment on lines +675 to +677
<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>
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@kraftbj kraftbj force-pushed the cherry-pick/607-fileperms-stat branch from 4b194d8 to 1ccd866 Compare April 7, 2026 22:07
@donnchawp donnchawp marked this pull request as ready for review April 13, 2026 13:25
Copy link
Copy Markdown
Contributor

@donnchawp donnchawp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thumbs up from me!

@donnchawp donnchawp merged commit bf44af1 into trunk Apr 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants