-
Notifications
You must be signed in to change notification settings - Fork 6
Fix: Replace automatic plugin deactivation with admin notice #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+227
−66
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ed9fdf
refactor: update legacy plugin deactivation to show admin notice inst…
theMasudRana 95f234f
fix: enhance legacy plugin notice handling for network-wide activations
theMasudRana 040f3c3
test: add legacy plugin notice tests for inactive state and user capa…
theMasudRana 1f0c258
fix: restrict legacy plugin notice display based on admin context
theMasudRana a74e72d
fix: update legacy plugin notice handling for admin context and impro…
theMasudRana eb30eeb
fix: improve deactivation URL handling and update block registration …
theMasudRana 2cd4ad0
fix: update upgrade notice to include admin prompt for deactivating o…
theMasudRana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,22 +39,23 @@ protected function setup_hooks(): void { | |
| add_filter( 'block_categories_all', [ $this, 'register_block_category' ] ); | ||
| add_action( 'init', [ $this, 'register_pattern_category' ] ); | ||
| add_action( 'init', [ $this, 'register_block_patterns' ] ); | ||
| add_action( 'admin_init', [ $this, 'deactivate_legacy_plugin' ] ); | ||
| add_action( 'admin_notices', [ $this, 'legacy_plugin_notice' ] ); | ||
| add_action( 'network_admin_notices', [ $this, 'legacy_plugin_notice' ] ); | ||
| } | ||
|
|
||
| /** | ||
| * Deactivate the legacy "Carousel Kit" plugin if still active. | ||
| * Show an admin notice if the legacy "Carousel Kit" plugin is still active. | ||
| * | ||
| * Handles both single-site and network-wide activations. | ||
| */ | ||
| public function deactivate_legacy_plugin(): void { | ||
| $old_plugin = 'carousel-kit/carousel-kit.php'; | ||
| public function legacy_plugin_notice(): void { | ||
| $old_plugin = 'carousel-kit/carousel-kit.php'; | ||
| $network_wide = is_multisite() && is_plugin_active_for_network( $old_plugin ); | ||
|
|
||
|
theMasudRana marked this conversation as resolved.
|
||
| if ( ! is_plugin_active( $old_plugin ) ) { | ||
| return; | ||
| } | ||
|
|
||
| $network_wide = is_multisite() && is_plugin_active_for_network( $old_plugin ); | ||
| if ( $network_wide && ! current_user_can( 'manage_network_plugins' ) ) { | ||
| return; | ||
| } | ||
|
|
@@ -63,21 +64,41 @@ public function deactivate_legacy_plugin(): void { | |
| return; | ||
| } | ||
|
|
||
| // Silent flag prevents deactivation hooks from firing redirect. | ||
| deactivate_plugins( $old_plugin, true, $network_wide ); | ||
|
|
||
| if ( is_plugin_active( $old_plugin ) ) { | ||
| // Only show the notice in the matching admin context. | ||
| if ( is_network_admin() !== $network_wide ) { | ||
| return; | ||
| } | ||
|
|
||
| add_action( | ||
| 'admin_notices', | ||
| static function (): void { | ||
| printf( | ||
| '<div class="notice notice-info is-dismissible"><p>%s</p></div>', | ||
| esc_html__( 'The old "Carousel Kit" plugin has been deactivated. rtCarousel is its replacement.', 'rt-carousel' ) | ||
| ); | ||
| } | ||
| if ( $network_wide ) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. additionally use is_network_admin() to check if users is no network admin site
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented in this commit. 1f0c258
|
||
| $deactivate_url = wp_nonce_url( | ||
| add_query_arg( | ||
| [ | ||
| 'action' => 'deactivate', | ||
| 'plugin' => $old_plugin, | ||
| 'networkwide' => '1', | ||
| ], | ||
| network_admin_url( 'plugins.php' ) | ||
| ), | ||
| 'deactivate-plugin_' . $old_plugin | ||
| ); | ||
| } else { | ||
| $deactivate_url = wp_nonce_url( | ||
| add_query_arg( | ||
| [ | ||
| 'action' => 'deactivate', | ||
| 'plugin' => $old_plugin, | ||
| ], | ||
| admin_url( 'plugins.php' ) | ||
| ), | ||
| 'deactivate-plugin_' . $old_plugin | ||
| ); | ||
| } | ||
|
|
||
| printf( | ||
| '<div class="notice notice-warning is-dismissible"><p>%s <a href="%s">%s</a></p></div>', | ||
| esc_html__( 'The "Carousel Kit" plugin is still active. rtCarousel is its replacement — please deactivate Carousel Kit.', 'rt-carousel' ), | ||
| esc_url( $deactivate_url ), | ||
| esc_html__( 'Deactivate Carousel Kit', 'rt-carousel' ) | ||
| ); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.