| @@ -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,32 @@ | ||
| 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 | + $replacement = "`elementor/element/wp-post/{$section_id}/{$current_sub_action}` or `elementor/element/wp-page/{$section_id}/{$current_sub_action}`"; | |
| 66 | + | |
| 67 | + Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->do_deprecated_action( $deprecated_action, func_get_args(), '2.7.0', $replacement ); | |
| 55 | 68 | } |
| 56 | 69 | |
| 57 | 70 | public static function clear_3rd_party_cache() { |
| 58 | 71 | // W3 Total Cache. |
| @@ -64,9 +77,9 @@ | ||
| 64 | 77 | if ( ! empty( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ) { |
| 65 | 78 | $GLOBALS['wp_fastest_cache']->deleteCache(); |
| 66 | 79 | } |
| 67 | 80 | |
| 68 | - // WP Super Cache. | |
| 81 | + // WP Super Cache | |
| 69 | 82 | if ( function_exists( 'wp_cache_clean_cache' ) ) { |
| 70 | 83 | global $file_prefix; |
| 71 | 84 | wp_cache_clean_cache( $file_prefix, true ); |
| 72 | 85 | } |
| @@ -87,20 +100,20 @@ | ||
| 87 | 100 | if ( ! User::is_current_user_can_edit_post_type( $typenow ) ) { |
| 88 | 101 | return; |
| 89 | 102 | } |
| 90 | 103 | |
| 91 | - // Introduced in WP 5.0. | |
| 104 | + // Introduced in WP 5.0 | |
| 92 | 105 | if ( function_exists( 'use_block_editor_for_post' ) && ! use_block_editor_for_post( $typenow ) ) { |
| 93 | 106 | return; |
| 94 | 107 | } |
| 95 | 108 | |
| 96 | - // Deprecated/removed in Gutenberg plugin v5.3.0. | |
| 109 | + // Deprecated/removed in Gutenberg plugin v5.3.0 | |
| 97 | 110 | if ( function_exists( 'gutenberg_can_edit_post_type' ) && ! gutenberg_can_edit_post_type( $typenow ) ) { |
| 98 | 111 | return; |
| 99 | 112 | } |
| 100 | 113 | |
| 101 | 114 | ?> |
| 102 | - <script> | |
| 115 | + <script type="text/javascript"> | |
| 103 | 116 | document.addEventListener( 'DOMContentLoaded', function() { |
| 104 | 117 | var dropdown = document.querySelector( '#split-page-title-action .dropdown' ); |
| 105 | 118 | |
| 106 | 119 | if ( ! dropdown ) { |
| @@ -106,9 +119,9 @@ | ||
| 106 | 119 | if ( ! dropdown ) { |
| 107 | 120 | return; |
| 108 | 121 | } |
| 109 | 122 | |
| 110 | - var url = '<?php echo esc_url( Plugin::$instance->documents->get_create_new_post_url( $typenow ) ); ?>'; | |
| 123 | + var url = '<?php echo esc_url( Utils::get_create_new_post_url( $typenow ) ); ?>'; | |
| 111 | 124 | |
| 112 | 125 | dropdown.insertAdjacentHTML( 'afterbegin', '<a href="' + url + '">Elementor</a>' ); |
| 113 | 126 | } ); |
| 114 | 127 | </script> |
| @@ -159,9 +172,9 @@ | ||
| 159 | 172 | if ( ! isset( $tabs['description'] ) && Plugin::$instance->preview->is_preview_mode() ) { |
| 160 | 173 | $post = get_post(); |
| 161 | 174 | if ( empty( $post->post_content ) ) { |
| 162 | 175 | $tabs['description'] = [ |
| 163 | - 'title' => esc_html__( 'Description', 'elementor' ), | |
| 176 | + 'title' => __( 'Description', 'elementor' ), | |
| 164 | 177 | 'priority' => 10, |
| 165 | 178 | 'callback' => 'woocommerce_product_description_tab', |
| 166 | 179 | ]; |
| 167 | 180 | } |
| @@ -213,12 +226,12 @@ | ||
| 213 | 226 | remove_filter( 'pum_admin_var', [ $pum_admin_instance, 'pum_admin_var' ] ); |
| 214 | 227 | } ); |
| 215 | 228 | } |
| 216 | 229 | |
| 217 | - // Fix Preview URL for https://github.com/wpmudev/domain-mapping plugin. | |
| 230 | + // Fix Preview URL for https://github.com/wpmudev/domain-mapping plugin | |
| 218 | 231 | if ( class_exists( 'domain_map' ) ) { |
| 219 | 232 | 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' ) ) { | |
| 233 | + if ( wp_parse_url( $preview_url, PHP_URL_HOST ) !== $_SERVER['HTTP_HOST'] ) { | |
| 221 | 234 | $preview_url = \domain_map::utils()->unswap_url( $preview_url ); |
| 222 | 235 | $preview_url = add_query_arg( [ |
| 223 | 236 | 'dm' => \Domainmap_Module_Mapping::BYPASS, |
| 224 | 237 | ], $preview_url ); |
| @@ -227,9 +240,9 @@ | ||
| 227 | 240 | return $preview_url; |
| 228 | 241 | } ); |
| 229 | 242 | } |
| 230 | 243 | |
| 231 | - // Gutenberg. | |
| 244 | + // Gutenberg | |
| 232 | 245 | if ( function_exists( 'gutenberg_init' ) ) { |
| 233 | 246 | add_action( 'admin_print_scripts-edit.php', [ __CLASS__, 'add_new_button_to_gutenberg' ], 11 ); |
| 234 | 247 | } |
| 235 | 248 | } |
| @@ -249,9 +262,29 @@ | ||
| 249 | 262 | * @access private |
| 250 | 263 | * @static |
| 251 | 264 | */ |
| 252 | 265 | private static function polylang_compatibility() { |
| 253 | - // Copy elementor data while polylang creates a translation copy. | |
| 266 | + // Fix language if the `get_user_locale` is difference from the `get_locale | |
| 267 | + if ( isset( $_REQUEST['action'] ) && 0 === strpos( $_REQUEST['action'], 'elementor' ) ) { | |
| 268 | + add_action( 'set_current_user', function() { | |
| 269 | + global $current_user; | |
| 270 | + $current_user->locale = get_locale(); | |
| 271 | + } ); | |
| 272 | + | |
| 273 | + // Fix for Polylang | |
| 274 | + define( 'PLL_AJAX_ON_FRONT', true ); | |
| 275 | + | |
| 276 | + add_action( 'pll_pre_init', function( $polylang ) { | |
| 277 | + if ( isset( $_REQUEST['post'] ) ) { | |
| 278 | + $post_language = $polylang->model->post->get_language( $_REQUEST['post'], 'locale' ); | |
| 279 | + if ( ! empty( $post_language ) ) { | |
| 280 | + $_REQUEST['lang'] = $post_language->locale; | |
| 281 | + } | |
| 282 | + } | |
| 283 | + } ); | |
| 284 | + } | |
| 285 | + | |
| 286 | + // Copy elementor data while polylang creates a translation copy | |
| 254 | 287 | add_filter( 'pll_copy_post_metas', [ __CLASS__, 'save_polylang_meta' ], 10, 4 ); |
| 255 | 288 | } |
| 256 | 289 | |
| 257 | 290 | /** |
| @@ -278,29 +311,8 @@ | ||
| 278 | 311 | Plugin::$instance->db->copy_elementor_meta( $from, $to ); |
| 279 | 312 | } |
| 280 | 313 | |
| 281 | 314 | 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 | 315 | } |
| 304 | 316 | |
| 305 | 317 | /** |
| 306 | 318 | * Process post meta before WP importer. |