| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | * |
| 7 | 7 | * @since 1.0 |
| 8 | 8 | */ |
| 9 | 9 | class PLL_Plugins_Compat { |
| 10 | - protected static $instance; // for singleton | |
| 10 | + static protected $instance; // for singleton | |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Constructor |
| 14 | 14 | * |
| @@ -34,10 +34,10 @@ | ||
| 34 | 34 | // Duplicate post |
| 35 | 35 | add_filter( 'option_duplicate_post_taxonomies_blacklist', array( $this, 'duplicate_post_taxonomies_blacklist' ) ); |
| 36 | 36 | |
| 37 | 37 | // Jetpack |
| 38 | - $this->jetpack = new PLL_Jetpack(); // Must be loaded before the plugin is active | |
| 39 | - add_action( 'pll_init', array( $this->featured_content = new PLL_Featured_Content(), 'init' ) ); | |
| 38 | + $this->jetpack = new PLL_Jetpack(); // Must be loaded before the plugin is active | |
| 39 | + $this->featured_content = new PLL_Featured_Content(); | |
| 40 | 40 | |
| 41 | 41 | // WP Sweep |
| 42 | 42 | add_filter( 'wp_sweep_excluded_taxonomies', array( $this, 'wp_sweep_excluded_taxonomies' ) ); |
| 43 | 43 | |
| @@ -82,9 +82,9 @@ | ||
| 82 | 82 | */ |
| 83 | 83 | public function plugins_loaded() { |
| 84 | 84 | // Yoast SEO |
| 85 | 85 | if ( defined( 'WPSEO_VERSION' ) ) { |
| 86 | - add_action( 'pll_init', array( $this->wpseo = new PLL_WPSEO(), 'init' ) ); | |
| 86 | + add_action( 'pll_language_defined', array( $this->wpseo = new PLL_WPSEO(), 'init' ) ); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | if ( pll_is_cache_active() ) { |
| 90 | 90 | add_action( 'pll_init', array( $this->cache_compat = new PLL_Cache_Compat(), 'init' ) ); |
| @@ -109,17 +109,12 @@ | ||
| 109 | 109 | if ( ( 'Divi' === get_template() || defined( 'ET_BUILDER_PLUGIN_VERSION' ) ) && class_exists( 'PLL_Divi_Builder' ) ) { |
| 110 | 110 | $this->divi_builder = new PLL_Divi_Builder(); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - // WP Offload Media Lite | |
| 114 | - if ( function_exists( 'as3cf_init' ) && class_exists( 'PLL_AS3CF' ) ) { | |
| 115 | - add_action( 'pll_init', array( $this->as3cf = new PLL_AS3CF(), 'init' ) ); | |
| 113 | + // Admin Columns & Admin Columns Pro | |
| 114 | + if ( ( defined( 'AC_FILE' ) || defined( 'ACP_FILE' ) ) && class_exists( 'PLL_CPAC' ) ) { | |
| 115 | + add_action( 'admin_init', array( $this->cpac = new PLL_CPAC(), 'init' ) ); | |
| 116 | 116 | } |
| 117 | - | |
| 118 | - // Content Blocks (Custom Post Widget) | |
| 119 | - if ( function_exists( 'custom_post_widget_plugin_init' ) && class_exists( 'PLL_Content_Blocks' ) ) { | |
| 120 | - add_action( 'pll_init', array( $this->content_blocks = new PLL_Content_Blocks(), 'init' ) ); | |
| 121 | - } | |
| 122 | 117 | } |
| 123 | 118 | |
| 124 | 119 | /** |
| 125 | 120 | * Look for active plugins and load compatibility layer after the theme has been setup |
| @@ -127,16 +122,12 @@ | ||
| 127 | 122 | * @since 2.3.8 |
| 128 | 123 | */ |
| 129 | 124 | public function after_setup_theme() { |
| 130 | 125 | // Advanced Custom Fields Pro |
| 131 | - if ( defined( 'ACF_VERSION' ) && version_compare( ACF_VERSION, '5.7.11', '>=' ) && class_exists( 'PLL_ACF' ) ) { | |
| 126 | + // The function acf_get_value() is not defined in ACF 4 | |
| 127 | + if ( class_exists( 'acf' ) && function_exists( 'acf_get_value' ) && class_exists( 'PLL_ACF' ) ) { | |
| 132 | 128 | add_action( 'init', array( $this->acf = new PLL_ACF(), 'init' ) ); |
| 133 | 129 | } |
| 134 | - | |
| 135 | - // Admin Columns & Admin Columns Pro | |
| 136 | - if ( did_action( 'pll_init' ) && ( defined( 'AC_FILE' ) || defined( 'ACP_FILE' ) ) && class_exists( 'PLL_CPAC' ) ) { | |
| 137 | - add_action( 'admin_init', array( $this->cpac = new PLL_CPAC(), 'init' ) ); | |
| 138 | - } | |
| 139 | 130 | } |
| 140 | 131 | |
| 141 | 132 | /** |
| 142 | 133 | * WordPress Importer |
| @@ -161,9 +152,9 @@ | ||
| 161 | 152 | $class = new ReflectionClass( 'WP_Import' ); |
| 162 | 153 | load_plugin_textdomain( 'wordpress-importer', false, basename( dirname( $class->getFileName() ) ) . '/languages' ); |
| 163 | 154 | |
| 164 | 155 | $GLOBALS['wp_import'] = new PLL_WP_Import(); |
| 165 | - register_importer( 'wordpress', 'WordPress', __( 'Import <strong>posts, pages, comments, custom fields, categories, and tags</strong> from a WordPress export file.', 'polylang' ), array( $GLOBALS['wp_import'], 'dispatch' ) ); // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 156 | + register_importer( 'wordpress', 'WordPress', __( 'Import <strong>posts, pages, comments, custom fields, categories, and tags</strong> from a WordPress export file.', 'wordpress-importer' ), array( $GLOBALS['wp_import'], 'dispatch' ) ); // WPCS: spelling ok. | |
| 166 | 157 | } |
| 167 | 158 | |
| 168 | 159 | /** |
| 169 | 160 | * WordPress Importer |
| @@ -175,9 +166,9 @@ | ||
| 175 | 166 | * @param array $terms an array of arrays containing terms information form the WXR file |
| 176 | 167 | * @return array |
| 177 | 168 | */ |
| 178 | 169 | public function wp_import_terms( $terms ) { |
| 179 | - $languages = include PLL_SETTINGS_INC . '/languages.php'; | |
| 170 | + include PLL_SETTINGS_INC . '/languages.php'; | |
| 180 | 171 | |
| 181 | 172 | foreach ( $terms as $key => $term ) { |
| 182 | 173 | if ( 'language' === $term['term_taxonomy'] ) { |
| 183 | 174 | $description = maybe_unserialize( $term['term_description'] ); |
| @@ -182,9 +173,9 @@ | ||
| 182 | 173 | if ( 'language' === $term['term_taxonomy'] ) { |
| 183 | 174 | $description = maybe_unserialize( $term['term_description'] ); |
| 184 | 175 | if ( empty( $description['flag_code'] ) && isset( $languages[ $description['locale'] ] ) ) { |
| 185 | 176 | $description['flag_code'] = $languages[ $description['locale'] ]['flag']; |
| 186 | - $terms[ $key ]['term_description'] = maybe_serialize( $description ); | |
| 177 | + $terms[ $key ]['term_description'] = serialize( $description ); | |
| 187 | 178 | } |
| 188 | 179 | } |
| 189 | 180 | } |
| 190 | 181 | return $terms; |
| @@ -222,9 +213,9 @@ | ||
| 222 | 213 | * @param object $post current post object |
| 223 | 214 | */ |
| 224 | 215 | public function cft_copy( $post_type, $post ) { |
| 225 | 216 | global $custom_field_template; |
| 226 | - if ( isset( $custom_field_template, $_REQUEST['from_post'], $_REQUEST['new_lang'] ) && ! empty( $post ) ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 217 | + if ( isset( $custom_field_template, $_REQUEST['from_post'], $_REQUEST['new_lang'] ) && ! empty( $post ) ) { | |
| 227 | 218 | $_REQUEST['post'] = $post->ID; |
| 228 | 219 | } |
| 229 | 220 | } |
| 230 | 221 | |
| @@ -265,21 +256,13 @@ | ||
| 265 | 256 | * |
| 266 | 257 | * @since 2.0.10 |
| 267 | 258 | */ |
| 268 | 259 | public function twenty_seventeen_init() { |
| 269 | - if ( 'twentyseventeen' === get_template() && did_action( 'pll_init' ) ) { | |
| 270 | - if ( function_exists( 'twentyseventeen_panel_count' ) && PLL() instanceof PLL_Frontend ) { | |
| 271 | - $num_sections = twentyseventeen_panel_count(); | |
| 272 | - for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) { | |
| 273 | - add_filter( 'theme_mod_panel_' . $i, 'pll_get_post' ); | |
| 274 | - } | |
| 260 | + if ( 'twentyseventeen' === get_template() && function_exists( 'twentyseventeen_panel_count' ) && did_action( 'pll_init' ) && PLL() instanceof PLL_Frontend ) { | |
| 261 | + $num_sections = twentyseventeen_panel_count(); | |
| 262 | + for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) { | |
| 263 | + add_filter( 'theme_mod_panel_' . $i, 'pll_get_post' ); | |
| 275 | 264 | } |
| 276 | - | |
| 277 | - if ( PLL() instanceof PLL_Frontend ) { | |
| 278 | - add_filter( 'theme_mod_external_header_video', 'pll__' ); | |
| 279 | - } else { | |
| 280 | - pll_register_string( __( 'Header video', 'polylang' ), get_theme_mod( 'external_header_video' ), 'Twenty Seventeen', false ); | |
| 281 | - } | |
| 282 | 265 | } |
| 283 | 266 | } |
| 284 | 267 | |
| 285 | 268 | /** |
| @@ -314,28 +297,25 @@ | ||
| 314 | 297 | return; |
| 315 | 298 | } |
| 316 | 299 | |
| 317 | 300 | // Don't redirect post previews |
| 318 | - if ( isset( $_GET['preview'] ) && 'true' === $_GET['preview'] ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 301 | + if ( isset( $_GET['preview'] ) && 'true' === $_GET['preview'] ) { | |
| 319 | 302 | return; |
| 320 | 303 | } |
| 321 | 304 | |
| 322 | 305 | // Don't redirect theme customizer |
| 323 | - if ( isset( $_POST['customize'] ) && isset( $_POST['theme'] ) && 'on' === $_POST['customize'] ) { // phpcs:ignore WordPress.Security.NonceVerification | |
| 306 | + if ( isset( $_POST['customize'] ) && isset( $_POST['theme'] ) && 'on' === $_POST['customize'] ) { | |
| 324 | 307 | return; |
| 325 | 308 | } |
| 326 | 309 | |
| 327 | 310 | // If we can't associate the requested domain to a language, redirect to the default domain |
| 328 | - $requested_url = pll_get_requested_url(); | |
| 329 | - $requested_host = wp_parse_url( $requested_url, PHP_URL_HOST ); | |
| 330 | - | |
| 331 | 311 | $hosts = PLL()->links_model->get_hosts(); |
| 332 | - $lang = array_search( $requested_host, $hosts ); | |
| 312 | + $lang = array_search( $_SERVER['HTTP_HOST'], $hosts ); | |
| 333 | 313 | |
| 334 | 314 | if ( empty( $lang ) ) { |
| 335 | - $status = get_site_option( 'dm_301_redirect' ) ? '301' : '302'; // Honor status redirect option | |
| 336 | - $redirect = str_replace( '://' . $requested_host, '://' . $hosts[ $options['default_lang'] ], $requested_url ); | |
| 337 | - wp_safe_redirect( $redirect, $status ); | |
| 315 | + $status = get_site_option( 'dm_301_redirect' ) ? '301' : '302'; // Honor status redirect option | |
| 316 | + $redirect = ( is_ssl() ? 'https://' : 'http://' ) . $hosts[ $options['default_lang'] ] . $_SERVER['REQUEST_URI']; | |
| 317 | + wp_redirect( $redirect, $status ); | |
| 338 | 318 | exit; |
| 339 | 319 | } |
| 340 | 320 | } else { |
| 341 | 321 | // Otherwise rely on MU Domain Mapping |