PluginProbe
Extendify / 3.0.5
Extendify v3.0.5
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Shared / Services / PluginRedirectDisabler.php

PluginRedirectDisabler.php in Extendify 3.0.5, at app/Shared/Services/PluginRedirectDisabler.php

164 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Prevents plugin activation redirects from interfering with Launch.
5 */
6
7 namespace Extendify\Shared\Services;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 /**
12 * Disables automatic setup wizard redirects from plugins we install.
13 *
14 * Uses four layers of defense:
15 * 1. Filters that plugins check before redirecting
16 * 2. Transient/option cleanup right after activation (priority 0)
17 * 3. Hook removal for plugins that call exit() during activated_plugin
18 * 4. wp_redirect interception as safety net
19 */
20 class PluginRedirectDisabler
21 {
22 /**
23 * Per-plugin cleanup actions keyed by plugin slug.
24 *
25 * @var array<string, array<string, mixed>>
26 */
27 private static $pluginCleanup = [
28 'wpforms-lite' => [
29 'transients' => ['wpforms_activation_redirect'],
30 ],
31 'wp-mail-smtp' => [
32 'transients' => ['wp_mail_smtp_activation_redirect'],
33 'setOptions' => ['wp_mail_smtp_activation_prevent_redirect' => true],
34 ],
35 'google-analytics-for-wordpress' => [
36 'transients' => ['_monsterinsights_activation_redirect'],
37 ],
38 'woocommerce' => [
39 'transients' => ['_wc_activation_redirect'],
40 ],
41 'all-in-one-seo-pack' => [
42 'setOptions' => ['aioseo_activation_redirect' => true],
43 ],
44 'really-simple-ssl' => [
45 'transients' => ['rsssl_redirect_to_settings_page'],
46 ],
47 'imagify' => [
48 'transients' => ['imagify_activation'],
49 ],
50 'complianz-gdpr' => [
51 'transients' => ['cmplz_redirect_to_settings_page'],
52 'setOptions' => ['cmplz_onboarding_dismissed' => true],
53 ],
54 'charitable' => [
55 'transients' => ['charitable_activation_redirect'],
56 ],
57 'give' => [
58 'transients' => ['_give_activation_redirect'],
59 ],
60 'seo-by-rank-math' => [
61 'transients' => ['_rank_math_activation_redirect'],
62 ],
63 'sugar-calendar-lite' => [
64 'transients' => ['sugar_calendar_activation_redirect'],
65 'setOptions' => ['sugar_calendar_prevent_redirect' => true],
66 ],
67 'the-events-calendar' => [
68 'transients' => ['_tribe_events_activation_redirect'],
69 'setOptions' => ['tribe_skip_welcome' => true],
70 ],
71 'complianz-terms-conditions' => [
72 'transients' => ['cmplz_tc_redirect_to_settings'],
73 ],
74 'translatepress-multilingual' => [
75 'setOptions' => ['trp_onboarding_started' => 'yes'],
76 ],
77 ];
78
79 /**
80 * URL patterns to intercept via wp_redirect filter.
81 *
82 * @var string[]
83 */
84 private static $redirectUrlPatterns = [
85 'page=wpseo_installation_successful',
86 'page=wc-gzd-setup',
87 ];
88
89 /**
90 * Sets up all redirect prevention hooks.
91 *
92 * @return void
93 */
94 public function __construct()
95 {
96 \add_filter('woocommerce_enable_setup_wizard', '__return_false');
97 \add_filter('woocommerce_prevent_automatic_wizard_redirect', '__return_true');
98 \add_filter('monsterinsights_enable_onboarding_wizard', '__return_false');
99 \add_filter('charitable_disable_activation_redirect', '__return_true');
100 \add_filter('tec_admin_update_page_bypass', '__return_true');
101
102 \add_action('activated_plugin', [$this, 'cleanupRedirectTriggers'], 0);
103
104 \add_action('activate_ecwid-shopping-cart/ecwid-shopping-cart.php', function () {
105 \remove_action('activated_plugin', 'ecwid_plugin_activation_redirect');
106 });
107
108 \add_action('activate_chatbot/qcld-wpwbot.php', function () {
109 \remove_action('activated_plugin', 'qc_wpbotfree_activation_redirect');
110 });
111
112 \add_filter('wp_redirect', [$this, 'interceptRedirects'], 9998);
113 }
114
115 /**
116 * Cleans up redirect triggers for the specific plugin being activated.
117 *
118 * @param string $plugin The plugin basename (e.g. 'wpforms-lite/wpforms.php').
119 * @return void
120 */
121 public function cleanupRedirectTriggers($plugin)
122 {
123 $slug = \dirname($plugin);
124 if (!in_array($slug, SupportedPlugins::SLUGS, true)) {
125 return;
126 }
127
128 if (!isset(self::$pluginCleanup[$slug])) {
129 return;
130 }
131
132 $cleanup = self::$pluginCleanup[$slug];
133
134 foreach ($cleanup['transients'] ?? [] as $transient) {
135 \delete_transient($transient);
136 }
137
138 foreach ($cleanup['deleteOptions'] ?? [] as $option) {
139 \delete_option($option);
140 }
141
142 foreach ($cleanup['setOptions'] ?? [] as $option => $value) {
143 \update_option($option, $value);
144 }
145 }
146
147 /**
148 * Intercepts known plugin redirect URLs.
149 *
150 * @param string $url The redirect URL.
151 * @return string The original URL or admin dashboard URL to block the redirect.
152 */
153 public function interceptRedirects($url)
154 {
155 foreach (self::$redirectUrlPatterns as $pattern) {
156 if (str_contains($url, $pattern)) {
157 return \admin_url();
158 }
159 }
160
161 return $url;
162 }
163 }
164