PageRenderTime 79ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 4ms

/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php

https://bitbucket.org/acipriani/madeinapulia.com
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

  1. <?php
  2. /**
  3. * Main SitePress Class
  4. *
  5. * @package wpml-core
  6. */
  7. class SitePress
  8. {
  9. private $settings;
  10. private $active_languages = array();
  11. private $this_lang;
  12. private $wp_query;
  13. private $admin_language = null;
  14. private $user_preferences = array();
  15. private $current_user;
  16. public $footer_preview = false;
  17. public $queries = array();
  18. /**
  19. * @var icl_cache
  20. */
  21. public $icl_translations_cache;
  22. /**
  23. * @var icl_cache
  24. */
  25. public $icl_locale_cache;
  26. /**
  27. * @var icl_cache
  28. */
  29. public $icl_flag_cache;
  30. /**
  31. * @var icl_cache
  32. */
  33. public $icl_language_name_cache;
  34. /**
  35. * @var icl_cache
  36. */
  37. public $icl_term_taxonomy_cache;
  38. function __construct()
  39. {
  40. do_action('wpml_before_startup');
  41. global $wpdb, $pagenow;
  42. $this->settings = get_option( 'icl_sitepress_settings' );
  43. //@tODO: To remove in WPML 3.5
  44. //@since 3.1
  45. if(is_admin() && !$this->get_setting('icl_capabilities_verified')) {
  46. icl_enable_capabilities();
  47. $this->settings = get_option( 'icl_sitepress_settings' );
  48. }
  49. // set up current user early
  50. // no authentication
  51. if ( defined( 'LOGGED_IN_COOKIE' ) && isset( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
  52. list( $username ) = explode( '|', $_COOKIE[ LOGGED_IN_COOKIE ] );
  53. $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->users} WHERE user_login = %s", array($username) ) );
  54. } else {
  55. $user_id = 0;
  56. }
  57. $this->current_user = new WP_User( $user_id );
  58. if ( is_null( $pagenow ) && is_multisite() ) {
  59. include ICL_PLUGIN_PATH . '/inc/hacks/vars-php-multisite.php';
  60. }
  61. if ( false != $this->settings ) {
  62. $this->verify_settings();
  63. }
  64. if ( isset( $_GET[ 'icl_action' ] ) ) {
  65. require_once ABSPATH . WPINC . '/pluggable.php';
  66. if ( $_GET[ 'icl_action' ] == 'reminder_popup' ) {
  67. add_action( 'init', array( $this, 'reminders_popup' ) );
  68. } elseif ( $_GET[ 'icl_action' ] == 'dismiss_help' ) {
  69. $this->settings[ 'dont_show_help_admin_notice' ] = true;
  70. $this->save_settings();
  71. }
  72. }
  73. if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == ICL_PLUGIN_FOLDER . '/menu/troubleshooting.php' && isset( $_GET[ 'debug_action' ] ) ) {
  74. ob_start();
  75. }
  76. if ( isset( $_REQUEST[ 'icl_ajx_action' ] ) ) {
  77. add_action( 'init', array( $this, 'ajax_setup' ), 15 );
  78. }
  79. add_action( 'admin_footer', array( $this, 'icl_nonces' ) );
  80. // Process post requests
  81. if ( !empty( $_POST ) ) {
  82. add_action( 'init', array( $this, 'process_forms' ) );
  83. }
  84. add_action( 'plugins_loaded', array( $this, 'initialize_cache' ), 0 );
  85. add_action( 'plugins_loaded', array( $this, 'init' ), 1 );
  86. add_action( 'init', array( $this, 'on_wp_init' ), 1 );
  87. add_action( 'admin_print_scripts', array( $this, 'js_scripts_setup' ) );
  88. add_action( 'admin_print_styles', array( $this, 'css_setup' ) );
  89. // Administration menus
  90. add_action( 'admin_menu', array( $this, 'administration_menu' ) );
  91. add_action( 'admin_menu', array( $this, 'administration_menu2' ), 30 );
  92. add_action( 'init', array( $this, 'plugin_localization' ) );
  93. //add_filter('tag_template', array($this, 'load_taxonomy_template'));
  94. 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' ) ) ) {
  95. // Post/page language box
  96. if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' || $pagenow == 'edit.php' ) {
  97. add_action( 'admin_head', array( $this, 'post_edit_language_options' ) );
  98. }
  99. //For when it will be possible to add custom bulk actions
  100. //add_action( 'bulk_actions-edit-post', array( $this, 'bulk_actions' ) );
  101. // Post/page save actions
  102. add_action( 'save_post', array( $this, 'save_post_actions' ), 100, 2 );
  103. add_action( 'updated_post_meta', array( $this, 'update_post_meta' ), 100, 4 );
  104. add_action( 'added_post_meta', array( $this, 'update_post_meta' ), 100, 4 );
  105. add_action( 'updated_postmeta', array( $this, 'update_post_meta' ), 100, 4 ); // ajax
  106. add_action( 'added_postmeta', array( $this, 'update_post_meta' ), 100, 4 ); // ajax
  107. add_action( 'delete_postmeta', array( $this, 'delete_post_meta' ) ); // ajax
  108. // Post/page delete actions
  109. // add_action('delete_post', array($this,'delete_post_actions'));
  110. add_action( 'before_delete_post', array( $this, 'before_delete_post_actions' ) );
  111. add_action( 'deleted_post', array( $this, 'deleted_post_actions' ) );
  112. add_action( 'wp_trash_post', array( $this, 'trash_post_actions' ) );
  113. add_action( 'untrashed_post', array( $this, 'untrashed_post_actions' ) );
  114. add_filter( 'posts_join', array( $this, 'posts_join_filter' ), 10, 2 );
  115. add_filter( 'posts_where', array( $this, 'posts_where_filter' ), 10, 2 );
  116. add_filter( 'comment_feed_join', array( $this, 'comment_feed_join' ) );
  117. add_filter( 'comments_clauses', array( $this, 'comments_clauses' ), 10, 2 );
  118. // Allow us to filter the Query vars before the posts query is being built and executed
  119. add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
  120. add_action( 'loop_start', array( $this, 'loop_start' ), 10 );
  121. add_filter( 'the_posts', array( $this, 'the_posts' ), 10 );
  122. add_filter( 'get_pages', array( $this, 'get_pages' ), 100, 2 );
  123. // Filter links to the root page
  124. add_filter('page_link', array($this, 'filter_root_permalink'), 10, 2);
  125. if ( $pagenow == 'edit.php' ) {
  126. add_action( 'admin_footer', array( $this, 'language_filter' ) );
  127. add_action( 'quick_edit_custom_box', array( 'WPML_Terms_Translations', 'quick_edit_terms_removal' ), 10, 2 );
  128. }
  129. add_filter( 'get_pages', array( $this, 'exclude_other_language_pages2' ) );
  130. add_filter( 'wp_dropdown_pages', array( $this, 'wp_dropdown_pages' ) );
  131. // posts and pages links filters
  132. add_filter( 'post_link', array( $this, 'permalink_filter' ), 1, 2 );
  133. add_filter( 'post_type_link', array( $this, 'permalink_filter' ), 1, 2 );
  134. add_filter( 'page_link', array( $this, 'permalink_filter' ), 1, 2 );
  135. add_filter( 'get_comment_link', array( $this, 'get_comment_link_filter' ) );
  136. // filter the saving of terms so that the taxonomy_ids of translated terms are correctly adjusted across taxonomies
  137. add_action('created_term_translation', array( 'WPML_Terms_Translations', 'sync_ttid_action' ), 10, 3 );
  138. // filters terms by language for the term/tag-box autoselect
  139. if ( ( isset( $_GET[ 'action' ] ) && ( $_GET[ 'action' ] == 'ajax-tag-search' )
  140. || isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'get-tagcloud' ) ) {
  141. add_filter( 'get_terms', array( 'WPML_Terms_Translations', 'get_terms_filter' ), 10, 2 );
  142. }
  143. $this->set_term_filters_and_hooks();
  144. // The delete filter only ensures the synchronizing of delete actions beween translations of a term.
  145. add_action( 'delete_term', array( 'WPML_Terms_Translations', 'delete_term_filter' ), 1, 3 );
  146. add_filter('pre_term_slug', array( 'WPML_Terms_Translations', 'pre_term_slug_filter' ), 10, 2 );
  147. add_action( 'set_object_terms', array( 'WPML_Terms_Translations', 'set_object_terms_action' ), 10, 6 );
  148. // AJAX Actions for the post edit screen
  149. add_action( 'wp_ajax_wpml_get_post_parent_id_by_lang', array( 'WPML_Post_Edit_Ajax', 'wpml_get_post_parent_id_by_lang' ) );
  150. add_action( 'wp_ajax_wpml_get_taxonomy_terms_json', array( 'WPML_Post_Edit_Ajax', 'wpml_get_taxonomy_terms_json' ) );
  151. add_action( 'wp_ajax_wpml_add_term_to_post', array( 'WPML_Post_Edit_Ajax', 'wpml_add_term_to_post' ) );
  152. add_action( 'wp_ajax_wpml_remove_terms_from_post', array( 'WPML_Post_Edit_Ajax', 'wpml_remove_terms_from_post' ) );
  153. add_action( 'wp_ajax_wpml_switch_post_language', array( 'WPML_Post_Edit_Ajax', 'wpml_switch_post_language' ) );
  154. add_action( 'wp_ajax_wpml_before_switch_post_language', array( 'WPML_Post_Edit_Ajax', 'wpml_before_switch_post_language' ) );
  155. add_action( 'wp_ajax_wpml_set_post_edit_lang', array( 'WPML_Post_Edit_Ajax', 'wpml_set_post_edit_lang' ) );
  156. add_action( 'wp_ajax_wpml_get_translated_taxonomies', array( 'WPML_Post_Edit_Ajax', 'wpml_get_translated_taxonomies' ) );
  157. add_action( 'wp_ajax_wpml_get_translations_table_data', array( 'WPML_Post_Edit_Ajax', 'wpml_get_translations_table_data' ) );
  158. add_action( 'wp_ajax_wpml_get_post_permalink', array( 'WPML_Post_Edit_Ajax', 'wpml_get_post_permalink' ) );
  159. add_action( 'wp_ajax_wpml_get_default_lang', array( 'WPML_Post_Edit_Ajax', 'wpml_get_default_lang' ) );
  160. // Ajax Action for the updating of term names on the troubleshooting page
  161. add_action( 'wp_ajax_wpml_update_term_names_troubleshoot', array( 'WPML_Troubleshooting_Terms_Menu', 'wpml_update_term_names_troubleshoot' ) );
  162. // short circuit get default category
  163. add_filter( 'pre_option_default_category', array( $this, 'pre_option_default_category' ) );
  164. add_filter( 'update_option_default_category', array( $this, 'update_option_default_category' ), 1, 2 );
  165. add_action( 'after-category-table', array( 'WPML_Terms_Translations', 'category_display_action' ), 1, 1 );
  166. // custom hook for adding the language selector to the template
  167. add_action( 'icl_language_selector', array( $this, 'language_selector' ) );
  168. // front end js
  169. add_action( 'wp_head', array( $this, 'front_end_js' ) );
  170. add_action( 'wp_head', array( $this, 'rtl_fix' ) );
  171. add_action( 'admin_print_styles', array( $this, 'rtl_fix' ) );
  172. add_action( 'restrict_manage_posts', array( $this, 'restrict_manage_posts' ) );
  173. add_filter( 'get_edit_post_link', array( $this, 'get_edit_post_link' ), 1, 3 );
  174. // adjacent posts links
  175. add_filter( 'get_previous_post_join', array( $this, 'get_adjacent_post_join' ) );
  176. add_filter( 'get_next_post_join', array( $this, 'get_adjacent_post_join' ) );
  177. add_filter( 'get_previous_post_where', array( $this, 'get_adjacent_post_where' ) );
  178. add_filter( 'get_next_post_where', array( $this, 'get_adjacent_post_where' ) );
  179. // feeds links
  180. add_filter( 'feed_link', array( $this, 'feed_link' ) );
  181. // commenting links
  182. add_filter( 'post_comments_feed_link', array( $this, 'post_comments_feed_link' ) );
  183. add_filter( 'trackback_url', array( $this, 'trackback_url' ) );
  184. add_filter( 'user_trailingslashit', array( $this, 'user_trailingslashit' ), 1, 2 );
  185. // date based archives
  186. add_filter( 'year_link', array( $this, 'archives_link' ) );
  187. add_filter( 'month_link', array( $this, 'archives_link' ) );
  188. add_filter( 'day_link', array( $this, 'archives_link' ) );
  189. add_filter( 'getarchives_join', array( $this, 'getarchives_join' ) );
  190. add_filter( 'getarchives_where', array( $this, 'getarchives_where' ) );
  191. add_filter( 'pre_option_home', array( $this, 'pre_option_home' ) );
  192. if ( !is_admin() ) {
  193. add_filter( 'attachment_link', array( $this, 'attachment_link_filter' ), 10, 2 );
  194. }
  195. // Filter custom type archive link (since WP 3.1)
  196. add_filter( 'post_type_archive_link', array( $this, 'post_type_archive_link_filter' ), 10, 2 );
  197. add_filter( 'author_link', array( $this, 'author_link' ) );
  198. add_filter( 'wp_unique_post_slug', array( $this, 'wp_unique_post_slug' ), 100, 5 );
  199. add_filter( 'home_url', array( $this, 'home_url' ), 1, 4 );
  200. // language negotiation
  201. add_action( 'query_vars', array( $this, 'query_vars' ) );
  202. add_filter( 'language_attributes', array( $this, 'language_attributes' ) );
  203. add_action( 'locale', array( $this, 'locale' ) );
  204. if ( isset( $_GET[ '____icl_validate_domain' ] ) ) {
  205. echo '<!--' . get_home_url() . '-->';
  206. exit;
  207. }
  208. add_filter( 'pre_option_page_on_front', array( $this, 'pre_option_page_on_front' ) );
  209. add_filter( 'pre_option_page_for_posts', array( $this, 'pre_option_page_for_posts' ) );
  210. add_filter( 'option_sticky_posts', array( $this, 'option_sticky_posts' ) );
  211. add_filter( 'request', array( $this, 'request_filter' ) );
  212. add_action( 'wp_head', array( $this, 'set_wp_query' ) );
  213. add_action( 'show_user_profile', array( $this, 'show_user_options' ) );
  214. add_action( 'personal_options_update', array( $this, 'save_user_options' ) );
  215. // column with links to translations (or add translation) - low priority
  216. add_action( 'init', array( $this, 'configure_custom_column' ), 1010 ); // accommodate Types init@999
  217. if ( !is_admin() ) {
  218. add_action( 'wp_head', array( $this, 'meta_generator_tag' ) );
  219. }
  220. require_once ICL_PLUGIN_PATH . '/inc/wp-nav-menus/iclNavMenu.class.php';
  221. new iclNavMenu;
  222. if ( is_admin() || defined( 'XMLRPC_REQUEST' ) || preg_match( '#wp-comments-post\.php$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
  223. global $iclTranslationManagement, $ICL_Pro_Translation;
  224. $iclTranslationManagement = new TranslationManagement;
  225. $ICL_Pro_Translation = new ICL_Pro_Translation();
  226. }
  227. add_action( 'wp_login', array( $this, 'reset_admin_language_cookie' ) );
  228. if ( $this->settings[ 'seo' ][ 'canonicalization_duplicates' ] ) {
  229. add_action( 'template_redirect', array( $this, 'setup_canonical_urls' ), 100 );
  230. }
  231. add_action( 'init', array( $this, '_taxonomy_languages_menu' ), 99 ); //allow hooking in
  232. if ( $this->settings[ 'seo' ][ 'head_langs' ] ) {
  233. add_action( 'wp_head', array( $this, 'head_langs' ) );
  234. }
  235. /**
  236. * add extra debug information
  237. */
  238. add_filter( 'icl_get_extra_debug_info', array( $this, 'add_extra_debug_info' ) );
  239. } //end if the initial language is set - existing_content_language_verified
  240. add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget_setup' ) );
  241. if ( is_admin() && $pagenow == 'index.php' ) {
  242. add_action( 'icl_dashboard_widget_notices', array( $this, 'print_translatable_custom_content_status' ) );
  243. }
  244. add_filter( 'core_version_check_locale', array( $this, 'wp_upgrade_locale' ) );
  245. if ( $pagenow == 'post.php' && isset( $_REQUEST[ 'action' ] ) && $_REQUEST[ 'action' ] == 'edit' && isset( $_GET[ 'post' ] ) ) {
  246. add_action( 'init', '_icl_trash_restore_prompt' );
  247. }
  248. add_action( 'init', array( $this, 'js_load' ), 2 ); // enqueue scripts - higher priority
  249. add_filter( 'get_pagenum_link', array( $this, 'get_pagenum_link' ) );
  250. add_action('switch_blog', array($this, 'init_settings'));
  251. add_filter('url_to_postid', array($this, 'url_to_postid'));
  252. //cron job to update WPML config index file from CDN
  253. add_action('update_wpml_config_index', array($this,'update_wpml_config_index_event'));
  254. //update WPML config files
  255. add_action('wp_ajax_update_wpml_config_index', array($this,'update_wpml_config_index_event_ajax'));
  256. add_action( 'after_switch_theme', array( $this, 'update_wpml_config_index_event' ) );
  257. add_action( 'activated_plugin', array( $this, 'update_wpml_config_index_event' ) );
  258. add_action('core_upgrade_preamble', array($this, 'update_index_screen'));
  259. add_shortcode('wpml_language_selector_widget', 'icl_language_selector');
  260. add_shortcode('wpml_language_selector_footer', 'icl_language_selector_footer');
  261. add_filter('get_search_form', array($this, 'get_search_form_filter'));
  262. add_action('plugins_loaded', array($this, 'load_dependencies'), 10000);
  263. do_action('wpml_after_startup');
  264. }
  265. function get_pagenum_link( $url ) {
  266. // fix cases like that in url:
  267. // lang=pl%2F%3Flang%3Dpl
  268. // lang=pl/?lang=pl
  269. $current_language = $this->get_current_language();
  270. $find[ ] = 'lang=' . $current_language . '%2F%3Flang%3D' . $current_language;
  271. $find[ ] = 'lang=' . $current_language . '/?lang=' . $current_language;
  272. $replace = 'lang=' . $current_language;
  273. $url = str_replace( $find, $replace, $url );
  274. // fix cases like that:
  275. // ?lang=pl/page/3/?lang=pl
  276. $pattern = '/(\?lang=' . $current_language . ')(\/page\/\d+)/';
  277. $url = preg_replace( $pattern, '$2', $url );
  278. return $url;
  279. }
  280. function init()
  281. {
  282. do_action('wpml_before_init');
  283. global $wpdb;
  284. $this->get_user_preferences();
  285. $this->set_admin_language();
  286. $default_language = $this->get_default_language();
  287. // default value for theme_localization_type OR
  288. // reset theme_localization_type if string translation was on (theme_localization_type was set to 2) and then it was deactivated
  289. if ( !isset( $this->settings[ 'theme_localization_type' ] ) || ( $this->settings[ 'theme_localization_type' ] == 1 && !defined( 'WPML_ST_VERSION' ) && !defined( 'WPML_DOING_UPGRADE' ) ) ) {
  290. global $sitepress_settings;
  291. $this->settings[ 'theme_localization_type' ] = $sitepress_settings[ 'theme_localization_type' ] = 2;
  292. }
  293. //configure callbacks for plugin menu pages
  294. if ( defined( 'WP_ADMIN' ) && isset( $_GET[ 'page' ] ) && 0 === strpos( $_GET[ 'page' ], basename( ICL_PLUGIN_PATH ) . '/' ) ) {
  295. add_action( 'icl_menu_footer', array( $this, 'menu_footer' ) );
  296. }
  297. //Run only if existing content language has been verified, and is front-end or settings are not corrupted
  298. if (!empty( $this->settings[ 'existing_content_language_verified' ] ) && (!is_admin() || SitePress::check_settings_integrity()) ) {
  299. if ( $this->settings[ 'language_negotiation_type' ] == 1 && $this->settings[ 'urls' ][ 'directory_for_default_language' ] && $this->settings[ 'urls' ][ 'show_on_root' ] == 'page' ) {
  300. include ICL_PLUGIN_PATH . '/inc/home-url-functions.php';
  301. }
  302. if ($this->settings[ 'language_negotiation_type' ] == 2) {
  303. add_filter( 'allowed_redirect_hosts', array( $this, 'allowed_redirect_hosts' ) );
  304. }
  305. if ( defined( 'WP_ADMIN' ) ) {
  306. if ( $this->settings[ 'language_negotiation_type' ] == 2 ) {
  307. //Login and Logout
  308. add_filter( 'login_url', array( $this, 'convert_url' ) );
  309. add_filter( 'logout_url', array( $this, 'convert_url' ) );
  310. add_filter( 'site_url', array( $this, 'convert_url' ) );
  311. }
  312. if (isset($_GET['post']) && is_numeric($_GET['post'])) {
  313. $post_type = get_post_type($_GET['post']);
  314. }
  315. $current_user = wp_get_current_user();
  316. if ( isset( $_GET[ 'lang' ] ) ) {
  317. $this->this_lang = rtrim( strip_tags( $_GET[ 'lang' ] ), '/' );
  318. $al = $this->get_active_languages();
  319. $al[ 'all' ] = true;
  320. if ( empty( $al[ $this->this_lang ] ) ) {
  321. $this->this_lang = $default_language;
  322. }
  323. // force default language for string translation
  324. // we also make sure it's not saved in the cookie
  325. } 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' ) )
  326. ) {
  327. $this->this_lang = $default_language;
  328. } elseif ( wpml_is_ajax() ) {
  329. $al = $this->get_active_languages();
  330. if ( isset( $_POST[ 'lang' ] ) && isset( $al[ $_POST[ 'lang' ] ] ) ) {
  331. $this->this_lang = $_POST[ 'lang' ];
  332. } else {
  333. if ($this->check_if_admin_action_from_referer()){
  334. $this->this_lang = $this->get_admin_language_cookie();
  335. } elseif(isset($_SERVER['HTTP_REFERER'])) {
  336. $this->this_lang = $this->get_language_from_url($_SERVER['HTTP_REFERER']);
  337. }
  338. }
  339. } elseif ( $lang = $this->get_admin_language_cookie() ) {
  340. $this->this_lang = $lang;
  341. } elseif ( isset($_POST['action']) && $_POST['action'] == 'editpost' && isset($_POST['icl_post_language'])) {
  342. $this->this_lang = $_POST['icl_post_language'];
  343. } elseif ( isset($_GET['post']) && is_numeric($_GET['post']) && isset($post_type) && $this->is_translated_post_type($post_type)) {
  344. $this->this_lang = $this->get_language_for_element($_GET['post'], 'post_' . $post_type);
  345. } elseif(isset($current_user->data)) {
  346. $lang = $this->get_user_admin_language( $current_user->data->ID );
  347. $this->this_lang = $lang ? $lang : $default_language;
  348. }
  349. $update_admin_language_cookie = false;
  350. $update_admin_language_cookie |= is_admin() && isset($_GET['lang']) && ( $this->get_current_language() != $this->get_admin_language_cookie() );
  351. $update_admin_language_cookie |= isset( $_GET[ 'admin_bar' ] ) && ( $_GET[ 'admin_bar' ] == 1 ) && !isset( $_GET[ 'page' ] );
  352. $update_admin_language_cookie |= !defined( 'WPML_ST_FOLDER' ) || ( isset($_GET[ 'page' ]) && $_GET[ 'page' ] != WPML_ST_FOLDER . '/menu/string-translation.php' );
  353. $update_admin_language_cookie |= !$this->get_admin_language_cookie();
  354. if ( $update_admin_language_cookie ) {
  355. $this->set_admin_language_cookie();
  356. }
  357. } else {
  358. $al = $this->get_active_languages();
  359. foreach ( $al as $l ) {
  360. $active_languages[ ] = $l[ 'code' ];
  361. }
  362. $active_languages[ ] = 'all';
  363. $s = isset( $_SERVER[ 'HTTPS' ] ) && $_SERVER[ 'HTTPS' ] == 'on' ? 's' : '';
  364. $home = get_home_url();
  365. if ( $s ) {
  366. $home = preg_replace( '#^http://#', 'https://', $home );
  367. }
  368. $url_parts = parse_url( $home );
  369. $non_default_port = ( isset( $url_parts[ 'port' ] ) && $url_parts[ 'port' ] != 80 ) ? ':' . $url_parts[ 'port' ] : '';
  370. $request = 'http' . $s . '://' . $this->get_server_host_name() . $_SERVER[ 'REQUEST_URI' ];
  371. $blog_path = ! empty( $url_parts[ 'path' ] ) ? $url_parts[ 'path' ] : '';
  372. switch ( $this->settings[ 'language_negotiation_type' ] ) {
  373. case 1:
  374. $path = str_replace( $home, '', $request );
  375. $parts = explode( '?', $path );
  376. $path = $parts[ 0 ];
  377. $exp = explode( '/', trim( $path, '/' ) );
  378. $language_part = $exp[ 0 ];
  379. if ( in_array( $language_part, $active_languages ) ) {
  380. $this->this_lang = $exp[ 0 ];
  381. // before hijacking the SERVER[REQUEST_URI]
  382. // override the canonical_redirect action
  383. // keep a copy of the original request uri
  384. remove_action( 'template_redirect', 'redirect_canonical' );
  385. global $_icl_server_request_uri;
  386. $_icl_server_request_uri = $_SERVER[ 'REQUEST_URI' ];
  387. add_action( 'template_redirect', array($this,'icl_redirect_canonical_wrapper'), 0 );
  388. //deal with situations when template files need to be called directly
  389. add_action( 'template_redirect', array( $this, '_allow_calling_template_file_directly' ) );
  390. //$_SERVER['REQUEST_URI'] = preg_replace('@^'. $blog_path . '/' . $this->this_lang.'@i', $blog_path ,$_SERVER['REQUEST_URI']);
  391. // Check for special case of www.example.com/fr where the / is missing on the end
  392. $parts = parse_url( $_SERVER[ 'REQUEST_URI' ] );
  393. if ( strlen( $parts[ 'path' ] ) == 0 ) {
  394. $_SERVER[ 'REQUEST_URI' ] = '/' . $_SERVER[ 'REQUEST_URI' ];
  395. }
  396. } else {
  397. $this->this_lang = $default_language;
  398. }
  399. /* If we access the root url via a non root slug/parameter combination,
  400. * we redirect accordingly.
  401. */
  402. if ( $this->settings[ 'language_negotiation_type' ] == 1 && $this->settings[ 'urls' ][ 'directory_for_default_language' ] && $this->settings[ 'urls' ][ 'show_on_root' ] == 'page' ) {
  403. $filtered_root_url = $this->filter_root_permalink( wpml_strip_subdir_from_url( site_url() ) . $_SERVER[ 'REQUEST_URI' ] );
  404. if ( $filtered_root_url != wpml_strip_subdir_from_url( site_url() ) . $_SERVER[ 'REQUEST_URI' ] ) {
  405. wp_redirect( $filtered_root_url, 302 );
  406. exit();
  407. }
  408. }
  409. if ( $this->is_root_page() ) {
  410. if ( $this->settings[ 'urls' ][ 'show_on_root' ] == 'html_file' ) {
  411. // html file
  412. if ( false === strpos( $this->settings[ 'urls' ][ 'root_html_file_path' ], '/' ) ) {
  413. $html_file = ABSPATH . $this->settings[ 'urls' ][ 'root_html_file_path' ];
  414. } else {
  415. $html_file = $this->settings[ 'urls' ][ 'root_html_file_path' ];
  416. }
  417. /** @noinspection PhpIncludeInspection */
  418. include $html_file;
  419. exit;
  420. } else {
  421. wpml_home_url_setup_root_page();
  422. }
  423. }
  424. break;
  425. case 2:
  426. $this->this_lang = $default_language;
  427. foreach( $this->settings[ 'language_domains' ] as $language_code => $domain ){
  428. if( rtrim( $this->get_server_host_name() . $blog_path, '/' ) == rtrim( preg_replace( '@^https?://@', '', $domain ), '/' ) ){
  429. $this->this_lang = $language_code;
  430. break;
  431. }
  432. }
  433. if ( defined( 'ICL_USE_MULTIPLE_DOMAIN_LOGIN' ) && ICL_USE_MULTIPLE_DOMAIN_LOGIN ) {
  434. include ICL_PLUGIN_PATH . '/modules/multiple-domains-login.php';
  435. }
  436. add_filter( 'site_url', array( $this, 'convert_url' ) );
  437. break;
  438. case 3:
  439. default:
  440. if ( isset( $_GET[ 'lang' ] ) ) {
  441. $this->this_lang = preg_replace( "/[^0-9a-zA-Z-]/i", '', strip_tags( $_GET[ 'lang' ] ) );
  442. // set the language based on the content id - for short links
  443. } elseif ( isset( $_GET[ 'page_id' ] ) ) {
  444. $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' ] );
  445. $this->this_lang = $wpdb->get_var( $language_code_prepared );
  446. } elseif ( isset( $_GET[ 'p' ] ) ) {
  447. $post_type_prepared = $wpdb->prepare( "SELECT post_type FROM {$wpdb->posts} WHERE ID=%d", $_GET[ 'p' ] );
  448. $post_type = $wpdb->get_var( $post_type_prepared );
  449. $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' ] );
  450. $this->this_lang = $wpdb->get_var( $language_code_prepared );
  451. } elseif ( isset( $_GET[ 'cat_ID' ] ) ) {
  452. $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' );
  453. $cat_tax_id = $wpdb->get_var( $cat_tax_id_prepared );
  454. $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 );
  455. $this->this_lang = $wpdb->get_var( $language_code_prepared );
  456. } elseif ( isset( $_GET[ 'tag' ] ) ) {
  457. $tag_tax_id_prepared = $wpdb->prepare( "
  458. SELECT x.term_taxonomy_id FROM {$wpdb->term_taxonomy} x JOIN {$wpdb->terms} t ON t.term_id = x.term_id
  459. WHERE t.slug=%s AND x.taxonomy='post_tag'", $_GET[ 'tag' ] );
  460. $tag_tax_id = $wpdb->get_var( $tag_tax_id_prepared );
  461. $language_code_prepared = $wpdb->prepare( "SELECT language_code FROM {$wpdb->prefix}icl_translations
  462. WHERE element_type='tax_post_tag' AND element_id=%d", $tag_tax_id );
  463. $this->this_lang = $wpdb->get_var( $language_code_prepared );
  464. }
  465. //
  466. if ( !isset( $_GET[ 'lang' ] ) && ( $this->this_lang && $this->this_lang != $default_language ) ) {
  467. if ( !isset( $GLOBALS[ 'wp_rewrite' ] ) ) {
  468. require_once ABSPATH . WPINC . '/rewrite.php';
  469. $GLOBALS[ 'wp_rewrite' ] = new WP_Rewrite();
  470. }
  471. define( 'ICL_DOING_REDIRECT', true );
  472. if ( isset( $_GET[ 'page_id' ] ) ) {
  473. wp_redirect( get_page_link( $_GET[ 'page_id' ] ), '301' );
  474. exit;
  475. } elseif ( isset( $_GET[ 'p' ] ) ) {
  476. wp_redirect( get_permalink( $_GET[ 'p' ] ), '301' );
  477. exit;
  478. } elseif ( isset( $_GET[ 'cat_ID' ] ) ) {
  479. wp_redirect( get_term_link( intval( $_GET[ 'cat_ID' ] ), 'category' ) );
  480. exit;
  481. } elseif ( isset( $_GET[ 'tag' ] ) ) {
  482. wp_redirect( get_term_link( $_GET[ 'tag' ], 'post_tag' ) );
  483. exit;
  484. } else {
  485. if ( isset( $this->settings[ 'taxonomies_sync_option' ] ) ) {
  486. $taxs = array_keys( (array)$this->settings[ 'taxonomies_sync_option' ] );
  487. foreach ( $taxs as $t ) {
  488. if ( isset( $_GET[ $t ] ) ) {
  489. $term_obj = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON t.term_id = x.term_id
  490. WHERE t.slug=%s AND x.taxonomy=%s", $_GET[ $t ], $t ) );
  491. $term_link = get_term_link( $term_obj, $t );
  492. $term_link = str_replace( '&amp;', '&', $term_link ); // fix
  493. if ( $term_link && !is_wp_error( $term_link ) ) {
  494. wp_redirect( $term_link );
  495. exit;
  496. }
  497. }
  498. }
  499. }
  500. }
  501. }
  502. if ( empty( $this->this_lang ) ) {
  503. $this->this_lang = $default_language;
  504. }
  505. }
  506. // allow forcing the current language when it can't be decoded from the URL
  507. $this->this_lang = apply_filters( 'icl_set_current_language', $this->this_lang );
  508. }
  509. //reorder active language to put 'this_lang' in front
  510. foreach ( $this->active_languages as $k => $al ) {
  511. if ( $al[ 'code' ] == $this->this_lang ) {
  512. unset( $this->active_languages[ $k ] );
  513. $this->active_languages = array_merge( array( $k => $al ), $this->active_languages );
  514. }
  515. }
  516. WPML_Troubleshooting_Terms_Menu::display_terms_with_suffix_admin_notice();
  517. // filter some queries
  518. add_filter( 'query', array( $this, 'filter_queries' ) );
  519. add_filter( 'option_rewrite_rules', array( $this, 'rewrite_rules_filter' ) );
  520. $this->set_language_cookie();
  521. 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' )
  522. ) {
  523. if ( version_compare( $GLOBALS[ 'wp_version' ], '3.3', '<' ) ) {
  524. // Legacy code for admin language switcher
  525. if ( !$this->is_rtl() && version_compare( $GLOBALS[ 'wp_version' ], '3.3', '>' ) ) {
  526. add_action( 'admin_notices', 'wpml_set_admin_language_switcher_place', 100 );
  527. add_action( 'network_admin_notices', 'wpml_set_admin_language_switcher_place', 100 );
  528. add_action( 'user_admin_notices', 'wpml_set_admin_language_switcher_place', 100 );
  529. function wpml_set_admin_language_switcher_place()
  530. {
  531. echo '<br clear="all" />';
  532. }
  533. }
  534. add_action( 'in_admin_header', array( $this, 'admin_language_switcher_legacy' ) );
  535. } else {
  536. // Admin language switcher goes to the WP admin bar
  537. add_action( 'wp_before_admin_bar_render', array( $this, 'admin_language_switcher' ) );
  538. }
  539. }
  540. if ( !is_admin() && defined( 'DISQUS_VERSION' ) ) {
  541. include ICL_PLUGIN_PATH . '/modules/disqus.php';
  542. }
  543. }
  544. /*
  545. * If user perform bulk taxonomy deletion when displaying non-default
  546. * language taxonomies, after deletion should stay with same language
  547. */
  548. if ( is_admin() &&
  549. isset($_POST['_wp_http_referer'])
  550. && false !== strpos($_POST['_wp_http_referer'], 'edit-tags.php')
  551. && !empty($_POST['delete_tags'])
  552. && is_array($_POST['delete_tags'])
  553. && !empty($_GET['lang'])
  554. && (
  555. $_POST['action'] == 'delete' || $_POST['action2'] == 'delete'
  556. ) ) {
  557. add_filter('wp_redirect', array($this, 'preserve_lang_param_after_bulk_category_delete'));
  558. }
  559. if ( $this->is_rtl() ) {
  560. $GLOBALS[ 'text_direction' ] = 'rtl';
  561. }
  562. if (!wpml_is_ajax() && is_admin() && empty( $this->settings[ 'dont_show_help_admin_notice' ] ) ) {
  563. if ( !$this->get_setting('setup_wizard_step') ) {
  564. if(SitePress::check_settings_integrity()) {
  565. add_action( 'admin_notices', array( $this, 'help_admin_notice' ) );
  566. }
  567. }
  568. }
  569. $short_v = implode( '.', array_slice( explode( '.', ICL_SITEPRESS_VERSION ), 0, 3 ) );
  570. if ( is_admin() && ( !isset( $this->settings[ 'hide_upgrade_notice' ] ) || $this->settings[ 'hide_upgrade_notice' ] != $short_v ) ) {
  571. add_action( 'admin_notices', array( $this, 'upgrade_notice' ) );
  572. }
  573. require ICL_PLUGIN_PATH . '/inc/template-constants.php';
  574. if ( defined( 'WPML_LOAD_API_SUPPORT' ) ) {
  575. require ICL_PLUGIN_PATH . '/inc/wpml-api.php';
  576. }
  577. add_action( 'wp_footer', array( $this, 'display_wpml_footer' ), 20 );
  578. if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
  579. add_action( 'xmlrpc_call', array( $this, 'xmlrpc_call_actions' ) );
  580. add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) );
  581. }
  582. if ( defined( 'WPML_TM_VERSION' ) && is_admin() ) {
  583. require ICL_PLUGIN_PATH . '/inc/quote.php';
  584. }
  585. add_action( 'init', array( $this, 'set_up_language_selector' ) );
  586. global $pagenow;
  587. if ( $pagenow == 'admin-ajax.php' ) {
  588. if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'wpml_tt_show_terms') {
  589. $default_language = $this->get_default_language();
  590. //@todo: remove the following live after WPML 3.5 release
  591. //$this->switch_lang($default_language, true);
  592. }
  593. }
  594. // set language to default and remove language switcher when in Taxonomy Translation page
  595. // If the page uses AJAX and the language must be forced to default, please use the
  596. // if ( $pagenow == 'admin-ajax.php' )above
  597. if ( is_admin() && isset( $_GET[ 'page' ] ) && ( $_GET[ 'page' ] == ICL_PLUGIN_FOLDER . '/menu/taxonomy-translation.php' || $_GET[ 'page' ] == ICL_PLUGIN_FOLDER . '/menu/menus-sync.php' ) ) {
  598. $default_language = $this->get_admin_language();
  599. $this->switch_lang($default_language, true);
  600. add_action( 'init', array( $this, 'remove_admin_language_switcher'));
  601. }
  602. /* Posts and new inline created terms, can only be saved in an active language.
  603. * Also the content of the post-new.php should always be filtered for one specific
  604. * active language, so to display the correct taxonomy terms for selection.
  605. */
  606. if ( $pagenow == 'post-new.php' ) {
  607. if ( ! $this->is_active_language( $this->get_current_language() ) ) {
  608. $default_language = $this->get_admin_language();
  609. $this->switch_lang( $default_language, true );
  610. }
  611. }
  612. //Code to run when reactivating the plugin
  613. $recently_activated = $this->get_setting('just_reactivated');
  614. if($recently_activated) {
  615. add_action( 'init', array( $this, 'rebuild_language_information' ), 1000 );
  616. }
  617. do_action('wpml_after_init');
  618. }
  619. /**
  620. * @param bool|String $requested_url String If this is specified the value of $url will be checked for whether it's the root page.
  621. * Checks whether the currently requested page is the root page.
  622. *
  623. * @return bool
  624. */
  625. function is_root_page( $requested_url = false ) {
  626. /*
  627. * A request leads to the root page under the following conditions.
  628. *
  629. * 1. The get parameter on it specifically requests the root page via either:
  630. * ?preview_id = {root_page_id}
  631. * ?page_id = {root_page_id}
  632. * ?p = {root_page_id}
  633. *
  634. * 2. The root page slug is the first slug after the domain.
  635. *
  636. * 3. There is no slug after the domain and the get parameters are not set as to redirect
  637. * to another page meaning:
  638. * no ?p, ?page_id or similar query parameter redirects to another post/page
  639. * no get parameter such as ?cat redirects to an archive page
  640. *
  641. */
  642. $is_root = true;
  643. // before checking anything see if the site even uses a root page
  644. $urls = $this->get_setting( 'urls' );
  645. if ( ! $urls
  646. || ! isset( $urls[ 'directory_for_default_language' ] )
  647. || ! $urls[ 'directory_for_default_language' ]
  648. || ! isset( $urls[ 'root_page' ] )
  649. || $urls[ 'root_page' ] == 0
  650. ) {
  651. $is_root = false;
  652. } elseif ( isset( $_SERVER[ 'REQUEST_URI' ] ) || $requested_url !== false ) {
  653. $root_id = $urls[ 'root_page' ];
  654. $root_slug = false;
  655. if ( $root_id ) {
  656. $root_page_object = get_post( $root_id );
  657. if ( $root_page_object && isset( $root_page_object->post_name ) ) {
  658. $root_slug = $root_page_object->post_name;
  659. }
  660. }
  661. if ( $root_slug === false ) {
  662. $is_root = false;
  663. } else {
  664. if ( $requested_url ) {
  665. $request_uri = parse_url( $requested_url, PHP_URL_PATH );
  666. $query_string = parse_url( $requested_url, PHP_URL_QUERY );
  667. if( $query_string ) {
  668. $request_uri .= '?' . $query_string;
  669. }
  670. } else {
  671. $request_uri = $_SERVER[ 'REQUEST_URI' ];
  672. }
  673. //If the get parameter ? is not preceeded by a /, add a '/'
  674. if ( strpos( $request_uri, '?' ) !== false && strpos( $request_uri, '/?' ) === false ) {
  675. $request_uri = str_replace( '?', '/?', $request_uri );
  676. }
  677. $request_uri = wpml_strip_subdir_from_url( $request_uri );
  678. //First get the slug of the requested url, should there be one.
  679. $slugs_and_get_params = explode( '/', $request_uri );
  680. foreach ( $slugs_and_get_params as $key => $slug ) {
  681. if ( ! trim( $slug ) ) {
  682. unset( $slugs_and_get_params[ $key ] );
  683. }
  684. }
  685. // if we have any slugs or get parameters it could be we are not on the root page
  686. if ( ! empty( $slugs_and_get_params ) ) {
  687. $get_query_string = '';
  688. // First of all see if we have get parameters
  689. if ( isset( $_GET ) && ! empty( $_GET ) ) {
  690. $get_query_string = array_pop( $slugs_and_get_params );
  691. /* In case we have get parameters we can instantly be sure to be on the root page
  692. * This can be done by either id parameters or by slug/name parameters.
  693. * ID parametes as of WP 4.1 are : p, page_id
  694. * Name parameters as of WP 4.1 are: name, pagename
  695. */
  696. if ( ( isset( $_GET[ 'p' ] ) && $_GET[ 'p' ] != $root_id )
  697. || ( isset( $_GET[ 'page_id' ] ) && $_GET[ 'page_id' ] != $root_id )
  698. || ( isset( $_GET[ 'name' ] ) && $_GET[ 'name' ] != $root_slug )
  699. || ( isset( $_GET[ 'pagename' ] ) && $_GET[ 'pagename' ] != $root_slug )
  700. ) {
  701. $is_root = false;
  702. }
  703. }
  704. /*
  705. * Next up there are other get parameters that allow us to recognize not being on the root page for certain.
  706. * These only come into play when neither of the above page parameters is set and therefore no specific page is queried for.
  707. */
  708. if ( ! ( isset( $_GET[ 'pagename' ] ) || isset( $_GET[ 'name' ] ) || isset( $_GET[ 'page_id' ] ) || isset( $_GET[ 'p' ] ) ) ) {
  709. /* The under these conditions excluded parameters, that ensure the root page to not be queried for, are determined in this way:
  710. * First we fetch all rewrite rules. This has to be done from the options cache since the actual rewrite object is not initialized yet.
  711. * Initializing it would impose a siginificant performance hit too.
  712. */
  713. $query = new WP_Query( str_replace( '?', '', $get_query_string ) );
  714. if ( ( $query->is_archive() ) ) {
  715. $is_root = false;
  716. }
  717. }
  718. // In case we have slugs, we need to check the last slug for whether it is the slug of the root page
  719. if ( $is_root && ! empty( $slugs_and_get_params ) ) {
  720. $slugs = $slugs_and_get_params;
  721. $last_slug = array_pop( $slugs );
  722. $second_slug = array_pop( $slugs );
  723. if ( ( $root_slug != $last_slug && ! is_numeric( $last_slug )
  724. || ( is_numeric( $last_slug ) && $second_slug != null && $root_slug != $second_slug && 'page' != $second_slug ) )
  725. && ( ! ( isset( $_GET[ 'p' ] ) && $_GET[ 'p' ] == $root_id )
  726. || ! ( isset( $_GET[ 'page_id' ] ) && $_GET[ 'page_id' ] == $root_id )
  727. || ! ( isset( $_GET[ 'name' ] ) && $_GET[ 'name' ] == $root_slug )
  728. || ! ( isset( $_GET[ 'pagename' ] ) && $_GET[ 'pagename' ] == $root_slug ) )
  729. ) {
  730. /* If the last slug is not the root slug or numeric,
  731. * then the current page is not the root page. This condition only holds though
  732. * in case no page/post parameters are appended to the request, that point towards the root page.
  733. */
  734. $is_root = false;
  735. }
  736. }
  737. }
  738. }
  739. }
  740. return $is_root;
  741. }
  742. /**
  743. * @param $url
  744. * Filters links to the root page, so that they are displayed properly in the front-end.
  745. *
  746. * @return mixed
  747. */
  748. function filter_root_permalink( $url ) {
  749. $urls = $this->get_setting( 'urls' );
  750. $root_id = $urls[ 'root_page' ];
  751. $root_page_object = get_post( $root_id );
  752. $url = str_replace( ' ', '', $url );
  753. $url = str_replace( '%20/', '/', $url );
  754. if ( $this->is_root_page( $url ) ) {
  755. $root_slug = $root_page_object->post_name;
  756. // Remove all whitespaces from urls
  757. $method = '';
  758. $new_url = str_replace( 'http://', '', $url );
  759. if ( $new_url != $url ) {
  760. $method = 'http://';
  761. } else {
  762. $new_url = str_replace( 'https://', '', $url );
  763. if ( $new_url != $url ) {
  764. $method = 'https://';
  765. }
  766. }
  767. $query = '';
  768. if ( strpos( $new_url, '?' ) !== false ) {
  769. $split_by_get_url = explode( '?', $new_url );
  770. $url_without_query = array_shift( $split_by_get_url );
  771. $query = implode( '?', $split_by_get_url );
  772. } else {
  773. $url_without_query = $new_url;
  774. }
  775. $slugs = explode( '/', $url_without_query );
  776. foreach ( $slugs as $key => $slug ) {
  777. if ( $slug == '' || strpos( $slug, parse_url( $url, PHP_URL_HOST ) ) !== false ) {
  778. unset( $slugs[ $key ] );
  779. }
  780. }
  781. $last_slug = array_pop( $slugs );
  782. $second_slug = array_pop( $slugs );
  783. if ( $second_slug == $root_slug && ( is_numeric( $last_slug ) || $last_slug == "" ) ) {
  784. $url_without_query = str_replace( '/' . $second_slug . '/', '/', $url_without_query );
  785. $potential_lang_slug = array_pop( $slugs );
  786. } elseif ( $last_slug == $root_slug ) {
  787. $url_without_query = str_replace( '/' . $last_slug, '/', $url_without_query );
  788. $potential_lang_slug = $second_slug;
  789. } else {
  790. $potential_lang_slug = array_pop( $slugs );
  791. }
  792. $all_langs = $this->get_active_languages();
  793. foreach ( $all_langs as $lang ) {
  794. if ( $lang[ 'code' ] == $potential_lang_slug ) {
  795. $url_without_query = str_replace( '/' . $potential_lang_slug, '/', $url_without_query );
  796. break;
  797. }
  798. }
  799. $new_url = trailingslashit($url_without_query);
  800. if ( $query != '' ) {
  801. $new_url = $new_url . '?' . $query;
  802. }
  803. /* Only if we actually have a root url, do we filter the url here.
  804. * This is to ensure that cases like url/wp-admin/members/root-slug are properly
  805. * differentiated from actualy root page calls, in case of root-slug's with
  806. * generic names potentially causing collisions.
  807. */
  808. if ( empty( $slugs ) ) {
  809. $url = $method . $new_url;
  810. }
  811. }
  812. return $url;
  813. }
  814. function load_dependencies() {
  815. do_action('wpml_load_dependencies');
  816. }
  817. /**
  818. * Sets up all term/taxonomy actions for use outside Translations Management or the Post Edit screen
  819. */
  820. function set_term_filters_and_hooks(){
  821. add_filter( 'terms_clauses', array( $this, 'terms_clauses' ), 10, 4 );
  822. add_filter( 'list_terms_exclusions', array( $this, 'exclude_other_terms' ), 1, 2 );
  823. add_filter( 'term_link', array( $this, 'tax_permalink_filter' ), 1, 2 );
  824. add_action( 'create_term', array( $this, 'create_term' ), 1, 2 );
  825. add_action( 'edit_term', array( $this, 'create_term' ), 1, 2 );
  826. add_filter( 'get_terms_args', array( $this, 'get_terms_args_filter' ) );
  827. add_filter( 'get_edit_term_link', array( $this, 'get_edit_term_link' ), 1, 4 );
  828. add_action('wp_ajax_icl_repair_broken_type_and_language_assignments', 'icl_repair_broken_type_and_language_assignments');
  829. //Taxonomies
  830. if ( version_compare( preg_replace( '#-RC[0-9]+(-[0-9]+)?$#', '', $GLOBALS[ 'wp_version' ] ), '3.1', '<' ) ) {
  831. add_filter( 'category_link', array( $this, 'category_permalink_filter' ), 1, 2 );
  832. add_filter( 'tag_link', array( $this, 'tax_permalink_filter' ), 1, 2 );
  833. }
  834. add_filter( 'taxonomy_template', array( $this, 'slug_template' ) );
  835. add_filter( 'category_template', array( $this, 'slug_template' ) );
  836. //post/page delete taxonomy
  837. add_action( 'deleted_term_relationships', array( $this, 'deleted_term_relationships' ), 10, 2 );
  838. // adjust queried categories and tags ids according to the language
  839. if ( $this->settings[ 'auto_adjust_ids' ] ) {
  840. add_action( 'parse_query', array( $this, 'parse_query' ) );
  841. add_action( 'wp_list_pages_excludes', array( $this, 'adjust_wp_list_pages_excludes' ) );
  842. if ( !is_admin() ) {
  843. add_filter( 'get_term', array( $this, 'get_term_adjust_id' ), 1, 1 );
  844. add_filter( 'category_link', array( $this, 'category_link_adjust_id' ), 1, 2 );
  845. add_filter( 'get_terms', array( $this, 'get_terms_adjust_ids' ), 1, 3 );
  846. add_filter( 'get_pages', array( $this, 'get_pages_adjust_ids' ), 1, 2 );
  847. }
  848. }
  849. }
  850. function icl_redirect_canonical_wrapper()
  851. {
  852. global $_icl_server_request_uri;
  853. $requested_url = ( !empty( $_SERVER[ 'HTTPS' ] ) && mb_strtolower( $_SERVER[ 'HTTPS' ] ) == 'on' ) ? 'https://' : 'http://';
  854. $requested_url .= $this->get_server_host_name();
  855. $requested_url .= $_icl_server_request_uri;
  856. redirect_canonical( $requested_url );
  857. }
  858. /**
  859. * If user perform bulk taxonomy deletion when displaying non-default
  860. * language taxonomies, after deletion should stay with same language
  861. *
  862. * @param string $location Url where browser will redirect
  863. * @return string Url where browser will redirect
  864. */
  865. function preserve_lang_param_after_bulk_category_delete($location) {
  866. if (empty($_GET['lang'])) {
  867. return $location;
  868. }
  869. $location = add_query_arg( 'lang', $_GET['lang'], $location );
  870. return $location;
  871. }
  872. function remove_admin_language_switcher() {
  873. remove_action( 'wp_before_admin_bar_render', array( $this, 'admin_language_switcher' ) );
  874. }
  875. function rebuild_language_information() {
  876. $this->set_setting('just_reactivated', 0);
  877. $this->save_settings();
  878. global $iclTranslationManagement;
  879. if ( isset( $iclTranslationManagement ) ) {
  880. $iclTranslationManagement->add_missing_language_information();
  881. }
  882. }
  883. function on_wp_init()
  884. {
  885. if ( is_admin() && current_user_can( 'manage_options' ) ) {
  886. if ( $this->icl_account_configured() ) {
  887. add_action( 'admin_notices', array( $this, 'icl_reminders' ) );
  888. }
  889. }
  890. include ICL_PLUGIN_PATH . '/inc/translation-management/taxonomy-translation.php';
  891. }
  892. function setup()
  893. {
  894. $setup_complete = $this->get_setting('setup_complete');
  895. if(!$setup_complete) {
  896. $this->set_setting('setup_complete', false);
  897. }
  898. return $setup_complete;
  899. }
  900. function get_current_user()
  901. {
  902. global $current_user;
  903. if ( did_action( 'set_current_user' ) ) {
  904. return $current_user;
  905. } else {
  906. return $this->current_user; // created early / no authentication
  907. }
  908. }
  909. function ajax_setup()
  910. {
  911. require ICL_PLUGIN_PATH . '/ajax.php';
  912. }
  913. function check_if_admin_action_from_referer() {
  914. $result = false;
  915. if ( isset( $_SERVER[ 'HTTP_REFERER' ] ) ) {
  916. $http_referer = parse_url( $_SERVER[ 'HTTP_REFERER' ] );
  917. $referer_path = $http_referer[ 'path' ];
  918. $referer_parts = explode( '/', $referer_path );
  919. if ( in_array( 'wp-admin', $referer_parts ) ) {
  920. $result = true;
  921. }
  922. }
  923. return $result;
  924. }
  925. function configure_custom_column()
  926. {
  927. global $pagenow, $wp_post_types;
  928. $pagenow_ = '';
  929. $is_ajax = false;
  930. if ( $pagenow == 'admin-ajax.php' ) {
  931. if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'inline-save' || isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'fetch-list'
  932. ) {
  933. $is_ajax = true;
  934. }
  935. }
  936. if ( ( $pagenow == 'edit.php' || $pagenow_ == 'edit-pages.php' || $is_ajax ) ) {
  937. $post_type = isset( $_REQUEST[ 'post_type' ] ) ? $_REQUEST[ 'post_type' ] : 'post';
  938. switch ( $post_type ) {
  939. case 'post':
  940. case 'page':
  941. add_filter( 'manage_' . $post_type . 's_columns', array( $this, 'add_posts_management_column' ) );
  942. if ( isset( $_GET[ 'post_type' ] ) && $_GET[ 'post_type' ] == 'page' ) {
  943. add_action( 'manage_' . $post_type . 's_custom_column', array( $this, 'add_content_for_posts_management_column' ) );
  944. }
  945. add_action( 'manage_posts_custom_column', array( $this, 'add_content_for_posts_management_column' ) );
  946. break;
  947. default:
  948. if ( in_array( $post_type, array_keys( $this->get_translatable_documents() ) ) ) {
  949. add_filter( 'manage_' . $post_type . '_posts_columns', array( $this, 'add_posts_management_column' ) );
  950. if ( $wp_post_types[ $post_type ]->hierarchical ) {
  951. add_action( 'manage_pages_custom_column', array( $this, 'add_content_for_posts_management_column' ) );
  952. add_action( 'manage_posts_custom_column', array( $this, 'add_content_for_posts_management_column' ) ); // add this too - for more types plugin
  953. } else {
  954. add_action( 'manage_posts_custom_column', array( $this, 'add_content_for_posts_management_column' ) );
  955. }
  956. }
  957. }
  958. add_action( 'admin_print_scripts', array( $this, '__set_posts_management_column_width' ) );
  959. }
  960. }
  961. function _taxonomy_languages_menu()
  962. {
  963. // tags language selection
  964. global $pagenow;
  965. if ( $pagenow == 'edit-tags.php' ) {
  966. // handle case of the tax edit page (after a taxonomy has been added)
  967. // needs to redirect back to
  968. if ( isset( $_GET[ 'trid' ] ) && isset( $_GET[ 'source_lang' ] ) ) {
  969. $translations = $this->get_element_translations( $_GET[ 'trid' ], 'tax_' . $_GET[ 'taxonomy' ] );
  970. if ( isset( $translations[ $_GET[ 'lang' ] ] ) ) {
  971. wp_redirect( get_edit_term_link( $translations[ $_

Large files files are truncated, but you can click here to view the full file