/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php
PHP | 11454 lines | 8995 code | 1677 blank | 782 comment | 2646 complexity | 1da29a2c6e3b1891894f9ae7200fde4a MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Main SitePress Class
- *
- * @package wpml-core
- */
- class SitePress
- {
-
- private $settings;
- private $active_languages = array();
- private $this_lang;
- private $wp_query;
- private $admin_language = null;
- private $user_preferences = array();
- private $current_user;
-
- public $footer_preview = false;
-
- public $queries = array();
-
- /**
- * @var icl_cache
- */
- public $icl_translations_cache;
- /**
- * @var icl_cache
- */
- public $icl_locale_cache;
- /**
- * @var icl_cache
- */
- public $icl_flag_cache;
- /**
- * @var icl_cache
- */
- public $icl_language_name_cache;
- /**
- * @var icl_cache
- */
- public $icl_term_taxonomy_cache;
-
- function __construct()
- {
- do_action('wpml_before_startup');
-
- global $wpdb, $pagenow;
-
- $this->settings = get_option( 'icl_sitepress_settings' );
-
- //@tODO: To remove in WPML 3.5
- //@since 3.1
- if(is_admin() && !$this->get_setting('icl_capabilities_verified')) {
- icl_enable_capabilities();
- $this->settings = get_option( 'icl_sitepress_settings' );
- }
-
- // set up current user early
- // no authentication
- if ( defined( 'LOGGED_IN_COOKIE' ) && isset( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
- list( $username ) = explode( '|', $_COOKIE[ LOGGED_IN_COOKIE ] );
- $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->users} WHERE user_login = %s", array($username) ) );
- } else {
- $user_id = 0;
- }
-
- $this->current_user = new WP_User( $user_id );
-
- if ( is_null( $pagenow ) && is_multisite() ) {
- include ICL_PLUGIN_PATH . '/inc/hacks/vars-php-multisite.php';
- }
-
- if ( false != $this->settings ) {
- $this->verify_settings();
- }
- if ( isset( $_GET[ 'icl_action' ] ) ) {
- require_once ABSPATH . WPINC . '/pluggable.php';
- if ( $_GET[ 'icl_action' ] == 'reminder_popup' ) {
- add_action( 'init', array( $this, 'reminders_popup' ) );
- } elseif ( $_GET[ 'icl_action' ] == 'dismiss_help' ) {
- $this->settings[ 'dont_show_help_admin_notice' ] = true;
- $this->save_settings();
- }
- }
-
- if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == ICL_PLUGIN_FOLDER . '/menu/troubleshooting.php' && isset( $_GET[ 'debug_action' ] ) ) {
- ob_start();
- }
-
- if ( isset( $_REQUEST[ 'icl_ajx_action' ] ) ) {
- add_action( 'init', array( $this, 'ajax_setup' ), 15 );
- }
- add_action( 'admin_footer', array( $this, 'icl_nonces' ) );
-
- // Process post requests
- if ( !empty( $_POST ) ) {
- add_action( 'init', array( $this, 'process_forms' ) );
- }
-
- add_action( 'plugins_loaded', array( $this, 'initialize_cache' ), 0 );
- add_action( 'plugins_loaded', array( $this, 'init' ), 1 );
- add_action( 'init', array( $this, 'on_wp_init' ), 1 );
-
- add_action( 'admin_print_scripts', array( $this, 'js_scripts_setup' ) );
- add_action( 'admin_print_styles', array( $this, 'css_setup' ) );
-
- // Administration menus
- add_action( 'admin_menu', array( $this, 'administration_menu' ) );
- add_action( 'admin_menu', array( $this, 'administration_menu2' ), 30 );
-
- add_action( 'init', array( $this, 'plugin_localization' ) );
-
- //add_filter('tag_template', array($this, 'load_taxonomy_template'));
-
- if ( $this->settings[ 'existing_content_language_verified' ] && ( $this->settings[ 'setup_complete' ] || ( !empty($_GET[ 'page' ]) && $this->settings['setup_wizard_step']==3 && $_GET[ 'page' ] == ICL_PLUGIN_FOLDER . '/menu/languages.php' ) ) ) {
-
- // Post/page language box
- if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' || $pagenow == 'edit.php' ) {
- add_action( 'admin_head', array( $this, 'post_edit_language_options' ) );
- }
- //For when it will be possible to add custom bulk actions
- //add_action( 'bulk_actions-edit-post', array( $this, 'bulk_actions' ) );
-
- // Post/page save actions
- add_action( 'save_post', array( $this, 'save_post_actions' ), 100, 2 );
-
- add_action( 'updated_post_meta', array( $this, 'update_post_meta' ), 100, 4 );
- add_action( 'added_post_meta', array( $this, 'update_post_meta' ), 100, 4 );
- add_action( 'updated_postmeta', array( $this, 'update_post_meta' ), 100, 4 ); // ajax
- add_action( 'added_postmeta', array( $this, 'update_post_meta' ), 100, 4 ); // ajax
- add_action( 'delete_postmeta', array( $this, 'delete_post_meta' ) ); // ajax
-
-
- // Post/page delete actions
- // add_action('delete_post', array($this,'delete_post_actions'));
- add_action( 'before_delete_post', array( $this, 'before_delete_post_actions' ) );
- add_action( 'deleted_post', array( $this, 'deleted_post_actions' ) );
- add_action( 'wp_trash_post', array( $this, 'trash_post_actions' ) );
- add_action( 'untrashed_post', array( $this, 'untrashed_post_actions' ) );
-
- add_filter( 'posts_join', array( $this, 'posts_join_filter' ), 10, 2 );
- add_filter( 'posts_where', array( $this, 'posts_where_filter' ), 10, 2 );
- add_filter( 'comment_feed_join', array( $this, 'comment_feed_join' ) );
-
- add_filter( 'comments_clauses', array( $this, 'comments_clauses' ), 10, 2 );
-
- // Allow us to filter the Query vars before the posts query is being built and executed
- add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
-
- add_action( 'loop_start', array( $this, 'loop_start' ), 10 );
- add_filter( 'the_posts', array( $this, 'the_posts' ), 10 );
- add_filter( 'get_pages', array( $this, 'get_pages' ), 100, 2 );
-
- // Filter links to the root page
- add_filter('page_link', array($this, 'filter_root_permalink'), 10, 2);
-
- if ( $pagenow == 'edit.php' ) {
- add_action( 'admin_footer', array( $this, 'language_filter' ) );
- add_action( 'quick_edit_custom_box', array( 'WPML_Terms_Translations', 'quick_edit_terms_removal' ), 10, 2 );
- }
-
- add_filter( 'get_pages', array( $this, 'exclude_other_language_pages2' ) );
- add_filter( 'wp_dropdown_pages', array( $this, 'wp_dropdown_pages' ) );
-
- // posts and pages links filters
- add_filter( 'post_link', array( $this, 'permalink_filter' ), 1, 2 );
- add_filter( 'post_type_link', array( $this, 'permalink_filter' ), 1, 2 );
- add_filter( 'page_link', array( $this, 'permalink_filter' ), 1, 2 );
-
- add_filter( 'get_comment_link', array( $this, 'get_comment_link_filter' ) );
-
- // filter the saving of terms so that the taxonomy_ids of translated terms are correctly adjusted across taxonomies
- add_action('created_term_translation', array( 'WPML_Terms_Translations', 'sync_ttid_action' ), 10, 3 );
- // filters terms by language for the term/tag-box autoselect
- if ( ( isset( $_GET[ 'action' ] ) && ( $_GET[ 'action' ] == 'ajax-tag-search' )
- || isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'get-tagcloud' ) ) {
- add_filter( 'get_terms', array( 'WPML_Terms_Translations', 'get_terms_filter' ), 10, 2 );
- }
-
- $this->set_term_filters_and_hooks();
-
- // The delete filter only ensures the synchronizing of delete actions beween translations of a term.
- add_action( 'delete_term', array( 'WPML_Terms_Translations', 'delete_term_filter' ), 1, 3 );
- add_filter('pre_term_slug', array( 'WPML_Terms_Translations', 'pre_term_slug_filter' ), 10, 2 );
- add_action( 'set_object_terms', array( 'WPML_Terms_Translations', 'set_object_terms_action' ), 10, 6 );
-
- // AJAX Actions for the post edit screen
- add_action( 'wp_ajax_wpml_get_post_parent_id_by_lang', array( 'WPML_Post_Edit_Ajax', 'wpml_get_post_parent_id_by_lang' ) );
- add_action( 'wp_ajax_wpml_get_taxonomy_terms_json', array( 'WPML_Post_Edit_Ajax', 'wpml_get_taxonomy_terms_json' ) );
- add_action( 'wp_ajax_wpml_add_term_to_post', array( 'WPML_Post_Edit_Ajax', 'wpml_add_term_to_post' ) );
- add_action( 'wp_ajax_wpml_remove_terms_from_post', array( 'WPML_Post_Edit_Ajax', 'wpml_remove_terms_from_post' ) );
- add_action( 'wp_ajax_wpml_switch_post_language', array( 'WPML_Post_Edit_Ajax', 'wpml_switch_post_language' ) );
- add_action( 'wp_ajax_wpml_before_switch_post_language', array( 'WPML_Post_Edit_Ajax', 'wpml_before_switch_post_language' ) );
- add_action( 'wp_ajax_wpml_set_post_edit_lang', array( 'WPML_Post_Edit_Ajax', 'wpml_set_post_edit_lang' ) );
- add_action( 'wp_ajax_wpml_get_translated_taxonomies', array( 'WPML_Post_Edit_Ajax', 'wpml_get_translated_taxonomies' ) );
- add_action( 'wp_ajax_wpml_get_translations_table_data', array( 'WPML_Post_Edit_Ajax', 'wpml_get_translations_table_data' ) );
- add_action( 'wp_ajax_wpml_get_post_permalink', array( 'WPML_Post_Edit_Ajax', 'wpml_get_post_permalink' ) );
- add_action( 'wp_ajax_wpml_get_default_lang', array( 'WPML_Post_Edit_Ajax', 'wpml_get_default_lang' ) );
-
- // Ajax Action for the updating of term names on the troubleshooting page
- add_action( 'wp_ajax_wpml_update_term_names_troubleshoot', array( 'WPML_Troubleshooting_Terms_Menu', 'wpml_update_term_names_troubleshoot' ) );
-
- // short circuit get default category
- add_filter( 'pre_option_default_category', array( $this, 'pre_option_default_category' ) );
- add_filter( 'update_option_default_category', array( $this, 'update_option_default_category' ), 1, 2 );
- add_action( 'after-category-table', array( 'WPML_Terms_Translations', 'category_display_action' ), 1, 1 );
-
- // custom hook for adding the language selector to the template
- add_action( 'icl_language_selector', array( $this, 'language_selector' ) );
-
- // front end js
- add_action( 'wp_head', array( $this, 'front_end_js' ) );
-
- add_action( 'wp_head', array( $this, 'rtl_fix' ) );
- add_action( 'admin_print_styles', array( $this, 'rtl_fix' ) );
-
- add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) );
-
- add_filter( 'get_edit_post_link', array( $this, 'get_edit_post_link' ), 1, 3 );
-
- // adjacent posts links
- add_filter( 'get_previous_post_join', array( $this, 'get_adjacent_post_join' ) );
- add_filter( 'get_next_post_join', array( $this, 'get_adjacent_post_join' ) );
- add_filter( 'get_previous_post_where', array( $this, 'get_adjacent_post_where' ) );
- add_filter( 'get_next_post_where', array( $this, 'get_adjacent_post_where' ) );
-
- // feeds links
- add_filter( 'feed_link', array( $this, 'feed_link' ) );
-
- // commenting links
- add_filter( 'post_comments_feed_link', array( $this, 'post_comments_feed_link' ) );
- add_filter( 'trackback_url', array( $this, 'trackback_url' ) );
- add_filter( 'user_trailingslashit', array( $this, 'user_trailingslashit' ), 1, 2 );
-
- // date based archives
- add_filter( 'year_link', array( $this, 'archives_link' ) );
- add_filter( 'month_link', array( $this, 'archives_link' ) );
- add_filter( 'day_link', array( $this, 'archives_link' ) );
- add_filter( 'getarchives_join', array( $this, 'getarchives_join' ) );
- add_filter( 'getarchives_where', array( $this, 'getarchives_where' ) );
- add_filter( 'pre_option_home', array( $this, 'pre_option_home' ) );
-
- if ( !is_admin() ) {
- add_filter( 'attachment_link', array( $this, 'attachment_link_filter' ), 10, 2 );
- }
-
- // Filter custom type archive link (since WP 3.1)
- add_filter( 'post_type_archive_link', array( $this, 'post_type_archive_link_filter' ), 10, 2 );
-
- add_filter( 'author_link', array( $this, 'author_link' ) );
-
- add_filter( 'wp_unique_post_slug', array( $this, 'wp_unique_post_slug' ), 100, 5 );
-
- add_filter( 'home_url', array( $this, 'home_url' ), 1, 4 );
-
- // language negotiation
- add_action( 'query_vars', array( $this, 'query_vars' ) );
-
- add_filter( 'language_attributes', array( $this, 'language_attributes' ) );
-
- add_action( 'locale', array( $this, 'locale' ) );
-
- if ( isset( $_GET[ '____icl_validate_domain' ] ) ) {
- echo '<!--' . get_home_url() . '-->';
- exit;
- }
-
- add_filter( 'pre_option_page_on_front', array( $this, 'pre_option_page_on_front' ) );
- add_filter( 'pre_option_page_for_posts', array( $this, 'pre_option_page_for_posts' ) );
-
- add_filter( 'option_sticky_posts', array( $this, 'option_sticky_posts' ) );
-
- add_filter( 'request', array( $this, 'request_filter' ) );
-
- add_action( 'wp_head', array( $this, 'set_wp_query' ) );
-
- add_action( 'show_user_profile', array( $this, 'show_user_options' ) );
- add_action( 'personal_options_update', array( $this, 'save_user_options' ) );
-
- // column with links to translations (or add translation) - low priority
- add_action( 'init', array( $this, 'configure_custom_column' ), 1010 ); // accommodate Types init@999
-
- if ( !is_admin() ) {
- add_action( 'wp_head', array( $this, 'meta_generator_tag' ) );
- }
-
- require_once ICL_PLUGIN_PATH . '/inc/wp-nav-menus/iclNavMenu.class.php';
- new iclNavMenu;
-
- if ( is_admin() || defined( 'XMLRPC_REQUEST' ) || preg_match( '#wp-comments-post\.php$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
- global $iclTranslationManagement, $ICL_Pro_Translation;
- $iclTranslationManagement = new TranslationManagement;
- $ICL_Pro_Translation = new ICL_Pro_Translation();
- }
-
- add_action( 'wp_login', array( $this, 'reset_admin_language_cookie' ) );
-
- if ( $this->settings[ 'seo' ][ 'canonicalization_duplicates' ] ) {
- add_action( 'template_redirect', array( $this, 'setup_canonical_urls' ), 100 );
- }
-
- add_action( 'init', array( $this, '_taxonomy_languages_menu' ), 99 ); //allow hooking in
-
- if ( $this->settings[ 'seo' ][ 'head_langs' ] ) {
- add_action( 'wp_head', array( $this, 'head_langs' ) );
- }
-
- /**
- * add extra debug information
- */
- add_filter( 'icl_get_extra_debug_info', array( $this, 'add_extra_debug_info' ) );
- } //end if the initial language is set - existing_content_language_verified
-
- add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget_setup' ) );
- if ( is_admin() && $pagenow == 'index.php' ) {
- add_action( 'icl_dashboard_widget_notices', array( $this, 'print_translatable_custom_content_status' ) );
- }
-
- add_filter( 'core_version_check_locale', array( $this, 'wp_upgrade_locale' ) );
-
- if ( $pagenow == 'post.php' && isset( $_REQUEST[ 'action' ] ) && $_REQUEST[ 'action' ] == 'edit' && isset( $_GET[ 'post' ] ) ) {
- add_action( 'init', '_icl_trash_restore_prompt' );
- }
-
- add_action( 'init', array( $this, 'js_load' ), 2 ); // enqueue scripts - higher priority
-
- add_filter( 'get_pagenum_link', array( $this, 'get_pagenum_link' ) );
-
- add_action('switch_blog', array($this, 'init_settings'));
- add_filter('url_to_postid', array($this, 'url_to_postid'));
-
- //cron job to update WPML config index file from CDN
- add_action('update_wpml_config_index', array($this,'update_wpml_config_index_event'));
- //update WPML config files
- add_action('wp_ajax_update_wpml_config_index', array($this,'update_wpml_config_index_event_ajax'));
- add_action( 'after_switch_theme', array( $this, 'update_wpml_config_index_event' ) );
- add_action( 'activated_plugin', array( $this, 'update_wpml_config_index_event' ) );
-
- add_action('core_upgrade_preamble', array($this, 'update_index_screen'));
-
- add_shortcode('wpml_language_selector_widget', 'icl_language_selector');
- add_shortcode('wpml_language_selector_footer', 'icl_language_selector_footer');
-
- add_filter('get_search_form', array($this, 'get_search_form_filter'));
-
- add_action('plugins_loaded', array($this, 'load_dependencies'), 10000);
- do_action('wpml_after_startup');
- }
-
- function get_pagenum_link( $url ) {
-
- // fix cases like that in url:
- // lang=pl%2F%3Flang%3Dpl
- // lang=pl/?lang=pl
- $current_language = $this->get_current_language();
- $find[ ] = 'lang=' . $current_language . '%2F%3Flang%3D' . $current_language;
- $find[ ] = 'lang=' . $current_language . '/?lang=' . $current_language;
- $replace = 'lang=' . $current_language;
-
- $url = str_replace( $find, $replace, $url );
-
- // fix cases like that:
- // ?lang=pl/page/3/?lang=pl
-
- $pattern = '/(\?lang=' . $current_language . ')(\/page\/\d+)/';
-
- $url = preg_replace( $pattern, '$2', $url );
-
- return $url;
- }
-
- function init()
- {
- do_action('wpml_before_init');
-
- global $wpdb;
-
- $this->get_user_preferences();
- $this->set_admin_language();
-
- $default_language = $this->get_default_language();
-
- // default value for theme_localization_type OR
- // reset theme_localization_type if string translation was on (theme_localization_type was set to 2) and then it was deactivated
- if ( !isset( $this->settings[ 'theme_localization_type' ] ) || ( $this->settings[ 'theme_localization_type' ] == 1 && !defined( 'WPML_ST_VERSION' ) && !defined( 'WPML_DOING_UPGRADE' ) ) ) {
- global $sitepress_settings;
- $this->settings[ 'theme_localization_type' ] = $sitepress_settings[ 'theme_localization_type' ] = 2;
- }
-
- //configure callbacks for plugin menu pages
- if ( defined( 'WP_ADMIN' ) && isset( $_GET[ 'page' ] ) && 0 === strpos( $_GET[ 'page' ], basename( ICL_PLUGIN_PATH ) . '/' ) ) {
- add_action( 'icl_menu_footer', array( $this, 'menu_footer' ) );
- }
-
- //Run only if existing content language has been verified, and is front-end or settings are not corrupted
- if (!empty( $this->settings[ 'existing_content_language_verified' ] ) && (!is_admin() || SitePress::check_settings_integrity()) ) {
-
- if ( $this->settings[ 'language_negotiation_type' ] == 1 && $this->settings[ 'urls' ][ 'directory_for_default_language' ] && $this->settings[ 'urls' ][ 'show_on_root' ] == 'page' ) {
- include ICL_PLUGIN_PATH . '/inc/home-url-functions.php';
- }
-
- if ($this->settings[ 'language_negotiation_type' ] == 2) {
- add_filter( 'allowed_redirect_hosts', array( $this, 'allowed_redirect_hosts' ) );
- }
-
- if ( defined( 'WP_ADMIN' ) ) {
-
- if ( $this->settings[ 'language_negotiation_type' ] == 2 ) {
- //Login and Logout
- add_filter( 'login_url', array( $this, 'convert_url' ) );
- add_filter( 'logout_url', array( $this, 'convert_url' ) );
- add_filter( 'site_url', array( $this, 'convert_url' ) );
- }
-
- if (isset($_GET['post']) && is_numeric($_GET['post'])) {
- $post_type = get_post_type($_GET['post']);
- }
-
- $current_user = wp_get_current_user();
-
- if ( isset( $_GET[ 'lang' ] ) ) {
- $this->this_lang = rtrim( strip_tags( $_GET[ 'lang' ] ), '/' );
- $al = $this->get_active_languages();
- $al[ 'all' ] = true;
- if ( empty( $al[ $this->this_lang ] ) ) {
- $this->this_lang = $default_language;
- }
- // force default language for string translation
- // we also make sure it's not saved in the cookie
- } elseif ( isset( $_GET[ 'page' ] ) && ( ( defined( 'WPML_ST_FOLDER' ) && $_GET[ 'page' ] == WPML_ST_FOLDER . '/menu/string-translation.php' ) || ( defined( 'WPML_TM_FOLDER' ) && $_GET[ 'page' ] == WPML_TM_FOLDER . '/menu/translations-queue.php' ) )
- ) {
- $this->this_lang = $default_language;
- } elseif ( wpml_is_ajax() ) {
- $al = $this->get_active_languages();
- if ( isset( $_POST[ 'lang' ] ) && isset( $al[ $_POST[ 'lang' ] ] ) ) {
- $this->this_lang = $_POST[ 'lang' ];
- } else {
- if ($this->check_if_admin_action_from_referer()){
- $this->this_lang = $this->get_admin_language_cookie();
- } elseif(isset($_SERVER['HTTP_REFERER'])) {
- $this->this_lang = $this->get_language_from_url($_SERVER['HTTP_REFERER']);
- }
- }
- } elseif ( $lang = $this->get_admin_language_cookie() ) {
- $this->this_lang = $lang;
- } elseif ( isset($_POST['action']) && $_POST['action'] == 'editpost' && isset($_POST['icl_post_language'])) {
- $this->this_lang = $_POST['icl_post_language'];
- } elseif ( isset($_GET['post']) && is_numeric($_GET['post']) && isset($post_type) && $this->is_translated_post_type($post_type)) {
- $this->this_lang = $this->get_language_for_element($_GET['post'], 'post_' . $post_type);
- } elseif(isset($current_user->data)) {
- $lang = $this->get_user_admin_language( $current_user->data->ID );
- $this->this_lang = $lang ? $lang : $default_language;
- }
-
- $update_admin_language_cookie = false;
- $update_admin_language_cookie |= is_admin() && isset($_GET['lang']) && ( $this->get_current_language() != $this->get_admin_language_cookie() );
- $update_admin_language_cookie |= isset( $_GET[ 'admin_bar' ] ) && ( $_GET[ 'admin_bar' ] == 1 ) && !isset( $_GET[ 'page' ] );
- $update_admin_language_cookie |= !defined( 'WPML_ST_FOLDER' ) || ( isset($_GET[ 'page' ]) && $_GET[ 'page' ] != WPML_ST_FOLDER . '/menu/string-translation.php' );
- $update_admin_language_cookie |= !$this->get_admin_language_cookie();
-
- if ( $update_admin_language_cookie ) {
- $this->set_admin_language_cookie();
- }
- } else {
- $al = $this->get_active_languages();
- foreach ( $al as $l ) {
- $active_languages[ ] = $l[ 'code' ];
- }
- $active_languages[ ] = 'all';
- $s = isset( $_SERVER[ 'HTTPS' ] ) && $_SERVER[ 'HTTPS' ] == 'on' ? 's' : '';
- $home = get_home_url();
- if ( $s ) {
- $home = preg_replace( '#^http://#', 'https://', $home );
- }
- $url_parts = parse_url( $home );
- $non_default_port = ( isset( $url_parts[ 'port' ] ) && $url_parts[ 'port' ] != 80 ) ? ':' . $url_parts[ 'port' ] : '';
- $request = 'http' . $s . '://' . $this->get_server_host_name() . $_SERVER[ 'REQUEST_URI' ];
- $blog_path = ! empty( $url_parts[ 'path' ] ) ? $url_parts[ 'path' ] : '';
-
- switch ( $this->settings[ 'language_negotiation_type' ] ) {
- case 1:
-
- $path = str_replace( $home, '', $request );
- $parts = explode( '?', $path );
- $path = $parts[ 0 ];
- $exp = explode( '/', trim( $path, '/' ) );
- $language_part = $exp[ 0 ];
-
- if ( in_array( $language_part, $active_languages ) ) {
- $this->this_lang = $exp[ 0 ];
-
- // before hijacking the SERVER[REQUEST_URI]
- // override the canonical_redirect action
- // keep a copy of the original request uri
- remove_action( 'template_redirect', 'redirect_canonical' );
- global $_icl_server_request_uri;
- $_icl_server_request_uri = $_SERVER[ 'REQUEST_URI' ];
- add_action( 'template_redirect', array($this,'icl_redirect_canonical_wrapper'), 0 );
-
- //deal with situations when template files need to be called directly
- add_action( 'template_redirect', array( $this, '_allow_calling_template_file_directly' ) );
-
- //$_SERVER['REQUEST_URI'] = preg_replace('@^'. $blog_path . '/' . $this->this_lang.'@i', $blog_path ,$_SERVER['REQUEST_URI']);
-
- // Check for special case of www.example.com/fr where the / is missing on the end
- $parts = parse_url( $_SERVER[ 'REQUEST_URI' ] );
- if ( strlen( $parts[ 'path' ] ) == 0 ) {
- $_SERVER[ 'REQUEST_URI' ] = '/' . $_SERVER[ 'REQUEST_URI' ];
- }
- } else {
- $this->this_lang = $default_language;
- }
-
- /* If we access the root url via a non root slug/parameter combination,
- * we redirect accordingly.
- */
- if ( $this->settings[ 'language_negotiation_type' ] == 1 && $this->settings[ 'urls' ][ 'directory_for_default_language' ] && $this->settings[ 'urls' ][ 'show_on_root' ] == 'page' ) {
- $filtered_root_url = $this->filter_root_permalink( wpml_strip_subdir_from_url( site_url() ) . $_SERVER[ 'REQUEST_URI' ] );
- if ( $filtered_root_url != wpml_strip_subdir_from_url( site_url() ) . $_SERVER[ 'REQUEST_URI' ] ) {
- wp_redirect( $filtered_root_url, 302 );
- exit();
- }
- }
-
- if ( $this->is_root_page() ) {
- if ( $this->settings[ 'urls' ][ 'show_on_root' ] == 'html_file' ) {
- // html file
- if ( false === strpos( $this->settings[ 'urls' ][ 'root_html_file_path' ], '/' ) ) {
- $html_file = ABSPATH . $this->settings[ 'urls' ][ 'root_html_file_path' ];
- } else {
- $html_file = $this->settings[ 'urls' ][ 'root_html_file_path' ];
- }
-
- /** @noinspection PhpIncludeInspection */
- include $html_file;
- exit;
- } else {
- wpml_home_url_setup_root_page();
- }
- }
-
- break;
- case 2:
-
- $this->this_lang = $default_language;
- foreach( $this->settings[ 'language_domains' ] as $language_code => $domain ){
- if( rtrim( $this->get_server_host_name() . $blog_path, '/' ) == rtrim( preg_replace( '@^https?://@', '', $domain ), '/' ) ){
- $this->this_lang = $language_code;
- break;
- }
- }
-
- if ( defined( 'ICL_USE_MULTIPLE_DOMAIN_LOGIN' ) && ICL_USE_MULTIPLE_DOMAIN_LOGIN ) {
- include ICL_PLUGIN_PATH . '/modules/multiple-domains-login.php';
- }
- add_filter( 'site_url', array( $this, 'convert_url' ) );
- break;
- case 3:
- default:
- if ( isset( $_GET[ 'lang' ] ) ) {
- $this->this_lang = preg_replace( "/[^0-9a-zA-Z-]/i", '', strip_tags( $_GET[ 'lang' ] ) );
- // set the language based on the content id - for short links
- } elseif ( isset( $_GET[ 'page_id' ] ) ) {
- $language_code_prepared = $wpdb->prepare( "SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type='post_page' AND element_id=%d", $_GET[ 'page_id' ] );
- $this->this_lang = $wpdb->get_var( $language_code_prepared );
- } elseif ( isset( $_GET[ 'p' ] ) ) {
- $post_type_prepared = $wpdb->prepare( "SELECT post_type FROM {$wpdb->posts} WHERE ID=%d", $_GET[ 'p' ] );
- $post_type = $wpdb->get_var( $post_type_prepared );
- $language_code_prepared = $wpdb->prepare( "SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type=%s AND element_id=%d", 'post_' . $post_type, $_GET[ 'p' ] );
- $this->this_lang = $wpdb->get_var( $language_code_prepared );
- } elseif ( isset( $_GET[ 'cat_ID' ] ) ) {
- $cat_tax_id_prepared = $wpdb->prepare( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", $_GET[ 'cat_ID' ], 'category' );
- $cat_tax_id = $wpdb->get_var( $cat_tax_id_prepared );
- $language_code_prepared = $wpdb->prepare( "SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type='tax_category' AND element_id=%d", $cat_tax_id );
- $this->this_lang = $wpdb->get_var( $language_code_prepared );
- } elseif ( isset( $_GET[ 'tag' ] ) ) {
- $tag_tax_id_prepared = $wpdb->prepare( "
- SELECT x.term_taxonomy_id FROM {$wpdb->term_taxonomy} x JOIN {$wpdb->terms} t ON t.term_id = x.term_id
- WHERE t.slug=%s AND x.taxonomy='post_tag'", $_GET[ 'tag' ] );
- $tag_tax_id = $wpdb->get_var( $tag_tax_id_prepared );
- $language_code_prepared = $wpdb->prepare( "SELECT language_code FROM {$wpdb->prefix}icl_translations
- WHERE element_type='tax_post_tag' AND element_id=%d", $tag_tax_id );
- $this->this_lang = $wpdb->get_var( $language_code_prepared );
- }
-
-
- //
- if ( !isset( $_GET[ 'lang' ] ) && ( $this->this_lang && $this->this_lang != $default_language ) ) {
- if ( !isset( $GLOBALS[ 'wp_rewrite' ] ) ) {
- require_once ABSPATH . WPINC . '/rewrite.php';
- $GLOBALS[ 'wp_rewrite' ] = new WP_Rewrite();
- }
- define( 'ICL_DOING_REDIRECT', true );
- if ( isset( $_GET[ 'page_id' ] ) ) {
- wp_redirect( get_page_link( $_GET[ 'page_id' ] ), '301' );
- exit;
- } elseif ( isset( $_GET[ 'p' ] ) ) {
- wp_redirect( get_permalink( $_GET[ 'p' ] ), '301' );
- exit;
- } elseif ( isset( $_GET[ 'cat_ID' ] ) ) {
- wp_redirect( get_term_link( intval( $_GET[ 'cat_ID' ] ), 'category' ) );
- exit;
- } elseif ( isset( $_GET[ 'tag' ] ) ) {
- wp_redirect( get_term_link( $_GET[ 'tag' ], 'post_tag' ) );
- exit;
- } else {
- if ( isset( $this->settings[ 'taxonomies_sync_option' ] ) ) {
- $taxs = array_keys( (array)$this->settings[ 'taxonomies_sync_option' ] );
- foreach ( $taxs as $t ) {
- if ( isset( $_GET[ $t ] ) ) {
- $term_obj = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON t.term_id = x.term_id
- WHERE t.slug=%s AND x.taxonomy=%s", $_GET[ $t ], $t ) );
- $term_link = get_term_link( $term_obj, $t );
- $term_link = str_replace( '&', '&', $term_link ); // fix
- if ( $term_link && !is_wp_error( $term_link ) ) {
- wp_redirect( $term_link );
- exit;
- }
- }
- }
- }
- }
-
- }
-
- if ( empty( $this->this_lang ) ) {
- $this->this_lang = $default_language;
- }
- }
- // allow forcing the current language when it can't be decoded from the URL
- $this->this_lang = apply_filters( 'icl_set_current_language', $this->this_lang );
-
- }
-
- //reorder active language to put 'this_lang' in front
- foreach ( $this->active_languages as $k => $al ) {
- if ( $al[ 'code' ] == $this->this_lang ) {
- unset( $this->active_languages[ $k ] );
- $this->active_languages = array_merge( array( $k => $al ), $this->active_languages );
- }
- }
-
- WPML_Troubleshooting_Terms_Menu::display_terms_with_suffix_admin_notice();
-
- // filter some queries
- add_filter( 'query', array( $this, 'filter_queries' ) );
-
- add_filter( 'option_rewrite_rules', array( $this, 'rewrite_rules_filter' ) );
-
- $this->set_language_cookie();
-
- if ( is_admin() && ( !isset( $_GET[ 'page' ] ) || !defined( 'WPML_ST_FOLDER' ) || $_GET[ 'page' ] != WPML_ST_FOLDER . '/menu/string-translation.php' ) && ( !isset( $_GET[ 'page' ] ) || !defined( 'WPML_TM_FOLDER' ) || $_GET[ 'page' ] != WPML_TM_FOLDER . '/menu/translations-queue.php' )
- ) {
-
- if ( version_compare( $GLOBALS[ 'wp_version' ], '3.3', '<' ) ) {
- // Legacy code for admin language switcher
- if ( !$this->is_rtl() && version_compare( $GLOBALS[ 'wp_version' ], '3.3', '>' ) ) {
- add_action( 'admin_notices', 'wpml_set_admin_language_switcher_place', 100 );
- add_action( 'network_admin_notices', 'wpml_set_admin_language_switcher_place', 100 );
- add_action( 'user_admin_notices', 'wpml_set_admin_language_switcher_place', 100 );
- function wpml_set_admin_language_switcher_place()
- {
- echo '<br clear="all" />';
- }
- }
- add_action( 'in_admin_header', array( $this, 'admin_language_switcher_legacy' ) );
- } else {
- // Admin language switcher goes to the WP admin bar
- add_action( 'wp_before_admin_bar_render', array( $this, 'admin_language_switcher' ) );
- }
-
- }
-
- if ( !is_admin() && defined( 'DISQUS_VERSION' ) ) {
- include ICL_PLUGIN_PATH . '/modules/disqus.php';
- }
-
- }
-
- /*
- * If user perform bulk taxonomy deletion when displaying non-default
- * language taxonomies, after deletion should stay with same language
- */
-
- if ( is_admin() &&
- isset($_POST['_wp_http_referer'])
- && false !== strpos($_POST['_wp_http_referer'], 'edit-tags.php')
-
- && !empty($_POST['delete_tags'])
- && is_array($_POST['delete_tags'])
-
- && !empty($_GET['lang'])
- && (
- $_POST['action'] == 'delete' || $_POST['action2'] == 'delete'
- ) ) {
- add_filter('wp_redirect', array($this, 'preserve_lang_param_after_bulk_category_delete'));
- }
-
- if ( $this->is_rtl() ) {
- $GLOBALS[ 'text_direction' ] = 'rtl';
- }
-
- if (!wpml_is_ajax() && is_admin() && empty( $this->settings[ 'dont_show_help_admin_notice' ] ) ) {
- if ( !$this->get_setting('setup_wizard_step') ) {
- if(SitePress::check_settings_integrity()) {
- add_action( 'admin_notices', array( $this, 'help_admin_notice' ) );
- }
- }
- }
-
- $short_v = implode( '.', array_slice( explode( '.', ICL_SITEPRESS_VERSION ), 0, 3 ) );
- if ( is_admin() && ( !isset( $this->settings[ 'hide_upgrade_notice' ] ) || $this->settings[ 'hide_upgrade_notice' ] != $short_v ) ) {
- add_action( 'admin_notices', array( $this, 'upgrade_notice' ) );
- }
-
- require ICL_PLUGIN_PATH . '/inc/template-constants.php';
- if ( defined( 'WPML_LOAD_API_SUPPORT' ) ) {
- require ICL_PLUGIN_PATH . '/inc/wpml-api.php';
-
- }
-
- add_action( 'wp_footer', array( $this, 'display_wpml_footer' ), 20 );
-
- if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
- add_action( 'xmlrpc_call', array( $this, 'xmlrpc_call_actions' ) );
- add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) );
- }
-
- if ( defined( 'WPML_TM_VERSION' ) && is_admin() ) {
- require ICL_PLUGIN_PATH . '/inc/quote.php';
- }
-
- add_action( 'init', array( $this, 'set_up_language_selector' ) );
-
- global $pagenow;
- if ( $pagenow == 'admin-ajax.php' ) {
- if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'wpml_tt_show_terms') {
- $default_language = $this->get_default_language();
- //@todo: remove the following live after WPML 3.5 release
- //$this->switch_lang($default_language, true);
- }
- }
- // set language to default and remove language switcher when in Taxonomy Translation page
- // If the page uses AJAX and the language must be forced to default, please use the
- // if ( $pagenow == 'admin-ajax.php' )above
- if ( is_admin() && isset( $_GET[ 'page' ] ) && ( $_GET[ 'page' ] == ICL_PLUGIN_FOLDER . '/menu/taxonomy-translation.php' || $_GET[ 'page' ] == ICL_PLUGIN_FOLDER . '/menu/menus-sync.php' ) ) {
- $default_language = $this->get_admin_language();
- $this->switch_lang($default_language, true);
- add_action( 'init', array( $this, 'remove_admin_language_switcher'));
- }
-
- /* Posts and new inline created terms, can only be saved in an active language.
- * Also the content of the post-new.php should always be filtered for one specific
- * active language, so to display the correct taxonomy terms for selection.
- */
- if ( $pagenow == 'post-new.php' ) {
- if ( ! $this->is_active_language( $this->get_current_language() ) ) {
- $default_language = $this->get_admin_language();
- $this->switch_lang( $default_language, true );
- }
- }
-
- //Code to run when reactivating the plugin
- $recently_activated = $this->get_setting('just_reactivated');
- if($recently_activated) {
- add_action( 'init', array( $this, 'rebuild_language_information' ), 1000 );
- }
-
- do_action('wpml_after_init');
- }
-
- /**
- * @param bool|String $requested_url String If this is specified the value of $url will be checked for whether it's the root page.
- * Checks whether the currently requested page is the root page.
- *
- * @return bool
- */
- function is_root_page( $requested_url = false ) {
-
- /*
- * A request leads to the root page under the following conditions.
- *
- * 1. The get parameter on it specifically requests the root page via either:
- * ?preview_id = {root_page_id}
- * ?page_id = {root_page_id}
- * ?p = {root_page_id}
- *
- * 2. The root page slug is the first slug after the domain.
- *
- * 3. There is no slug after the domain and the get parameters are not set as to redirect
- * to another page meaning:
- * no ?p, ?page_id or similar query parameter redirects to another post/page
- * no get parameter such as ?cat redirects to an archive page
- *
- */
-
- $is_root = true;
-
- // before checking anything see if the site even uses a root page
-
- $urls = $this->get_setting( 'urls' );
-
- if ( ! $urls
- || ! isset( $urls[ 'directory_for_default_language' ] )
- || ! $urls[ 'directory_for_default_language' ]
- || ! isset( $urls[ 'root_page' ] )
- || $urls[ 'root_page' ] == 0
- ) {
- $is_root = false;
- } elseif ( isset( $_SERVER[ 'REQUEST_URI' ] ) || $requested_url !== false ) {
-
- $root_id = $urls[ 'root_page' ];
- $root_slug = false;
- if ( $root_id ) {
- $root_page_object = get_post( $root_id );
- if ( $root_page_object && isset( $root_page_object->post_name ) ) {
- $root_slug = $root_page_object->post_name;
- }
- }
-
- if ( $root_slug === false ) {
- $is_root = false;
- } else {
-
- if ( $requested_url ) {
- $request_uri = parse_url( $requested_url, PHP_URL_PATH );
- $query_string = parse_url( $requested_url, PHP_URL_QUERY );
- if( $query_string ) {
- $request_uri .= '?' . $query_string;
- }
- } else {
- $request_uri = $_SERVER[ 'REQUEST_URI' ];
- }
-
- //If the get parameter ? is not preceeded by a /, add a '/'
- if ( strpos( $request_uri, '?' ) !== false && strpos( $request_uri, '/?' ) === false ) {
- $request_uri = str_replace( '?', '/?', $request_uri );
- }
-
- $request_uri = wpml_strip_subdir_from_url( $request_uri );
-
- //First get the slug of the requested url, should there be one.
- $slugs_and_get_params = explode( '/', $request_uri );
-
- foreach ( $slugs_and_get_params as $key => $slug ) {
- if ( ! trim( $slug ) ) {
- unset( $slugs_and_get_params[ $key ] );
- }
- }
-
- // if we have any slugs or get parameters it could be we are not on the root page
-
- if ( ! empty( $slugs_and_get_params ) ) {
- $get_query_string = '';
- // First of all see if we have get parameters
- if ( isset( $_GET ) && ! empty( $_GET ) ) {
- $get_query_string = array_pop( $slugs_and_get_params );
- /* In case we have get parameters we can instantly be sure to be on the root page
- * This can be done by either id parameters or by slug/name parameters.
- * ID parametes as of WP 4.1 are : p, page_id
- * Name parameters as of WP 4.1 are: name, pagename
- */
-
- if ( ( isset( $_GET[ 'p' ] ) && $_GET[ 'p' ] != $root_id )
- || ( isset( $_GET[ 'page_id' ] ) && $_GET[ 'page_id' ] != $root_id )
- || ( isset( $_GET[ 'name' ] ) && $_GET[ 'name' ] != $root_slug )
- || ( isset( $_GET[ 'pagename' ] ) && $_GET[ 'pagename' ] != $root_slug )
- ) {
- $is_root = false;
- }
- }
-
- /*
- * Next up there are other get parameters that allow us to recognize not being on the root page for certain.
- * These only come into play when neither of the above page parameters is set and therefore no specific page is queried for.
- */
- if ( ! ( isset( $_GET[ 'pagename' ] ) || isset( $_GET[ 'name' ] ) || isset( $_GET[ 'page_id' ] ) || isset( $_GET[ 'p' ] ) ) ) {
-
- /* The under these conditions excluded parameters, that ensure the root page to not be queried for, are determined in this way:
- * First we fetch all rewrite rules. This has to be done from the options cache since the actual rewrite object is not initialized yet.
- * Initializing it would impose a siginificant performance hit too.
- */
- $query = new WP_Query( str_replace( '?', '', $get_query_string ) );
-
- if ( ( $query->is_archive() ) ) {
- $is_root = false;
- }
- }
-
-
- // In case we have slugs, we need to check the last slug for whether it is the slug of the root page
-
- if ( $is_root && ! empty( $slugs_and_get_params ) ) {
- $slugs = $slugs_and_get_params;
- $last_slug = array_pop( $slugs );
- $second_slug = array_pop( $slugs );
- if ( ( $root_slug != $last_slug && ! is_numeric( $last_slug )
- || ( is_numeric( $last_slug ) && $second_slug != null && $root_slug != $second_slug && 'page' != $second_slug ) )
- && ( ! ( isset( $_GET[ 'p' ] ) && $_GET[ 'p' ] == $root_id )
- || ! ( isset( $_GET[ 'page_id' ] ) && $_GET[ 'page_id' ] == $root_id )
- || ! ( isset( $_GET[ 'name' ] ) && $_GET[ 'name' ] == $root_slug )
- || ! ( isset( $_GET[ 'pagename' ] ) && $_GET[ 'pagename' ] == $root_slug ) )
- ) {
- /* If the last slug is not the root slug or numeric,
- * then the current page is not the root page. This condition only holds though
- * in case no page/post parameters are appended to the request, that point towards the root page.
- */
- $is_root = false;
- }
- }
- }
- }
- }
-
- return $is_root;
- }
-
- /**
- * @param $url
- * Filters links to the root page, so that they are displayed properly in the front-end.
- *
- * @return mixed
- */
- function filter_root_permalink( $url ) {
- $urls = $this->get_setting( 'urls' );
- $root_id = $urls[ 'root_page' ];
- $root_page_object = get_post( $root_id );
- $url = str_replace( ' ', '', $url );
- $url = str_replace( '%20/', '/', $url );
-
- if ( $this->is_root_page( $url ) ) {
- $root_slug = $root_page_object->post_name;
-
- // Remove all whitespaces from urls
- $method = '';
- $new_url = str_replace( 'http://', '', $url );
- if ( $new_url != $url ) {
- $method = 'http://';
- } else {
- $new_url = str_replace( 'https://', '', $url );
- if ( $new_url != $url ) {
- $method = 'https://';
- }
- }
-
- $query = '';
-
- if ( strpos( $new_url, '?' ) !== false ) {
-
- $split_by_get_url = explode( '?', $new_url );
- $url_without_query = array_shift( $split_by_get_url );
- $query = implode( '?', $split_by_get_url );
- } else {
- $url_without_query = $new_url;
- }
-
- $slugs = explode( '/', $url_without_query );
-
- foreach ( $slugs as $key => $slug ) {
- if ( $slug == '' || strpos( $slug, parse_url( $url, PHP_URL_HOST ) ) !== false ) {
- unset( $slugs[ $key ] );
- }
- }
-
- $last_slug = array_pop( $slugs );
- $second_slug = array_pop( $slugs );
-
- if ( $second_slug == $root_slug && ( is_numeric( $last_slug ) || $last_slug == "" ) ) {
- $url_without_query = str_replace( '/' . $second_slug . '/', '/', $url_without_query );
- $potential_lang_slug = array_pop( $slugs );
- } elseif ( $last_slug == $root_slug ) {
- $url_without_query = str_replace( '/' . $last_slug, '/', $url_without_query );
- $potential_lang_slug = $second_slug;
- } else {
- $potential_lang_slug = array_pop( $slugs );
- }
-
- $all_langs = $this->get_active_languages();
-
- foreach ( $all_langs as $lang ) {
- if ( $lang[ 'code' ] == $potential_lang_slug ) {
- $url_without_query = str_replace( '/' . $potential_lang_slug, '/', $url_without_query );
- break;
- }
- }
- $new_url = trailingslashit($url_without_query);
-
- if ( $query != '' ) {
- $new_url = $new_url . '?' . $query;
- }
-
- /* Only if we actually have a root url, do we filter the url here.
- * This is to ensure that cases like url/wp-admin/members/root-slug are properly
- * differentiated from actualy root page calls, in case of root-slug's with
- * generic names potentially causing collisions.
- */
-
- if ( empty( $slugs ) ) {
- $url = $method . $new_url;
- }
- }
-
- return $url;
- }
-
- function load_dependencies() {
- do_action('wpml_load_dependencies');
- }
-
- /**
- * Sets up all term/taxonomy actions for use outside Translations Management or the Post Edit screen
- */
- function set_term_filters_and_hooks(){
- add_filter( 'terms_clauses', array( $this, 'terms_clauses' ), 10, 4 );
- add_filter( 'list_terms_exclusions', array( $this, 'exclude_other_terms' ), 1, 2 );
- add_filter( 'term_link', array( $this, 'tax_permalink_filter' ), 1, 2 );
- add_action( 'create_term', array( $this, 'create_term' ), 1, 2 );
- add_action( 'edit_term', array( $this, 'create_term' ), 1, 2 );
- add_filter( 'get_terms_args', array( $this, 'get_terms_args_filter' ) );
- add_filter( 'get_edit_term_link', array( $this, 'get_edit_term_link' ), 1, 4 );
-
- add_action('wp_ajax_icl_repair_broken_type_and_language_assignments', 'icl_repair_broken_type_and_language_assignments');
-
- //Taxonomies
- if ( version_compare( preg_replace( '#-RC[0-9]+(-[0-9]+)?$#', '', $GLOBALS[ 'wp_version' ] ), '3.1', '<' ) ) {
- add_filter( 'category_link', array( $this, 'category_permalink_filter' ), 1, 2 );
- add_filter( 'tag_link', array( $this, 'tax_permalink_filter' ), 1, 2 );
- }
- add_filter( 'taxonomy_template', array( $this, 'slug_template' ) );
- add_filter( 'category_template', array( $this, 'slug_template' ) );
-
- //post/page delete taxonomy
- add_action( 'deleted_term_relationships', array( $this, 'deleted_term_relationships' ), 10, 2 );
-
- // adjust queried categories and tags ids according to the language
- if ( $this->settings[ 'auto_adjust_ids' ] ) {
- add_action( 'parse_query', array( $this, 'parse_query' ) );
- add_action( 'wp_list_pages_excludes', array( $this, 'adjust_wp_list_pages_excludes' ) );
- if ( !is_admin() ) {
- add_filter( 'get_term', array( $this, 'get_term_adjust_id' ), 1, 1 );
- add_filter( 'category_link', array( $this, 'category_link_adjust_id' ), 1, 2 );
- add_filter( 'get_terms', array( $this, 'get_terms_adjust_ids' ), 1, 3 );
- add_filter( 'get_pages', array( $this, 'get_pages_adjust_ids' ), 1, 2 );
- }
- }
- }
-
- function icl_redirect_canonical_wrapper()
- {
- global $_icl_server_request_uri;
- $requested_url = ( !empty( $_SERVER[ 'HTTPS' ] ) && mb_strtolower( $_SERVER[ 'HTTPS' ] ) == 'on' ) ? 'https://' : 'http://';
- $requested_url .= $this->get_server_host_name();
- $requested_url .= $_icl_server_request_uri;
- redirect_canonical( $requested_url );
- }
-
- /**
- * If user perform bulk taxonomy deletion when displaying non-default
- * language taxonomies, after deletion should stay with same language
- *
- * @param string $location Url where browser will redirect
- * @return string Url where browser will redirect
- */
- function preserve_lang_param_after_bulk_category_delete($location) {
- if (empty($_GET['lang'])) {
- return $location;
- }
-
- $location = add_query_arg( 'lang', $_GET['lang'], $location );
-
- return $location;
- }
-
- function remove_admin_language_switcher() {
- remove_action( 'wp_before_admin_bar_render', array( $this, 'admin_language_switcher' ) );
- }
-
- function rebuild_language_information() {
- $this->set_setting('just_reactivated', 0);
- $this->save_settings();
- global $iclTranslationManagement;
- if ( isset( $iclTranslationManagement ) ) {
- $iclTranslationManagement->add_missing_language_information();
- }
- }
-
- function on_wp_init()
- {
- if ( is_admin() && current_user_can( 'manage_options' ) ) {
- if ( $this->icl_account_configured() ) {
- add_action( 'admin_notices', array( $this, 'icl_reminders' ) );
- }
- }
-
- include ICL_PLUGIN_PATH . '/inc/translation-management/taxonomy-translation.php';
- }
-
- function setup()
- {
- $setup_complete = $this->get_setting('setup_complete');
- if(!$setup_complete) {
- $this->set_setting('setup_complete', false);
- }
- return $setup_complete;
- }
-
- function get_current_user()
- {
- global $current_user;
- if ( did_action( 'set_current_user' ) ) {
- return $current_user;
- } else {
- return $this->current_user; // created early / no authentication
- }
- }
-
- function ajax_setup()
- {
- require ICL_PLUGIN_PATH . '/ajax.php';
- }
-
- function check_if_admin_action_from_referer() {
-
- $result = false;
- if ( isset( $_SERVER[ 'HTTP_REFERER' ] ) ) {
- $http_referer = parse_url( $_SERVER[ 'HTTP_REFERER' ] );
- $referer_path = $http_referer[ 'path' ];
- $referer_parts = explode( '/', $referer_path );
- if ( in_array( 'wp-admin', $referer_parts ) ) {
- $result = true;
- }
- }
-
- return $result;
- }
-
- function configure_custom_column()
- {
- global $pagenow, $wp_post_types;
-
- $pagenow_ = '';
-
- $is_ajax = false;
- if ( $pagenow == 'admin-ajax.php' ) {
- if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'inline-save' || isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'fetch-list'
- ) {
- $is_ajax = true;
- }
- }
-
- if ( ( $pagenow == 'edit.php' || $pagenow_ == 'edit-pages.php' || $is_ajax ) ) {
- $post_type = isset( $_REQUEST[ 'post_type' ] ) ? $_REQUEST[ 'post_type' ] : 'post';
- switch ( $post_type ) {
- case 'post':
- case 'page':
- add_filter( 'manage_' . $post_type . 's_columns', array( $this, 'add_posts_management_column' ) );
- if ( isset( $_GET[ 'post_type' ] ) && $_GET[ 'post_type' ] == 'page' ) {
- add_action( 'manage_' . $post_type . 's_custom_column', array( $this, 'add_content_for_posts_management_column' ) );
- }
- add_action( 'manage_posts_custom_column', array( $this, 'add_content_for_posts_management_column' ) );
- break;
- default:
- if ( in_array( $post_type, array_keys( $this->get_translatable_documents() ) ) ) {
- add_filter( 'manage_' . $post_type . '_posts_columns', array( $this, 'add_posts_management_column' ) );
- if ( $wp_post_types[ $post_type ]->hierarchical ) {
- add_action( 'manage_pages_custom_column', array( $this, 'add_content_for_posts_management_column' ) );
- add_action( 'manage_posts_custom_column', array( $this, 'add_content_for_posts_management_column' ) ); // add this too - for more types plugin
- } else {
- add_action( 'manage_posts_custom_column', array( $this, 'add_content_for_posts_management_column' ) );
- }
- }
- }
- add_action( 'admin_print_scripts', array( $this, '__set_posts_management_column_width' ) );
- }
- }
-
- function _taxonomy_languages_menu()
- {
- // tags language selection
- global $pagenow;
- if ( $pagenow == 'edit-tags.php' ) {
- // handle case of the tax edit page (after a taxonomy has been added)
- // needs to redirect back to
- if ( isset( $_GET[ 'trid' ] ) && isset( $_GET[ 'source_lang' ] ) ) {
- $translations = $this->get_element_translations( $_GET[ 'trid' ], 'tax_' . $_GET[ 'taxonomy' ] );
- if ( isset( $translations[ $_GET[ 'lang' ] ] ) ) {
- wp_redirect( get_edit_term_link( $translations[ $_…
Large files files are truncated, but you can click here to view the full file