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
webp-converter-for-media / src / Service / DeactivationModalLoader.php
webp-converter-for-media / src / Service Last commit date
BackupExcluder.php 2 weeks ago CacheIntegrator.php 2 weeks ago CloudflareConfigurator.php 2 weeks ago DeactivationModalLoader.php 2 weeks ago EnvDetector.php 2 weeks ago FileLoader.php 2 weeks ago MediaStatusViewer.php 2 weeks ago OptionsAccessManager.php 2 weeks ago PathsGenerator.php 2 weeks ago RestApiUnlocker.php 2 weeks ago ServerConfigurator.php 2 weeks ago SiteHealthDetector.php 2 weeks ago StatsManager.php 2 weeks ago TokenValidator.php 2 weeks ago ViewLoader.php 2 weeks ago WpCliManager.php 2 weeks ago
DeactivationModalLoader.php
226 lines
1 <?php
2
3 namespace WebpConverter\Service;
4
5 use WebpConverter\Error\Notice\LibsNotInstalledNotice;
6 use WebpConverter\Error\Notice\LibsWithoutWebpSupportNotice;
7 use WebpConverter\HookableInterface;
8 use WebpConverter\PluginData;
9 use WebpConverter\PluginInfo;
10 use WebpConverter\Settings\Page\AdvancedSettingsPage;
11 use WebpConverter\Settings\Page\PageIntegrator;
12 use WebpConverterVendor\MattPlugins\DeactivationModal;
13
14 /**
15 * Initiates the popup displayed when the plugin is deactivated.
16 */
17 class DeactivationModalLoader implements HookableInterface {
18
19 const API_URL = 'https://data.mattplugins.com/deactivations/%s';
20
21 private PluginInfo $plugin_info;
22
23 private PluginData $plugin_data;
24
25 private StatsManager $stats_manager;
26
27 public function __construct(
28 PluginInfo $plugin_info,
29 PluginData $plugin_data,
30 ?StatsManager $stats_manager = null
31 ) {
32 $this->plugin_info = $plugin_info;
33 $this->plugin_data = $plugin_data;
34 $this->stats_manager = $stats_manager ?: new StatsManager();
35 }
36
37 /**
38 * {@inheritdoc}
39 */
40 public function init_hooks(): void {
41 add_action( 'load-plugins.php', [ $this, 'load_modal' ] );
42 }
43
44 /**
45 * @throws DeactivationModal\Exception\DuplicatedFormOptionKeyException
46 * @throws DeactivationModal\Exception\DuplicatedFormValueKeyException
47 * @internal
48 */
49 public function load_modal(): void {
50 new DeactivationModal\Modal(
51 $this->plugin_info->get_plugin_slug(),
52 new DeactivationModal\Model\FormTemplate(
53 sprintf( self::API_URL, $this->plugin_info->get_plugin_slug() ),
54 sprintf(
55 /* translators: %s: plugin name */
56 __( 'We are sorry that you are leaving our %s plugin', 'webp-converter-for-media' ),
57 'Converter for Media'
58 ),
59 __( 'Can you, please, take a moment to tell us why you are deactivating this plugin (anonymous answer)?', 'webp-converter-for-media' ),
60 __( 'Submit and Deactivate', 'webp-converter-for-media' ),
61 __( 'Skip and Deactivate', 'webp-converter-for-media' ),
62 $this->load_notice_message()
63 ),
64 ( new DeactivationModal\Model\FormOptions() )
65 ->set_option(
66 new DeactivationModal\Model\FormOption(
67 'server_config',
68 10,
69 sprintf(
70 /* translators: %s: notice title */
71 __( 'I have the %s notice in the plugin settings', 'webp-converter-for-media' ),
72 __( 'Server configuration error', 'webp-converter-for-media' )
73 ),
74 function () {
75 $errors = apply_filters( 'webpc_server_errors', [] );
76 if ( ! in_array(
77 $errors,
78 [ [ LibsWithoutWebpSupportNotice::ERROR_KEY ], [ LibsNotInstalledNotice::ERROR_KEY ] ]
79 ) ) {
80 return null;
81 }
82
83 return sprintf(
84 /* translators: %1$s: open anchor tag, %2$s: close anchor tag */
85 __( 'If your server does not meet the technical requirements, you can use "Remote server" as "Conversion method", in %1$sthe plugin settings%2$s.', 'webp-converter-for-media' ),
86 '<a href="' . esc_url( PageIntegrator::get_settings_page_url() ) . '">',
87 '</a>'
88 );
89 },
90 __( 'What is your error? Have you been looking for a solution to this issue?', 'webp-converter-for-media' )
91 )
92 )
93 ->set_option(
94 new DeactivationModal\Model\FormOption(
95 'misunderstanding',
96 20,
97 __( 'Images are not displayed in the WebP format', 'webp-converter-for-media' ),
98 function () {
99 return sprintf(
100 /* translators: %1$s: open anchor tag, %2$s: close anchor tag */
101 __( 'Check out %1$sour instructions%2$s and see how to check if the plugin is working properly.', 'webp-converter-for-media' ),
102 '<a href="https://url.mattplugins.com/converter-deactivation-misunderstanding-instruction" target="_blank">',
103 '</a>'
104 );
105 },
106 __( 'Did you check the operation of the plugin in accordance with the instructions?', 'webp-converter-for-media' )
107 )
108 )
109 ->set_option(
110 new DeactivationModal\Model\FormOption(
111 'website_broken',
112 30,
113 __( 'This plugin broke my website', 'webp-converter-for-media' ),
114 function () {
115 return sprintf(
116 /* translators: %1$s: option label, %2$s: open anchor tag, %3$s: close anchor tag */
117 __( 'Check the %1$s option in %2$sthe plugin settings%3$s - this should solve the problem.', 'webp-converter-for-media' ),
118 __( 'Disable rewrite inheritance in .htaccess files', 'webp-converter-for-media' ),
119 '<a href="' . esc_url( PageIntegrator::get_settings_page_url( AdvancedSettingsPage::PAGE_SLUG ) ) . '">',
120 '</a>'
121 );
122 },
123 __( 'What exactly happened?', 'webp-converter-for-media' )
124 )
125 )
126 ->set_option(
127 new DeactivationModal\Model\FormOption(
128 'better_plugin',
129 40,
130 __( 'I found a better plugin', 'webp-converter-for-media' ),
131 null,
132 __( 'What is the name of this plugin? Why is it better?', 'webp-converter-for-media' )
133 )
134 )
135 ->set_option(
136 new DeactivationModal\Model\FormOption(
137 'temporary_deactivation',
138 50,
139 __( 'This is a temporary deactivation', 'webp-converter-for-media' ),
140 null,
141 null
142 )
143 )
144 ->set_option(
145 new DeactivationModal\Model\FormOption(
146 'other',
147 60,
148 __( 'Other reason', 'webp-converter-for-media' ),
149 null,
150 __( 'What is the reason? What can we improve for you?', 'webp-converter-for-media' )
151 )
152 ),
153 ( new DeactivationModal\Model\FormValues() )
154 ->set_value(
155 new DeactivationModal\Model\FormValue(
156 'request_error_codes',
157 function () {
158 return implode( ',', apply_filters( 'webpc_server_errors', [] ) );
159 }
160 )
161 )
162 ->set_value(
163 new DeactivationModal\Model\FormValue(
164 'request_plugin_settings',
165 function () {
166 $settings_json = json_encode( $this->plugin_data->get_plugin_settings_public() );
167 return base64_encode( $settings_json ?: '' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions
168 }
169 )
170 )
171 ->set_value(
172 new DeactivationModal\Model\FormValue(
173 'request_plugin_stats',
174 function () {
175 $stats_data = [
176 'usage_time' => $this->stats_manager->get_plugin_usage_time(),
177 'first_version' => $this->stats_manager->get_plugin_first_version(),
178 'regeneration_images' => $this->stats_manager->get_regeneration_images(),
179 'webp_all' => $this->stats_manager->get_images_webp_all(),
180 'webp_unconverted' => $this->stats_manager->get_images_webp_unconverted(),
181 'avif_all' => $this->stats_manager->get_images_avif_all(),
182 'avif_unconverted' => $this->stats_manager->get_images_avif_unconverted(),
183 'rewrite_root' => PathsGenerator::get_rewrite_root(),
184 'rewrite_path' => PathsGenerator::get_rewrite_path(),
185 ];
186
187 $stats_json = json_encode( $stats_data );
188 return base64_encode( $stats_json ?: '' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions
189 }
190 )
191 )
192 ->set_value(
193 new DeactivationModal\Model\FormValue(
194 'request_plugin_version',
195 function () {
196 return $this->plugin_info->get_plugin_version();
197 }
198 )
199 )
200 );
201 }
202
203 /**
204 * @return string|null
205 */
206 private function load_notice_message(): ?string {
207 if ( ( apply_filters( 'webpc_server_errors', [] ) !== [] ) || is_multisite() ) {
208 return null;
209 }
210
211 $images_all = $this->stats_manager->get_images_webp_all() ?: 0;
212 $images_left = $this->stats_manager->get_images_webp_unconverted() ?: 0;
213 if ( ( $images_all === 0 ) || ( $images_left === 0 ) ) {
214 return null;
215 }
216
217 return sprintf(
218 /* translators: %1$s: button label, %2$s: open anchor tag, %3$s: close anchor tag */
219 __( 'You have unconverted images on your website - click the %1$s button in %2$sthe plugin settings%3$s. This is all you need to do after installing the plugin.', 'webp-converter-for-media' ),
220 '"' . __( 'Start Bulk Optimization', 'webp-converter-for-media' ) . '"',
221 '<a href="' . esc_url( admin_url( 'upload.php?page=' . PageIntegrator::UPLOAD_MENU_PAGE ) ) . '">',
222 '</a>'
223 );
224 }
225 }
226