| @@ -1,11 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | -use Elementor\Core\Base\Document; | |
| 5 | 4 | use Elementor\Core\DocumentTypes\PageBase; |
| 6 | 5 | use Elementor\TemplateLibrary\Source_Local; |
| 7 | -use Elementor\Utils; | |
| 8 | 6 | |
| 9 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | 8 | exit; // Exit if accessed directly. |
| 11 | 9 | } |
| @@ -34,9 +32,8 @@ | ||
| 34 | 32 | public static function register_actions() { |
| 35 | 33 | add_action( 'init', [ __CLASS__, 'init' ] ); |
| 36 | 34 | |
| 37 | 35 | self::polylang_compatibility(); |
| 38 | - self::yoast_duplicate_post(); | |
| 39 | 36 | |
| 40 | 37 | if ( is_admin() || defined( 'WP_LOAD_IMPORTERS' ) ) { |
| 41 | 38 | add_filter( 'wp_import_post_meta', [ __CLASS__, 'on_wp_import_post_meta' ] ); |
| 42 | 39 | add_filter( 'wxr_importer.pre_process.post_meta', [ __CLASS__, 'on_wxr_importer_pre_process_post_meta' ] ); |
| @@ -43,16 +40,34 @@ | ||
| 43 | 40 | } |
| 44 | 41 | |
| 45 | 42 | add_action( 'elementor/maintenance_mode/mode_changed', [ __CLASS__, 'clear_3rd_party_cache' ] ); |
| 46 | 43 | |
| 47 | - // Enable floating buttons and link in bio experiment for all. | |
| 48 | - // TODO Remove in version 3.26. | |
| 49 | - add_filter( 'pre_option_elementor_experiment-floating-buttons', [ __CLASS__, 'return_active' ] ); | |
| 50 | - add_filter( 'pre_option_elementor_experiment-link-in-bio', [ __CLASS__, 'return_active' ] ); | |
| 44 | + add_action( 'elementor/element/before_section_start', [ __CLASS__, 'document_post_deprecated_hooks' ], 10, 3 ); | |
| 45 | + add_action( 'elementor/element/after_section_start', [ __CLASS__, 'document_post_deprecated_hooks' ], 10, 3 ); | |
| 46 | + add_action( 'elementor/element/before_section_end', [ __CLASS__, 'document_post_deprecated_hooks' ], 10, 3 ); | |
| 47 | + add_action( 'elementor/element/after_section_end', [ __CLASS__, 'document_post_deprecated_hooks' ], 10, 3 ); | |
| 51 | 48 | } |
| 52 | 49 | |
| 53 | - public static function return_active() { | |
| 54 | - return 'active'; | |
| 50 | + public static function document_post_deprecated_hooks( $instance, $section_id, $args ) { | |
| 51 | + if ( ! $instance instanceof PageBase ) { | |
| 52 | + return; | |
| 53 | + } | |
| 54 | + | |
| 55 | + $current_action = current_action(); | |
| 56 | + $current_action = explode( '/', $current_action ); | |
| 57 | + $current_sub_action = $current_action[2]; | |
| 58 | + | |
| 59 | + $deprecated_action = "elementor/element/post/{$section_id}/{$current_sub_action}"; | |
| 60 | + | |
| 61 | + if ( ! has_action( $deprecated_action ) ) { | |
| 62 | + return; | |
| 63 | + } | |
| 64 | + | |
| 65 | + // TODO: Hard deprecation on 3.1.0. | |
| 66 | + // $replacement = "`elementor/element/wp-post/{$section_id}/{$current_sub_action}` or `elementor/element/wp-page/{$section_id}/{$current_sub_action}`"; | |
| 67 | + // _deprecated_hook( $deprecated_action, '2.7.0', $replacement ); | |
| 68 | + | |
| 69 | + do_action( $deprecated_action, $instance, $section_id, $args ); | |
| 55 | 70 | } |
| 56 | 71 | |
| 57 | 72 | public static function clear_3rd_party_cache() { |
| 58 | 73 | // W3 Total Cache. |
| @@ -64,9 +79,9 @@ | ||
| 64 | 79 | if ( ! empty( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ) { |
| 65 | 80 | $GLOBALS['wp_fastest_cache']->deleteCache(); |
| 66 | 81 | } |
| 67 | 82 | |
| 68 | - // WP Super Cache. | |
| 83 | + // WP Super Cache | |
| 69 | 84 | if ( function_exists( 'wp_cache_clean_cache' ) ) { |
| 70 | 85 | global $file_prefix; |
| 71 | 86 | wp_cache_clean_cache( $file_prefix, true ); |
| 72 | 87 | } |
| @@ -87,20 +102,20 @@ | ||
| 87 | 102 | if ( ! User::is_current_user_can_edit_post_type( $typenow ) ) { |
| 88 | 103 | return; |
| 89 | 104 | } |
| 90 | 105 | |
| 91 | - // Introduced in WP 5.0. | |
| 106 | + // Introduced in WP 5.0 | |
| 92 | 107 | if ( function_exists( 'use_block_editor_for_post' ) && ! use_block_editor_for_post( $typenow ) ) { |
| 93 | 108 | return; |
| 94 | 109 | } |
| 95 | 110 | |
| 96 | - // Deprecated/removed in Gutenberg plugin v5.3.0. | |
| 111 | + // Deprecated/removed in Gutenberg plugin v5.3.0 | |
| 97 | 112 | if ( function_exists( 'gutenberg_can_edit_post_type' ) && ! gutenberg_can_edit_post_type( $typenow ) ) { |
| 98 | 113 | return; |
| 99 | 114 | } |
| 100 | 115 | |
| 101 | 116 | ?> |
| 102 | - <script> | |
| 117 | + <script type="text/javascript"> | |
| 103 | 118 | document.addEventListener( 'DOMContentLoaded', function() { |
| 104 | 119 | var dropdown = document.querySelector( '#split-page-title-action .dropdown' ); |
| 105 | 120 | |
| 106 | 121 | if ( ! dropdown ) { |
| @@ -106,9 +121,9 @@ | ||
| 106 | 121 | if ( ! dropdown ) { |
| 107 | 122 | return; |
| 108 | 123 | } |
| 109 | 124 | |
| 110 | - var url = '<?php echo esc_url( Plugin::$instance->documents->get_create_new_post_url( $typenow ) ); ?>'; | |
| 125 | + var url = '<?php echo esc_url( Utils::get_create_new_post_url( $typenow ) ); ?>'; | |
| 111 | 126 | |
| 112 | 127 | dropdown.insertAdjacentHTML( 'afterbegin', '<a href="' + url + '">Elementor</a>' ); |
| 113 | 128 | } ); |
| 114 | 129 | </script> |
| @@ -159,9 +174,9 @@ | ||
| 159 | 174 | if ( ! isset( $tabs['description'] ) && Plugin::$instance->preview->is_preview_mode() ) { |
| 160 | 175 | $post = get_post(); |
| 161 | 176 | if ( empty( $post->post_content ) ) { |
| 162 | 177 | $tabs['description'] = [ |
| 163 | - 'title' => esc_html__( 'Description', 'elementor' ), | |
| 178 | + 'title' => __( 'Description', 'elementor' ), | |
| 164 | 179 | 'priority' => 10, |
| 165 | 180 | 'callback' => 'woocommerce_product_description_tab', |
| 166 | 181 | ]; |
| 167 | 182 | } |
| @@ -213,12 +228,12 @@ | ||
| 213 | 228 | remove_filter( 'pum_admin_var', [ $pum_admin_instance, 'pum_admin_var' ] ); |
| 214 | 229 | } ); |
| 215 | 230 | } |
| 216 | 231 | |
| 217 | - // Fix Preview URL for https://github.com/wpmudev/domain-mapping plugin. | |
| 232 | + // Fix Preview URL for https://github.com/wpmudev/domain-mapping plugin | |
| 218 | 233 | if ( class_exists( 'domain_map' ) ) { |
| 219 | 234 | add_filter( 'elementor/document/urls/preview', function( $preview_url ) { |
| 220 | - if ( wp_parse_url( $preview_url, PHP_URL_HOST ) !== Utils::get_super_global_value( $_SERVER, 'HTTP_HOST' ) ) { | |
| 235 | + if ( wp_parse_url( $preview_url, PHP_URL_HOST ) !== $_SERVER['HTTP_HOST'] ) { | |
| 221 | 236 | $preview_url = \domain_map::utils()->unswap_url( $preview_url ); |
| 222 | 237 | $preview_url = add_query_arg( [ |
| 223 | 238 | 'dm' => \Domainmap_Module_Mapping::BYPASS, |
| 224 | 239 | ], $preview_url ); |
| @@ -227,9 +242,9 @@ | ||
| 227 | 242 | return $preview_url; |
| 228 | 243 | } ); |
| 229 | 244 | } |
| 230 | 245 | |
| 231 | - // Gutenberg. | |
| 246 | + // Gutenberg | |
| 232 | 247 | if ( function_exists( 'gutenberg_init' ) ) { |
| 233 | 248 | add_action( 'admin_print_scripts-edit.php', [ __CLASS__, 'add_new_button_to_gutenberg' ], 11 ); |
| 234 | 249 | } |
| 235 | 250 | } |
| @@ -249,9 +264,29 @@ | ||
| 249 | 264 | * @access private |
| 250 | 265 | * @static |
| 251 | 266 | */ |
| 252 | 267 | private static function polylang_compatibility() { |
| 253 | - // Copy elementor data while polylang creates a translation copy. | |
| 268 | + // Fix language if the `get_user_locale` is difference from the `get_locale | |
| 269 | + if ( isset( $_REQUEST['action'] ) && 0 === strpos( $_REQUEST['action'], 'elementor' ) ) { | |
| 270 | + add_action( 'set_current_user', function() { | |
| 271 | + global $current_user; | |
| 272 | + $current_user->locale = get_locale(); | |
| 273 | + } ); | |
| 274 | + | |
| 275 | + // Fix for Polylang | |
| 276 | + define( 'PLL_AJAX_ON_FRONT', true ); | |
| 277 | + | |
| 278 | + add_action( 'pll_pre_init', function( $polylang ) { | |
| 279 | + if ( isset( $_REQUEST['post'] ) ) { | |
| 280 | + $post_language = $polylang->model->post->get_language( $_REQUEST['post'], 'locale' ); | |
| 281 | + if ( ! empty( $post_language ) ) { | |
| 282 | + $_REQUEST['lang'] = $post_language->locale; | |
| 283 | + } | |
| 284 | + } | |
| 285 | + } ); | |
| 286 | + } | |
| 287 | + | |
| 288 | + // Copy elementor data while polylang creates a translation copy | |
| 254 | 289 | add_filter( 'pll_copy_post_metas', [ __CLASS__, 'save_polylang_meta' ], 10, 4 ); |
| 255 | 290 | } |
| 256 | 291 | |
| 257 | 292 | /** |
| @@ -278,29 +313,8 @@ | ||
| 278 | 313 | Plugin::$instance->db->copy_elementor_meta( $from, $to ); |
| 279 | 314 | } |
| 280 | 315 | |
| 281 | 316 | return $keys; |
| 282 | - } | |
| 283 | - | |
| 284 | - private static function yoast_duplicate_post() { | |
| 285 | - add_filter( 'duplicate_post_excludelist_filter', function( $meta_excludelist ) { | |
| 286 | - $exclude_list = [ | |
| 287 | - Document::TYPE_META_KEY, | |
| 288 | - '_elementor_page_assets', | |
| 289 | - '_elementor_controls_usage', | |
| 290 | - '_elementor_css', | |
| 291 | - '_elementor_screenshot', | |
| 292 | - ]; | |
| 293 | - | |
| 294 | - return array_merge( $meta_excludelist, $exclude_list ); | |
| 295 | - } ); | |
| 296 | - | |
| 297 | - add_action( 'duplicate_post_post_copy', function( $new_post_id, $post ) { | |
| 298 | - $original_template_type = get_post_meta( $post->ID, Document::TYPE_META_KEY, true ); | |
| 299 | - if ( ! empty( $original_template_type ) ) { | |
| 300 | - update_post_meta( $new_post_id, Document::TYPE_META_KEY, $original_template_type ); | |
| 301 | - } | |
| 302 | - }, 10, 2 ); | |
| 303 | 317 | } |
| 304 | 318 | |
| 305 | 319 | /** |
| 306 | 320 | * Process post meta before WP importer. |