Skip to content

Refactor: optimize multisite plugin output and reduce duplication#1022

Draft
kraftbj wants to merge 1 commit into
trunkfrom
cherry-pick/606-multisite-optimization
Draft

Refactor: optimize multisite plugin output and reduce duplication#1022
kraftbj wants to merge 1 commit into
trunkfrom
cherry-pick/606-multisite-optimization

Conversation

@kraftbj
Copy link
Copy Markdown
Contributor

@kraftbj kraftbj commented Apr 7, 2026

Summary

Manually cherry-picks the still-valid refactoring changes from closed PR #606 (which couldn't be reopened due to history divergence), adapted to the current trunk codebase.

Originally proposed by @stodorovic in #606.

Changes to plugins/multisite.php:

  • Refactor the Enable/Disable cache link output in wp_super_cache_blogs_field() to use a single printf() with esc_url() and esc_html() instead of duplicated echo + wp_nonce_url() calls
  • Introduce a $cache_disabled variable to eliminate the duplicated get_blog_option() call
  • Use wp_create_nonce() directly in query args for cleaner, more explicit nonce handling
  • Add WPCS suppression comments for $_GET accesses
  • Properly sanitize the nonce value with sanitize_text_field() and wp_unslash()

See #606

Test plan

  • Verify on a multisite install that the "Cached" column appears on the Network Admin > Sites page
  • Verify clicking "Disable" disables caching for that site and the link changes to "Enable"
  • Verify clicking "Enable" re-enables caching and the link changes back to "Disable"
  • Verify the nonce check still works (manually tampering with the URL should fail)

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

This PR refactors the multisite “Cached” column action links in wp_super_cache_blogs_field() to reduce duplicated logic and make link generation/escaping more consistent, based on the still-applicable parts of closed PR #606.

Changes:

  • Refactors Enable/Disable link output to a single printf() using esc_url()/esc_html().
  • Avoids a duplicated get_blog_option() call by introducing $cache_disabled and deriving action/text from it.
  • Adjusts nonce creation/verification and adds PHPCS suppressions around $_GET access.
Comments suppressed due to low confidence (1)

plugins/multisite.php:32

  • filter_input( INPUT_GET, 'action' ) is called twice in the same block. Assign it once to a local $action variable before the conditional chain to reduce duplication and make the control flow easier to follow.
		if ( 'disable_cache' === filter_input( INPUT_GET, 'action' ) ) {
			add_blog_option( $blog_id, 'wp_super_cache_disabled', 1 );
		} elseif ( 'enable_cache' === filter_input( INPUT_GET, 'action' ) ) {
			delete_blog_option( $blog_id, 'wp_super_cache_disabled' );

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/multisite.php Outdated
@kraftbj kraftbj force-pushed the cherry-pick/606-multisite-optimization branch from 9781849 to 612cb29 Compare April 7, 2026 22:03
@kraftbj kraftbj force-pushed the cherry-pick/606-multisite-optimization branch from eb1863d to aa53690 Compare April 7, 2026 22:23
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.

3 participants