PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.8
Elementor Website Builder – more than just a page builder v3.7.8
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.7.8, at includes/compatibility.php

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