PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / trunk
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments vtrunk
4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / WordPress / CompatibilityService.php
surecart / app / src / WordPress Last commit date
Admin 1 month ago Assets 1 week ago CLI 2 years ago Cache 1 month ago Pages 1 year ago PostTypes 4 months ago Posts 1 year ago Shortcodes 1 month ago Taxonomies 1 year ago Templates 1 year ago Users 3 days ago ActionsService.php 4 years ago CompatibilityService.php 1 week ago CurrencyService.php 6 months ago GoogleMapApiService.php 4 months ago HealthService.php 4 months ago LineItemStateService.php 2 years ago PluginActionLinksService.php 1 year ago PluginService.php 1 week ago PluginServiceProvider.php 1 year ago RecaptchaValidationService.php 2 years ago StateService.php 8 months ago ThemeService.php 5 months ago ThemeServiceProvider.php 8 months ago TranslationsServiceProvider.php 4 months ago UpgradeNoticeService.php 1 year ago
CompatibilityService.php
315 lines
1 <?php
2 /**
3 * Compatibility service.
4 *
5 * @package SureCartAppCore
6 * @author SureCart <support@surecart.com>
7 * @copyright SureCart
8 * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
9 * @link https://surecart.com
10 */
11
12 namespace SureCart\WordPress;
13
14 /**
15 * Provides compatibility with other plugins.
16 */
17 class CompatibilityService {
18 /**
19 * Bootstrap the service.
20 *
21 * @return void
22 */
23 public function bootstrap() {
24 // UAG fix.
25 add_action( 'render_block_data', [ $this, 'maybeEnqueueUAGBAssets' ] );
26 // SC Form Shortcode fix.
27 add_filter( 'surecart/shortcode/render', [ $this, 'maybeEnqueueUAGBAssetsForShortcode' ], 5, 3 );
28
29 // rankmath fix.
30 add_action( 'rank_math/head', [ $this, 'rankMathFix' ] );
31 add_filter( 'rank_math/frontend/canonical', [ $this, 'rankMathUrlFix' ] );
32 add_filter( 'rank_math/sitemap/xml_post_url', [ $this, 'rankMathUrlFix' ] );
33 add_filter( 'rank_math/sitemap/post_type_archive_link', [ $this, 'rankMathUrlFix' ] );
34
35 // Yoast SEO fix.
36 add_action( 'wpseo_frontend_presenters', [ $this, 'yoastSEOFix' ] );
37
38 // Siteground JS combine exclude.
39 add_filter( 'sgo_javascript_combine_exclude_ids', [ $this, 'sitegroundJsCombineExcludeScriptIds' ] );
40
41 // Show gutenberg active notice.
42 add_action( 'admin_init', [ $this, 'gutenbergActiveNotice' ] );
43
44 // Warn when the WordPress version is below what the plugin requires.
45 add_action( 'current_screen', [ $this, 'minimumWpVersionNotice' ] );
46
47 // Load Divi Compatibility CSS.
48 add_action( 'wp_enqueue_scripts', [ $this, 'diviCompatibility' ] );
49
50 // Load Bricks Compatibility CSS.
51 add_action( 'wp_enqueue_scripts', [ $this, 'bricksCompatibility' ] );
52
53 // Load Blocks Global Styles if enabled by Merchant in the setting.
54 if ( (bool) get_option( 'surecart_load_block_assets_on_demand', false ) && \SureCart::theme()->shouldLoadOnDemandBlockAssets() ) {
55 add_filter( 'should_load_separate_core_block_assets', '__return_true' );
56 }
57
58 add_action( 'render_block', [ $this, 'fixKadenceAccordionPaneButtonType' ], 10, 2 );
59 }
60
61 /**
62 * Adds type="button" to the button in the Kadence Accordion Pane.
63 * This prevents the button from submitting the form.
64 *
65 * @param string $content Block content.
66 * @param array $block Block data.
67 *
68 * @return string
69 */
70 public function fixKadenceAccordionPaneButtonType( $content, $block ) {
71 if ( 'kadence/pane' === $block['blockName'] ) {
72 $processor = new \WP_HTML_Tag_Processor( $content );
73 $has_tag = $processor->next_tag( 'button' );
74 if ( $has_tag ) {
75 $processor->set_attribute( 'type', 'button' );
76 }
77 return $processor->get_updated_html();
78 }
79 return $content;
80 }
81
82 /**
83 * Load Divi Compatibility CSS.
84 *
85 * @return void
86 */
87 public function diviCompatibility() {
88 if ( ! is_plugin_active( 'divi-builder/divi-builder.php' ) ) {
89 return;
90 }
91 wp_enqueue_style( 'surecart-divi-compatibility', plugins_url( 'styles/divi-compatibility.css', SURECART_PLUGIN_FILE ), '', \SureCart::plugin()->version(), 'all' );
92 }
93
94 /**
95 * Load Bricks Compatibility CSS.
96 *
97 * @return void
98 */
99 public function bricksCompatibility() {
100 $active_theme = wp_get_theme();
101
102 if ( empty( $active_theme ) || 'Bricks' !== $active_theme->get( 'Name' ) ) {
103 return;
104 }
105
106 wp_enqueue_style( 'surecart-bricks-compatibility', plugins_url( 'styles/bricks-compatibility.css', SURECART_PLUGIN_FILE ), '', \SureCart::plugin()->version(), 'all' );
107 }
108
109 /** Prevent Yoast SEO from outputing SEO meta tags on our custom pages.
110 *
111 * @param array $presenters Presenters.
112 * @return array Empty Array.
113 */
114 public function yoastSEOFix( $presenters ) {
115 if ( is_singular( 'sc_product' ) || is_singular( 'sc_collection' ) || is_singular( 'sc_upsell' ) ) {
116 $title_presenters = array_filter(
117 $presenters,
118 function ( $item ) {
119 return strpos( get_class( $item ), 'SEO\Presenters\Title_Presenter' );
120 }
121 );
122 return apply_filters( 'sc_wpseo_frontend_presenters', $title_presenters, $presenters );
123 }
124
125 return $presenters;
126 }
127
128 /**
129 * Prevent rankmath from outputting og:tags on our custom pages.
130 *
131 * @return void
132 */
133 public function rankMathFix() {
134 if ( is_singular( 'sc_product' ) || is_singular( 'sc_collection' ) || is_singular( 'sc_upsell' ) ) {
135 remove_all_actions( 'rank_math/opengraph/facebook' );
136 remove_all_actions( 'rank_math/opengraph/twitter' );
137 }
138 }
139
140 /**
141 * Fix the canonical URL for rankmath.
142 *
143 * @param string $canonical The canonical URL.
144 *
145 * @return string
146 */
147 public function rankMathUrlFix( $canonical ) {
148 // Some Rank Math filters may pass boolean false to indicate the archive/link
149 // should not be included. If $canonical is empty or not a string, don't process.
150 if ( empty( $canonical ) || ! is_string( $canonical ) ) {
151 return $canonical;
152 }
153
154 return remove_query_arg( 'currency', $canonical );
155 }
156
157 /**
158 * Render block data.
159 *
160 * @param array $parsed_block Block data.
161 *
162 * @return array
163 */
164 public function maybeEnqueueUAGBAssets( $parsed_block ) {
165 // UAGB must be activated.
166 if ( ! class_exists( '\UAGB_Post_Assets' ) ) {
167 return $parsed_block;
168 }
169
170 // must be our checkout form block.
171 if ( 'surecart/checkout-form' !== $parsed_block['blockName'] && 'surecart/upsell' !== $parsed_block['blockName'] ) {
172 return $parsed_block;
173 }
174
175 $post = get_post();
176 $upsell_id = isset( $post->upsell->id ) ? $post->upsell->id : null;
177
178 $id = $parsed_block['attrs']['id'] ?? $upsell_id;
179
180 if ( empty( $id ) ) {
181 return $parsed_block;
182 }
183
184 // If Spectra Blocks are present in the form, enqueue the assets.
185 $post_assets_instance = new \UAGB_Post_Assets( $id );
186 $post_assets_instance->enqueue_scripts(); // This will enqueue the JS and CSS files.
187
188 if ( ! empty( $post_assets_instance->file_generation ) && 'disabled' === $post_assets_instance->file_generation ) {
189 add_action( 'wp_footer', array( $post_assets_instance, 'print_stylesheet' ) ); // As on checkout page, the wp_head action is loaded late & Spectra prints inline CSS on that action for file_generation disabled case, we need to print the CSS on footer.
190 }
191
192 return $parsed_block;
193 }
194
195 /**
196 * Filter SC Form Shortcode to load the Spectra Blocks Assets.
197 *
198 * @param string $output Content.
199 * @param array $attributes Shortcode attributes.
200 * @param string $name Shortcode Tag.
201 *
202 * @return array
203 */
204 public function maybeEnqueueUAGBAssetsForShortcode( $output, $attributes, $name ) {
205 // UAGB must be activated.
206 if ( ! class_exists( '\UAGB_Post_Assets' ) ) {
207 return $output;
208 }
209
210 // must be our form shortcode.
211 if ( 'sc_form' !== $name ) {
212 return $output;
213 }
214
215 // must have an ID.
216 if ( empty( $attributes['id'] ) ) {
217 return $output;
218 }
219
220 // If Spectra Blocks are present in the form, enqueue the assets.
221 $post_assets_instance = new \UAGB_Post_Assets( $attributes['id'] );
222 $post_assets_instance->enqueue_scripts();
223
224 return $output;
225 }
226
227 /**
228 * Show the Gutenberg active notice.
229 *
230 * @return void
231 */
232 public function gutenbergActiveNotice(): void {
233 if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
234 \SureCart::notices()->add(
235 [
236 'name' => 'gutenberg_active_notice',
237 'type' => 'warning',
238 'title' => esc_html__( 'SureCart', 'surecart' ),
239 'text' => wp_kses_post( __( '<p>The Gutenberg plugin is currently active. SureCart blocks might not perform as expected within the block editor. If you encounter any issues, consider disabling the Gutenberg plugin.<p>', 'surecart' ) ),
240 ]
241 );
242 }
243 }
244
245 /**
246 * Warn admins when the site's WordPress version is below the plugin's minimum.
247 *
248 * @return void
249 */
250 public function minimumWpVersionNotice(): void {
251 // Only surface to users who can actually update core.
252 if ( ! current_user_can( 'update_core' ) ) {
253 return;
254 }
255
256 // Limit to the plugins screen and SureCart's own admin pages to avoid
257 // polluting unrelated admin screens. Reuses the canonical screen-id list.
258 $screen = get_current_screen();
259 if ( empty( $screen ) ) {
260 return;
261 }
262
263 $allowed_screens = array_merge( [ 'plugins' ], \SureCart::plugin()->pages()->getSureCartPageScreenIds() );
264 if ( ! in_array( $screen->id, $allowed_screens, true ) ) {
265 return;
266 }
267
268 $required = \SureCart::plugin()->requiredWPVersion();
269
270 // Nothing declared, or the site already meets the minimum.
271 if ( empty( $required ) || ! version_compare( get_bloginfo( 'version' ), $required, '<' ) ) {
272 return;
273 }
274
275 \SureCart::notices()->add(
276 [
277 'type' => 'error',
278 'title' => esc_html__( 'SureCart', 'surecart' ),
279 'text' => wp_kses_post(
280 sprintf(
281 /* translators: %s: minimum required WordPress version. */
282 __( '<p>SureCart requires WordPress %s or higher. Please update WordPress to keep your store working correctly.</p>', 'surecart' ),
283 esc_html( $required )
284 )
285 ),
286 ]
287 );
288 }
289
290 /**
291 * Exclude SureCart JS modules from Siteground JS combine.
292 * This is to prevent the JS modules from being combined and minified by Siteground.
293 *
294 * @param array $exclude_ids Array of JS module IDs to exclude.
295 *
296 * @return array
297 */
298 public function sitegroundJsCombineExcludeScriptIds( $exclude_ids ) {
299 // WordPress scripts which depends on interactivity.
300 $exclude_ids[] = '@wordpress/block-library/navigation/view-js-module';
301
302 // SureCart scripts.
303 $exclude_ids[] = '@surecart/product-page-js-module';
304 $exclude_ids[] = '@surecart/image-slider-js-module';
305 $exclude_ids[] = '@surecart/checkout-js-module';
306 $exclude_ids[] = '@surecart/cart-js-module';
307 $exclude_ids[] = '@surecart/checkout-service-js-module';
308 $exclude_ids[] = '@surecart/checkout-events-js-module';
309 $exclude_ids[] = '@surecart/dropdown-js-module';
310 $exclude_ids[] = '@surecart/product-list-js-module';
311
312 return $exclude_ids;
313 }
314 }
315