Plugins: Fix wp_edit_theme_plugin_file() to detect network-active plugins - #13620
bishalsthadev wants to merge 1 commit into
Conversation
plugins. $is_active only checked the site-level active_plugins option, so the fatal-error loopback check was silently skipped for network-active plugins. Use is_plugin_active() instead, which already accounts for network activation.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @bishalsthadev. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| deactivate_plugins( $plugin ); | ||
| revoke_super_admin( $user_id ); | ||
|
|
There was a problem hiding this comment.
These shouldn't be needed. The they are automatically cleaned up.
| deactivate_plugins( $plugin ); | |
| revoke_super_admin( $user_id ); |
| $loopback_requested = false; | ||
| add_filter( | ||
| 'pre_http_request', | ||
| function ( $preempt, $parsed_args, $url ) use ( &$loopback_requested ) { |
There was a problem hiding this comment.
| function ( $preempt, $parsed_args, $url ) use ( &$loopback_requested ) { | |
| static function ( $preempt, array $parsed_args, string $url ) use ( &$loopback_requested ) { |
| wp_edit_theme_plugin_file( | ||
| array( | ||
| 'plugin' => $plugin, | ||
| 'file' => $plugin, | ||
| 'newcontent' => file_get_contents( WP_PLUGIN_DIR . '/' . $plugin ), | ||
| 'nonce' => wp_create_nonce( 'edit-plugin_' . $plugin ), | ||
| ) | ||
| ); |
There was a problem hiding this comment.
Shouldn't this assert that the return value is true as well?
| wp_set_current_user( $user_id ); | ||
|
|
||
| $plugin = 'hello.php'; | ||
| activate_plugin( $plugin, '', true ); |
There was a problem hiding this comment.
| activate_plugin( $plugin, '', true ); | |
| $this->assertNull( activate_plugin( $plugin, '', true ) ); |
Fixes https://core.trac.wordpress.org/ticket/66129
wp_edit_theme_plugin_file() checked plugin activity with a raw in_array()
against the active_plugins option, which never accounts for network-wide
activation. is_plugin_active() already handles both cases and is used
elsewhere in this file, so this swaps in that helper and adds a
multisite unit test for the loopback-check behavior.