PluginProbe
Elementor Website Builder – more than just a page builder / 3.9.1
Elementor Website Builder – more than just a page builder v3.9.1
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / compatibility.php

compatibility.php in Elementor Website Builder – more than just a page builder 3.9.1, at includes/compatibility.php

375 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Base\Document;
5 use Elementor\Core\DocumentTypes\PageBase;
6 use Elementor\TemplateLibrary\Source_Local;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Elementor compatibility.
14 *
15 * Elementor compatibility handler class is responsible for compatibility with
16 * external plugins. The class resolves different issues with non-compatible
17 * plugins.
18 *
19 * @since 1.0.0
20 */
21 class Compatibility {
22
23 /**
24 * Register actions.
25 *
26 * Run Elementor compatibility with external plugins using custom filters and
27 * actions.
28 *
29 * @since 1.0.0
30 * @access public
31 * @static
32 */
33 public static function register_actions() {
34 add_action( 'init', [ __CLASS__, 'init' ] );
35
36 self::polylang_compatibility();
37 self::yoast_duplicate_post();
38
39 if ( is_admin() || defined( 'WP_LOAD_IMPORTERS' ) ) {
40 add_filter( 'wp_import_post_meta', [ __CLASS__, 'on_wp_import_post_meta' ] );
41 add_filter( 'wxr_importer.pre_process.post_meta', [ __CLASS__, 'on_wxr_importer_pre_process_post_meta' ] );
42 }
43
44 add_action( 'elementor/maintenance_mode/mode_changed', [ __CLASS__, 'clear_3rd_party_cache' ] );
45 }
46
47 public static function clear_3rd_party_cache() {
48 // W3 Total Cache.
49 if ( function_exists( 'w3tc_flush_all' ) ) {
50 w3tc_flush_all();
51 }
52
53 // WP Fastest Cache.
54 if ( ! empty( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ) {
55 $GLOBALS['wp_fastest_cache']->deleteCache();
56 }
57
58 // WP Super Cache
59 if ( function_exists( 'wp_cache_clean_cache' ) ) {
60 global $file_prefix;
61 wp_cache_clean_cache( $file_prefix, true );
62 }
63 }
64
65 /**
66 * Add new button to gutenberg.
67 *
68 * Insert new "Elementor" button to the gutenberg editor to create new post
69 * using Elementor page builder.
70 *
71 * @since 1.9.0
72 * @access public
73 * @static
74 */
75 public static function add_new_button_to_gutenberg() {
76 global $typenow;
77 if ( ! User::is_current_user_can_edit_post_type( $typenow ) ) {
78 return;
79 }
80
81 // Introduced in WP 5.0
82 if ( function_exists( 'use_block_editor_for_post' ) && ! use_block_editor_for_post( $typenow ) ) {
83 return;
84 }
85
86 // Deprecated/removed in Gutenberg plugin v5.3.0
87 if ( function_exists( 'gutenberg_can_edit_post_type' ) && ! gutenberg_can_edit_post_type( $typenow ) ) {
88 return;
89 }
90
91 ?>
92 <script type="text/javascript">
93 document.addEventListener( 'DOMContentLoaded', function() {
94 var dropdown = document.querySelector( '#split-page-title-action .dropdown' );
95
96 if ( ! dropdown ) {
97 return;
98 }
99
100 var url = '<?php echo esc_url( Plugin::$instance->documents->get_create_new_post_url( $typenow ) ); ?>';
101
102 dropdown.insertAdjacentHTML( 'afterbegin', '<a href="' + url + '">Elementor</a>' );
103 } );
104 </script>
105 <?php
106 }
107
108 /**
109 * Init.
110 *
111 * Initialize Elementor compatibility with external plugins.
112 *
113 * Fired by `init` action.
114 *
115 * @since 1.0.0
116 * @access public
117 * @static
118 */
119 public static function init() {
120 // Hotfix for NextGEN Gallery plugin.
121 if ( defined( 'NGG_PLUGIN_VERSION' ) ) {
122 add_filter( 'elementor/document/urls/edit', function( $edit_link ) {
123 return add_query_arg( 'display_gallery_iframe', '', $edit_link );
124 } );
125 }
126
127 // Exclude our Library from Yoast SEO plugin.
128 add_filter( 'wpseo_sitemaps_supported_post_types', [ __CLASS__, 'filter_library_post_type' ] );
129 add_filter( 'wpseo_accessible_post_types', [ __CLASS__, 'filter_library_post_type' ] );
130 add_filter( 'wpseo_sitemap_exclude_post_type', function( $retval, $post_type ) {
131 if ( Source_Local::CPT === $post_type ) {
132 $retval = true;
133 }
134
135 return $retval;
136 }, 10, 2 );
137
138 // Disable optimize files in Editor from Autoptimize plugin.
139 add_filter( 'autoptimize_filter_noptimize', function( $retval ) {
140 if ( Plugin::$instance->editor->is_edit_mode() ) {
141 $retval = true;
142 }
143
144 return $retval;
145 } );
146
147 // Add the description (content) tab for a new product, so it can be edited with Elementor.
148 add_filter( 'woocommerce_product_tabs', function( $tabs ) {
149 if ( ! isset( $tabs['description'] ) && Plugin::$instance->preview->is_preview_mode() ) {
150 $post = get_post();
151 if ( empty( $post->post_content ) ) {
152 $tabs['description'] = [
153 'title' => esc_html__( 'Description', 'elementor' ),
154 'priority' => 10,
155 'callback' => 'woocommerce_product_description_tab',
156 ];
157 }
158 }
159
160 return $tabs;
161 } );
162
163 // Fix WC session not defined in editor.
164 if ( class_exists( 'woocommerce' ) ) {
165 add_action( 'elementor/editor/before_enqueue_scripts', function() {
166 remove_action( 'woocommerce_shortcode_before_product_cat_loop', 'wc_print_notices' );
167 remove_action( 'woocommerce_before_shop_loop', 'wc_print_notices' );
168 remove_action( 'woocommerce_before_single_product', 'wc_print_notices' );
169 } );
170
171 add_filter( 'elementor/maintenance_mode/is_login_page', function( $value ) {
172
173 // Support Woocommerce Account Page.
174 if ( is_account_page() && ! is_user_logged_in() ) {
175 $value = true;
176 }
177 return $value;
178 } );
179 }
180
181 // Fix Jetpack Contact Form in Editor Mode.
182 if ( class_exists( 'Grunion_Editor_View' ) ) {
183 add_action( 'elementor/editor/before_enqueue_scripts', function() {
184 remove_action( 'media_buttons', 'grunion_media_button', 999 );
185 remove_action( 'admin_enqueue_scripts', 'grunion_enable_spam_recheck' );
186
187 remove_action( 'admin_notices', [ 'Grunion_Editor_View', 'handle_editor_view_js' ] );
188 remove_action( 'admin_head', [ 'Grunion_Editor_View', 'admin_head' ] );
189 } );
190 }
191
192 // Fix Popup Maker in Editor Mode.
193 if ( class_exists( 'PUM_Admin_Shortcode_UI' ) ) {
194 add_action( 'elementor/editor/before_enqueue_scripts', function() {
195 $pum_admin_instance = \PUM_Admin_Shortcode_UI::instance();
196
197 remove_action( 'print_media_templates', [ $pum_admin_instance, 'print_media_templates' ] );
198 remove_action( 'admin_print_footer_scripts', [ $pum_admin_instance, 'admin_print_footer_scripts' ], 100 );
199 remove_action( 'wp_ajax_pum_do_shortcode', [ $pum_admin_instance, 'wp_ajax_pum_do_shortcode' ] );
200
201 remove_action( 'admin_enqueue_scripts', [ $pum_admin_instance, 'admin_enqueue_scripts' ] );
202
203 remove_filter( 'pum_admin_var', [ $pum_admin_instance, 'pum_admin_var' ] );
204 } );
205 }
206
207 // Fix Preview URL for https://github.com/wpmudev/domain-mapping plugin
208 if ( class_exists( 'domain_map' ) ) {
209 add_filter( 'elementor/document/urls/preview', function( $preview_url ) {
210 if ( wp_parse_url( $preview_url, PHP_URL_HOST ) !== $_SERVER['HTTP_HOST'] ) {
211 $preview_url = \domain_map::utils()->unswap_url( $preview_url );
212 $preview_url = add_query_arg( [
213 'dm' => \Domainmap_Module_Mapping::BYPASS,
214 ], $preview_url );
215 }
216
217 return $preview_url;
218 } );
219 }
220
221 // Gutenberg
222 if ( function_exists( 'gutenberg_init' ) ) {
223 add_action( 'admin_print_scripts-edit.php', [ __CLASS__, 'add_new_button_to_gutenberg' ], 11 );
224 }
225 }
226
227 public static function filter_library_post_type( $post_types ) {
228 unset( $post_types[ Source_Local::CPT ] );
229
230 return $post_types;
231 }
232
233 /**
234 * Polylang compatibility.
235 *
236 * Fix Polylang compatibility with Elementor.
237 *
238 * @since 2.0.0
239 * @access private
240 * @static
241 */
242 private static function polylang_compatibility() {
243 // Copy elementor data while polylang creates a translation copy
244 add_filter( 'pll_copy_post_metas', [ __CLASS__, 'save_polylang_meta' ], 10, 4 );
245 }
246
247 /**
248 * Save polylang meta.
249 *
250 * Copy elementor data while polylang creates a translation copy.
251 *
252 * Fired by `pll_copy_post_metas` filter.
253 *
254 * @since 1.6.0
255 * @access public
256 * @static
257 *
258 * @param array $keys List of custom fields names.
259 * @param bool $sync True if it is synchronization, false if it is a copy.
260 * @param int $from ID of the post from which we copy information.
261 * @param int $to ID of the post to which we paste information.
262 *
263 * @return array List of custom fields names.
264 */
265 public static function save_polylang_meta( $keys, $sync, $from, $to ) {
266 // Copy only for a new post.
267 if ( ! $sync ) {
268 Plugin::$instance->db->copy_elementor_meta( $from, $to );
269 }
270
271 return $keys;
272 }
273
274 private static function yoast_duplicate_post() {
275 add_filter( 'duplicate_post_excludelist_filter', function( $meta_excludelist ) {
276 $exclude_list = [
277 Document::TYPE_META_KEY,
278 '_elementor_page_assets',
279 '_elementor_controls_usage',
280 '_elementor_css',
281 '_elementor_screenshot',
282 ];
283
284 return array_merge( $meta_excludelist, $exclude_list );
285 } );
286
287 add_action( 'duplicate_post_post_copy', function( $new_post_id, $post ) {
288 $original_template_type = get_post_meta( $post->ID, Document::TYPE_META_KEY, true );
289 if ( ! empty( $original_template_type ) ) {
290 update_post_meta( $new_post_id, Document::TYPE_META_KEY, $original_template_type );
291 }
292 }, 10, 2 );
293 }
294
295 /**
296 * Process post meta before WP importer.
297 *
298 * Normalize Elementor post meta on import, We need the `wp_slash` in order
299 * to avoid the unslashing during the `add_post_meta`.
300 *
301 * Fired by `wp_import_post_meta` filter.
302 *
303 * @since 1.0.0
304 * @access public
305 * @static
306 *
307 * @param array $post_meta Post meta.
308 *
309 * @return array Updated post meta.
310 */
311 public static function on_wp_import_post_meta( $post_meta ) {
312 $is_wp_importer_before_0_7 = self::is_wp_importer_before_0_7();
313
314 if ( $is_wp_importer_before_0_7 ) {
315 foreach ( $post_meta as &$meta ) {
316 if ( '_elementor_data' === $meta['key'] ) {
317 $meta['value'] = wp_slash( $meta['value'] );
318 break;
319 }
320 }
321 }
322
323 return $post_meta;
324 }
325
326 /**
327 * Is WP Importer Before 0.7
328 *
329 * Checks if WP Importer is installed, and whether its version is older than 0.7.
330 *
331 * @return bool
332 */
333 public static function is_wp_importer_before_0_7() {
334 $wp_importer = get_plugins( '/wordpress-importer' );
335
336 if ( ! empty( $wp_importer ) ) {
337 $wp_importer_version = $wp_importer['wordpress-importer.php']['Version'];
338
339 if ( version_compare( $wp_importer_version, '0.7', '<' ) ) {
340 return true;
341 }
342 }
343
344 return false;
345 }
346
347 /**
348 * Process post meta before WXR importer.
349 *
350 * Normalize Elementor post meta on import with the new WP_importer, We need
351 * the `wp_slash` in order to avoid the unslashing during the `add_post_meta`.
352 *
353 * Fired by `wxr_importer.pre_process.post_meta` filter.
354 *
355 * @since 1.0.0
356 * @access public
357 * @static
358 *
359 * @param array $post_meta Post meta.
360 *
361 * @return array Updated post meta.
362 */
363 public static function on_wxr_importer_pre_process_post_meta( $post_meta ) {
364 $is_wp_importer_before_0_7 = self::is_wp_importer_before_0_7();
365
366 if ( $is_wp_importer_before_0_7 ) {
367 if ( '_elementor_data' === $post_meta['key'] ) {
368 $post_meta['value'] = wp_slash( $post_meta['value'] );
369 }
370 }
371
372 return $post_meta;
373 }
374 }
375