PLL_Plugins_Compat

Manages compatibility with 3rd party plugins ( and themes ) This class is available as soon as the plugin is loaded.

Defined (1)

The class is defined in the following location(s).

/modules/plugins/plugins-compat.php  
  1. class PLL_Plugins_Compat { 
  2. static protected $instance; // for singleton 
  3.  
  4. /** 
  5. * Constructor 
  6. * @since 1.0 
  7. */ 
  8. protected function __construct() { 
  9. // WordPress Importer 
  10. add_action( 'init', array( $this, 'maybe_wordpress_importer' ) ); 
  11. add_filter( 'wp_import_terms', array( $this, 'wp_import_terms' ) ); 
  12.  
  13. // YARPP 
  14. add_action( 'init', array( $this, 'yarpp_init' ) ); // after Polylang has registered its taxonomy in setup_theme 
  15.  
  16. // Yoast SEO 
  17. add_action( 'pll_language_defined', array( $this, 'wpseo_init' ) ); 
  18.  
  19. // Custom field template 
  20. add_action( 'add_meta_boxes', array( $this, 'cft_copy' ), 10, 2 ); 
  21.  
  22. // Aqua Resizer 
  23. add_filter( 'pll_home_url_black_list', array( $this, 'aq_home_url_black_list' ) ); 
  24.  
  25. // Twenty Fourteen 
  26. add_filter( 'transient_featured_content_ids', array( $this, 'twenty_fourteen_featured_content_ids' ) ); 
  27. add_filter( 'option_featured-content', array( $this, 'twenty_fourteen_option_featured_content' ) ); 
  28.  
  29. // Duplicate post 
  30. add_filter( 'option_duplicate_post_taxonomies_blacklist' , array( $this, 'duplicate_post_taxonomies_blacklist' ) ); 
  31.  
  32. // Jetpack 3 
  33. add_action( 'init', array( $this, 'jetpack_init' ) ); 
  34. add_action( 'jetpack_widget_get_top_posts', array( $this, 'jetpack_widget_get_top_posts' ), 10, 3 ); 
  35. add_filter( 'grunion_contact_form_field_html', array( $this, 'grunion_contact_form_field_html_filter' ), 10, 3 ); 
  36. add_filter( 'jetpack_open_graph_tags', array( $this, 'jetpack_ogp' ) ); 
  37. add_filter( 'jetpack_relatedposts_filter_filters', array( $this, 'jetpack_relatedposts_filter_filters' ), 10, 2 ); 
  38.  
  39. // Jetpack infinite scroll 
  40. if ( ! defined( 'PLL_AJAX_ON_FRONT' ) && isset( $_GET['infinity'], $_POST['action'] ) && 'infinite_scroll' == $_POST['action'] ) { 
  41. define( 'PLL_AJAX_ON_FRONT', true ); 
  42.  
  43. // WP Sweep 
  44. add_filter( 'wp_sweep_excluded_taxonomies', array( $this, 'wp_sweep_excluded_taxonomies' ) ); 
  45.  
  46. // Twenty Seventeen 
  47. add_action( 'init', array( $this, 'twenty_seventeen_init' ) ); 
  48.  
  49. // No category base (works for Yoast SEO too) 
  50. add_filter( 'get_terms_args', array( $this, 'no_category_base_get_terms_args' ), 5 ); // Before adding cache domain 
  51.  
  52. /** 
  53. * Access to the single instance of the class 
  54. * @since 1.7 
  55. * @return object 
  56. */ 
  57. static public function instance() { 
  58. if ( empty( self::$instance ) ) { 
  59. self::$instance = new self(); 
  60.  
  61. return self::$instance; 
  62.  
  63. /** 
  64. * WordPress Importer 
  65. * If WordPress Importer is active, replace the wordpress_importer_init function 
  66. * @since 1.2 
  67. */ 
  68. function maybe_wordpress_importer() { 
  69. if ( defined( 'WP_LOAD_IMPORTERS' ) && class_exists( 'WP_Import' ) ) { 
  70. remove_action( 'admin_init', 'wordpress_importer_init' ); 
  71. add_action( 'admin_init', array( $this, 'wordpress_importer_init' ) ); 
  72.  
  73. /** 
  74. * WordPress Importer 
  75. * Loads our child class PLL_WP_Import instead of WP_Import 
  76. * @since 1.2 
  77. */ 
  78. function wordpress_importer_init() { 
  79. $class = new ReflectionClass( 'WP_Import' ); 
  80. load_plugin_textdomain( 'wordpress-importer', false, basename( dirname( $class->getFileName() ) ) . '/languages' ); 
  81.  
  82. $GLOBALS['wp_import'] = new PLL_WP_Import(); 
  83. register_importer( 'wordpress', 'WordPress', __( 'Import <strong>posts, pages, comments, custom fields, categories, and tags</strong> from a WordPress export file.', 'wordpress-importer' ), array( $GLOBALS['wp_import'], 'dispatch' ) ); 
  84.  
  85. /** 
  86. * WordPress Importer 
  87. * Backward Compatibility Polylang < 1.8 
  88. * Sets the flag when importing a language and the file has been exported with Polylang < 1.8 
  89. * @since 1.8 
  90. * @param array $terms an array of arrays containing terms information form the WXR file 
  91. * @return array 
  92. */ 
  93. function wp_import_terms( $terms ) { 
  94. include PLL_SETTINGS_INC . '/languages.php'; 
  95.  
  96. foreach ( $terms as $key => $term ) { 
  97. if ( 'language' === $term['term_taxonomy'] ) { 
  98. $description = maybe_unserialize( $term['term_description'] ); 
  99. if ( empty( $description['flag_code'] ) && isset( $languages[ $description['locale'] ] ) ) { 
  100. $description['flag_code'] = $languages[ $description['locale'] ][4]; 
  101. $terms[ $key ]['term_description'] = serialize( $description ); 
  102. return $terms; 
  103.  
  104. /** 
  105. * YARPP 
  106. * Just makes YARPP aware of the language taxonomy ( after Polylang registered it ) 
  107. * @since 1.0 
  108. */ 
  109. public function yarpp_init() { 
  110. $GLOBALS['wp_taxonomies']['language']->yarpp_support = 1; 
  111.  
  112. /** 
  113. * Yoast SEO 
  114. * Translate options and add specific filters and actions 
  115. * @since 1.6.4 
  116. */ 
  117. public function wpseo_init() { 
  118. if ( ! defined( 'WPSEO_VERSION' ) ) { 
  119. return; 
  120.  
  121. if ( ! PLL() instanceof PLL_Frontend ) { 
  122. add_action( 'admin_init', array( $this, 'wpseo_register_strings' ) ); 
  123. return; 
  124.  
  125. add_filter( 'option_wpseo_titles', array( $this, 'wpseo_translate_titles' ) ); 
  126.  
  127. // Reloads options once the language has been defined to enable translations 
  128. // Useful only when the language is set from content 
  129. if ( did_action( 'wp_loaded' ) ) { 
  130. if ( version_compare( WPSEO_VERSION, '1.7.2', '<' ) ) { 
  131. global $wpseo_front; 
  132. } else { 
  133. $wpseo_front = WPSEO_Frontend::get_instance(); 
  134.  
  135. $options = version_compare( WPSEO_VERSION, '1.5', '<' ) ? get_wpseo_options_arr() : WPSEO_Options::get_option_names(); 
  136. foreach ( $options as $opt ) { 
  137. $wpseo_front->options = array_merge( $wpseo_front->options, (array) get_option( $opt ) ); 
  138.  
  139. // Filters sitemap queries to remove inactive language or to get 
  140. // one sitemap per language when using multiple domains or subdomains 
  141. // because WPSEO does not accept several domains or subdomains in one sitemap 
  142. add_filter( 'wpseo_posts_join', array( $this, 'wpseo_posts_join' ), 10, 2 ); 
  143. add_filter( 'wpseo_posts_where', array( $this, 'wpseo_posts_where' ), 10, 2 ); 
  144. add_filter( 'wpseo_typecount_join', array( $this, 'wpseo_posts_join' ), 10, 2 ); 
  145. add_filter( 'wpseo_typecount_where', array( $this, 'wpseo_posts_where' ), 10, 2 ); 
  146.  
  147. if ( PLL()->options['force_lang'] > 1 ) { 
  148. add_filter( 'wpseo_enable_xml_sitemap_transient_caching', '__return_false' ); // Disable cache! otherwise WPSEO keeps only one domain (thanks to Junaid Bhura) 
  149. add_filter( 'home_url', array( $this, 'wpseo_home_url' ) , 10, 2 ); // Fix home_url 
  150. } else { 
  151. // Get all terms in all languages when the language is set from the content or directory name 
  152. add_filter( 'get_terms_args', array( $this, 'wpseo_remove_terms_filter' ) ); 
  153.  
  154. // Add the homepages for all languages to the sitemap when the front page displays posts 
  155. if ( ! get_option( 'page_on_front' ) ) { 
  156. add_filter( 'wpseo_sitemap_post_content', array( $this, 'add_language_home_urls' ) ); 
  157.  
  158. add_filter( 'pll_home_url_white_list', array( $this, 'wpseo_home_url_white_list' ) ); 
  159. add_action( 'wpseo_opengraph', array( $this, 'wpseo_ogp' ), 2 ); 
  160. add_filter( 'wpseo_canonical', array( $this, 'wpseo_canonical' ) ); 
  161.  
  162. /** 
  163. * Yoast SEO 
  164. * Registers strings for custom post types and custom taxonomies titles and meta descriptions 
  165. * @since 2.0 
  166. */ 
  167. function wpseo_register_strings() { 
  168. $options = get_option( 'wpseo_titles' ); 
  169. foreach ( get_post_types( array( 'public' => true, '_builtin' => false ) ) as $t ) { 
  170. if ( pll_is_translated_post_type( $t ) && ! empty( $options[ 'title-' . $t ] ) ) { 
  171. pll_register_string( 'title-' . $t, $options[ 'title-' . $t ], 'wordpress-seo' ); 
  172. pll_register_string( 'metadesc-' . $t, $options[ 'metadesc-' . $t ], 'wordpress-seo' ); 
  173. foreach ( get_post_types( array( 'has_archive' => true, '_builtin' => false ) ) as $t ) { 
  174. if ( pll_is_translated_post_type( $t ) && ! empty( $options[ 'title-ptarchive-' . $t ] ) ) { 
  175. pll_register_string( 'title-ptarchive-' . $t, $options[ 'title-ptarchive-' . $t ], 'wordpress-seo' ); 
  176. pll_register_string( 'metadesc-ptarchive-' . $t, $options[ 'metadesc-ptarchive-' . $t ], 'wordpress-seo' ); 
  177. pll_register_string( 'bctitle-ptarchive-' . $t, $options[ 'bctitle-ptarchive-' . $t ], 'wordpress-seo' ); 
  178. foreach ( get_taxonomies( array( 'public' => true, '_builtin' => false ) ) as $t ) { 
  179. if ( pll_is_translated_taxonomy( $t ) && ! empty( $options[ 'title-tax-' . $t ] ) ) { 
  180. pll_register_string( 'title-tax-' . $t, $options[ 'title-tax-' . $t ], 'wordpress-seo' ); 
  181. pll_register_string( 'metadesc-tax-' . $t, $options[ 'metadesc-tax-' . $t ], 'wordpress-seo' ); 
  182.  
  183. /** 
  184. * Yoast SEO 
  185. * Translates strings for custom post types and custom taxonomies titles and meta descriptions 
  186. * @since 2.0 
  187. * @param array $options 
  188. * @return array 
  189. */ 
  190. function wpseo_translate_titles( $options ) { 
  191. if ( PLL() instanceof PLL_Frontend ) { 
  192. foreach ( get_post_types( array( 'public' => true, '_builtin' => false ) ) as $t ) { 
  193. if ( pll_is_translated_post_type( $t ) && ! empty( $options[ 'title-' . $t ] ) ) { 
  194. $options[ 'title-' . $t ] = pll__( $options[ 'title-' . $t ] ); 
  195. $options[ 'metadesc-' . $t ] = pll__( $options[ 'metadesc-' . $t ] ); 
  196. foreach ( get_post_types( array( 'has_archive' => true, '_builtin' => false ) ) as $t ) { 
  197. if ( pll_is_translated_post_type( $t ) && ! empty( $options[ 'title-ptarchive-' . $t ] ) ) { 
  198. $options[ 'title-ptarchive-' . $t ] = pll__( $options[ 'title-ptarchive-' . $t ] ); 
  199. $options[ 'metadesc-ptarchive-' . $t ] = pll__( $options[ 'metadesc-ptarchive-' . $t ] ); 
  200. $options[ 'bctitle-ptarchive-' . $t ] = pll__( $options[ 'bctitle-ptarchive-' . $t ] ); 
  201. foreach ( get_taxonomies( array( 'public' => true, '_builtin' => false ) ) as $t ) { 
  202. if ( pll_is_translated_taxonomy( $t ) && ! empty( $options[ 'title-tax-' . $t ] ) ) { 
  203. $options[ 'title-tax-' . $t ] = pll__( $options[ 'title-tax-' . $t ] ); 
  204. $options[ 'metadesc-tax-' . $t ] = pll__( $options[ 'metadesc-tax-' . $t ] ); 
  205. return $options; 
  206.  
  207. /** 
  208. * Yoast SEO 
  209. * Fixes the home url as well as the stylesheet url 
  210. * Only when using multiple domains or subdomains 
  211. * @since 1.6.4 
  212. * @param string $url 
  213. * @return $url 
  214. */ 
  215. public function wpseo_home_url( $url, $path ) { 
  216. $uri = empty( $path ) ? ltrim( $_SERVER['REQUEST_URI'], '/' ) : $path; 
  217.  
  218. if ( 'sitemap_index.xml' === $uri || preg_match( '#([^/]+?)-sitemap([0-9]+)?\.xml|([a-z]+)?-?sitemap\.xsl#', $uri ) ) { 
  219. $url = PLL()->links_model->switch_language_in_link( $url, PLL()->curlang ); 
  220.  
  221. return $url; 
  222.  
  223. /** 
  224. * Yoast SEO 
  225. * Get active languages for the sitemaps 
  226. * @since 2.0 
  227. * @return array list of active language slugs, empty if all languages are active 
  228. */ 
  229. protected function wpseo_get_active_languages() { 
  230. $languages = PLL()->model->get_languages_list(); 
  231. if ( wp_list_filter( $languages, array( 'active' => false ) ) ) { 
  232. return wp_list_pluck( wp_list_filter( $languages, array( 'active' => false ), 'NOT' ), 'slug' ); 
  233. return array(); 
  234.  
  235. /** 
  236. * Yoast SEO 
  237. * Modifies the sql request for posts sitemaps 
  238. * Only when using multiple domains or subdomains or if some languages are not active 
  239. * @since 1.6.4 
  240. * @param string $sql JOIN clause 
  241. * @param string $post_type 
  242. * @return string 
  243. */ 
  244. public function wpseo_posts_join( $sql, $post_type ) { 
  245. return pll_is_translated_post_type( $post_type ) && ( PLL()->options['force_lang'] > 1 || $this->wpseo_get_active_languages() ) ? $sql. PLL()->model->post->join_clause() : $sql; 
  246.  
  247. /** 
  248. * Yoast SEO 
  249. * Modifies the sql request for posts sitemaps 
  250. * Only when using multiple domains or subdomains or if some languages are not active 
  251. * @since 1.6.4 
  252. * @param string $sql WHERE clause 
  253. * @param string $post_type 
  254. * @return string 
  255. */ 
  256. public function wpseo_posts_where( $sql, $post_type ) { 
  257. if ( pll_is_translated_post_type( $post_type ) ) { 
  258. if ( PLL()->options['force_lang'] > 1 ) { 
  259. return $sql . PLL()->model->post->where_clause( PLL()->curlang ); 
  260.  
  261. if ( $languages = $this->wpseo_get_active_languages() ) { 
  262. return $sql . PLL()->model->post->where_clause( $languages ); 
  263. return $sql; 
  264.  
  265. /** 
  266. * Yoast SEO 
  267. * Removes the language filter (and remove inactive languages) for the taxonomy sitemaps 
  268. * Only when the language is set from the content or directory name 
  269. * @since 1.0.3 
  270. * @param array $args get_terms arguments 
  271. * @return array modified list of arguments 
  272. */ 
  273. public function wpseo_remove_terms_filter( $args ) { 
  274. if ( isset( $GLOBALS['wp_query']->query['sitemap'] ) ) { 
  275. $args['lang'] = implode( ', ', $this->wpseo_get_active_languages() ); 
  276. return $args; 
  277.  
  278. /** 
  279. * Yoast SEO 
  280. * Adds the home urls for all (active) languages to the sitemap 
  281. * @since 1.9 
  282. * @param string $str additional urls to sitemap post 
  283. * @return string 
  284. */ 
  285. public function add_language_home_urls( $str ) { 
  286. global $wpseo_sitemaps; 
  287. $renderer = version_compare( WPSEO_VERSION, '3.2', '<' ) ? $wpseo_sitemaps : $wpseo_sitemaps->renderer; 
  288.  
  289. $languages = wp_list_pluck( wp_list_filter( PLL()->model->get_languages_list() , array( 'active' => false ), 'NOT' ), 'slug' ); 
  290.  
  291. foreach ( $languages as $lang ) { 
  292. if ( empty( PLL()->options['hide_default'] ) || pll_default_language() !== $lang ) { 
  293. $str .= $renderer->sitemap_url( array( 
  294. 'loc' => pll_home_url( $lang ),  
  295. 'pri' => 1,  
  296. 'chf' => apply_filters( 'wpseo_sitemap_homepage_change_freq', 'daily', pll_home_url( $lang ) ),  
  297. ) ); 
  298. return $str; 
  299.  
  300. /** 
  301. * Yoast SEO 
  302. * @since 1.1.2 
  303. * @param array $arr 
  304. * @return array 
  305. */ 
  306. public function wpseo_home_url_white_list( $arr ) { 
  307. return array_merge( $arr, array( array( 'file' => 'wordpress-seo' ) ) ); 
  308.  
  309. /** 
  310. * Yoast SEO 
  311. * Adds opengraph support for translations 
  312. * @since 1.6 
  313. */ 
  314. public function wpseo_ogp() { 
  315. global $wpseo_og; 
  316.  
  317. // WPSEO already deals with the locale 
  318. if ( did_action( 'pll_init' ) && method_exists( $wpseo_og, 'og_tag' ) ) { 
  319. foreach ( PLL()->model->get_languages_list() as $language ) { 
  320. if ( $language->slug != PLL()->curlang->slug && PLL()->links->get_translation_url( $language ) && $fb_locale = self::get_fb_locale( $language ) ) { 
  321. $wpseo_og->og_tag( 'og:locale:alternate', $fb_locale ); 
  322.  
  323. /** 
  324. * Yoast SEO 
  325. * Fixes the canonical front page url as unlike WP, WPSEO does not add a trailing slash to the canonical front page url 
  326. * @since 1.7.10 
  327. * @param string $url 
  328. * @return $url 
  329. */ 
  330. public function wpseo_canonical( $url ) { 
  331. return is_front_page( $url ) && get_option( 'permalink_structure' ) ? trailingslashit( $url ) : $url; 
  332.  
  333. /** 
  334. * Aqua Resizer 
  335. * @since 1.1.5 
  336. * @param array $arr 
  337. * @return array 
  338. */ 
  339. public function aq_home_url_black_list( $arr ) { 
  340. return array_merge( $arr, array( array( 'function' => 'aq_resize' ) ) ); 
  341.  
  342. /** 
  343. * Custom field template 
  344. * Custom field template does check $_REQUEST['post'] to populate the custom fields values 
  345. * @since 1.0.2 
  346. * @param string $post_type unused 
  347. * @param object $post current post object 
  348. */ 
  349. public function cft_copy( $post_type, $post ) { 
  350. global $custom_field_template; 
  351. if ( isset( $custom_field_template, $_REQUEST['from_post'], $_REQUEST['new_lang'] ) && ! empty( $post ) ) { 
  352. $_REQUEST['post'] = $post->ID; 
  353.  
  354. /** 
  355. * Twenty Fourteen 
  356. * Rewrites the function Featured_Content::get_featured_post_ids() 
  357. * @since 1.4 
  358. * @param array $ids featured posts ids 
  359. * @return array modified featured posts ids ( include all languages ) 
  360. */ 
  361. public function twenty_fourteen_featured_content_ids( $featured_ids ) { 
  362. if ( 'twentyfourteen' != get_template() || ! did_action( 'pll_init' ) || false !== $featured_ids ) { 
  363. return $featured_ids; 
  364.  
  365. $settings = Featured_Content::get_setting(); 
  366.  
  367. if ( ! $term = wpcom_vip_get_term_by( 'name', $settings['tag-name'], 'post_tag' ) ) { 
  368. return $featured_ids; 
  369.  
  370. // Get featured tag translations 
  371. $tags = PLL()->model->term->get_translations( $term->term_id ); 
  372. $ids = array(); 
  373.  
  374. // Query for featured posts in all languages 
  375. // One query per language to get the correct number of posts per language 
  376. foreach ( $tags as $tag ) { 
  377. $_ids = get_posts( array( 
  378. 'lang' => 0, // avoid language filters 
  379. 'fields' => 'ids',  
  380. 'numberposts' => Featured_Content::$max_posts,  
  381. 'tax_query' => array( array( 
  382. 'taxonomy' => 'post_tag',  
  383. 'terms' => (int) $tag,  
  384. ) ),  
  385. ) ); 
  386.  
  387. $ids = array_merge( $ids, $_ids ); 
  388.  
  389. $ids = array_map( 'absint', $ids ); 
  390. set_transient( 'featured_content_ids', $ids ); 
  391.  
  392. return $ids; 
  393.  
  394. /** 
  395. * Twenty Fourteen 
  396. * Translates the featured tag id in featured content settings 
  397. * Mainly to allow hiding it when requested in featured content options 
  398. * Acts only on frontend 
  399. * @since 1.4 
  400. * @param array $settings featured content settings 
  401. * @return array modified $settings 
  402. */ 
  403. public function twenty_fourteen_option_featured_content( $settings ) { 
  404. if ( 'twentyfourteen' == get_template() && PLL() instanceof PLL_Frontend && $settings['tag-id'] && $tr = pll_get_term( $settings['tag-id'] ) ) { 
  405. $settings['tag-id'] = $tr; 
  406.  
  407. return $settings; 
  408.  
  409. /** 
  410. * Duplicate Post 
  411. * Avoid duplicating the 'post_translations' taxonomy 
  412. * @since 1.8 
  413. * @param array $taxonomies 
  414. * @return array 
  415. */ 
  416. function duplicate_post_taxonomies_blacklist( $taxonomies ) { 
  417. $taxonomies[] = 'post_translations'; 
  418. return $taxonomies; 
  419.  
  420. /** 
  421. * Jetpack 
  422. * Add filters 
  423. * @since 2.1 
  424. */ 
  425. public function jetpack_init() { 
  426. if ( ! defined( 'JETPACK__VERSION' ) ) { 
  427. return; 
  428.  
  429. // Infinite scroll ajax url must be on the right domain 
  430. if ( did_action( 'pll_init' ) && PLL()->options['force_lang'] > 1 ) { 
  431. add_filter( 'infinite_scroll_ajax_url', array( PLL()->links_model, 'site_url' ) ); 
  432. add_filter( 'infinite_scroll_js_settings', array( $this, 'jetpack_infinite_scroll_js_settings' ) ); 
  433.  
  434. /** 
  435. * Jetpack 
  436. * Adapted from the same function in jetpack-3.0.2/3rd-party/wpml.php 
  437. * @since 1.5.4 
  438. */ 
  439. public function jetpack_widget_get_top_posts( $posts, $post_ids, $count ) { 
  440. foreach ( $posts as $k => $post ) { 
  441. if ( pll_current_language() !== pll_get_post_language( $post['post_id'] ) ) { 
  442. unset( $posts[ $k ] ); 
  443.  
  444. return $posts; 
  445.  
  446. /** 
  447. * Jetpack 
  448. * Adapted from the same function in jetpack-3.0.2/3rd-party/wpml.php 
  449. * Keeps using 'icl_translate' as the function registers the string 
  450. * @since 1.5.4 
  451. */ 
  452. public function grunion_contact_form_field_html_filter( $r, $field_label, $id ) { 
  453. if ( function_exists( 'icl_translate' ) ) { 
  454. if ( pll_current_language() !== pll_default_language() ) { 
  455. $label_translation = icl_translate( 'jetpack ', $field_label . '_label', $field_label ); 
  456. $r = str_replace( $field_label, $label_translation, $r ); 
  457.  
  458. return $r; 
  459.  
  460. /** 
  461. * Jetpack 
  462. * Adds opengraph support for locale and translations 
  463. * @since 1.6 
  464. * @param array $tags opengraph tags to output 
  465. * @return array 
  466. */ 
  467. public function jetpack_ogp( $tags ) { 
  468. if ( did_action( 'pll_init' ) ) { 
  469. foreach ( PLL()->model->get_languages_list() as $language ) { 
  470. if ( $language->slug != PLL()->curlang->slug && PLL()->links->get_translation_url( $language ) && $fb_locale = self::get_fb_locale( $language ) ) { 
  471. $tags['og:locale:alternate'][] = $fb_locale; 
  472. if ( $language->slug == PLL()->curlang->slug && $fb_locale = self::get_fb_locale( $language ) ) { 
  473. $tags['og:locale'] = $fb_locale; 
  474. return $tags; 
  475.  
  476. /** 
  477. * Jetpack 
  478. * Allows to make sure that related posts are in the correct language 
  479. * @since 1.8 
  480. * @param array $filters Array of ElasticSearch filters based on the post_id and args. 
  481. * @param string $post_id Post ID of the post for which we are retrieving Related Posts. 
  482. * @return array 
  483. */ 
  484. function jetpack_relatedposts_filter_filters( $filters, $post_id ) { 
  485. $slug = sanitize_title( pll_get_post_language( $post_id, 'name' ) ); 
  486. $filters[] = array( 'term' => array( 'taxonomy.language.slug' => $slug ) ); 
  487. return $filters; 
  488.  
  489. /** 
  490. * Jetpack 
  491. * Fixes the settings history host for infinite scroll when using subdomains or multiple domains 
  492. * @since 2.1 
  493. * @param array $settings 
  494. * @return array 
  495. */ 
  496. public function jetpack_infinite_scroll_js_settings( $settings ) { 
  497. $settings['history']['host'] = parse_url( pll_home_url(), PHP_URL_HOST ); // Jetpack uses get_option( 'home' ) 
  498. return $settings; 
  499.  
  500. /** 
  501. * WP Sweep 
  502. * Add 'term_language' and 'term_translations' to excluded taxonomies otherwise terms loose their language and translation group 
  503. * @since 2.0 
  504. * @param array $excluded_taxonomies list of taxonomies excluded from sweeping 
  505. * @return array 
  506. */ 
  507. public function wp_sweep_excluded_taxonomies( $excluded_taxonomies ) { 
  508. return array_merge( $excluded_taxonomies, array( 'term_language', 'term_translations' ) ); 
  509.  
  510. /** 
  511. * Twenty Seventeen 
  512. * Translates the front page panels 
  513. * @since 2.0.10 
  514. */ 
  515. public function twenty_seventeen_init() { 
  516. if ( 'twentyseventeen' === get_template() && did_action( 'pll_init' ) && PLL() instanceof PLL_Frontend ) { 
  517. $num_sections = twentyseventeen_panel_count(); 
  518. for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) { 
  519. add_filter( 'theme_mod_panel_' . $i, 'pll_get_post' ); 
  520.  
  521. /** 
  522. * Make sure No category base plugins (including Yoast SEO) get all categories when flushing rules 
  523. * @since 2.1 
  524. * @param array $args 
  525. * @return array 
  526. */ 
  527. public function no_category_base_get_terms_args( $args ) { 
  528. if ( doing_filter( 'category_rewrite_rules' ) ) { 
  529. $args['lang'] = ''; 
  530. return $args; 
  531.  
  532. /** 
  533. * Correspondance between WordPress locales and Facebook locales 
  534. * @see https://translate.wordpress.org/ 
  535. * @see https://www.facebook.com/translations/FacebookLocales.xml 
  536. * @since 1.8.1 Update the list of locales 
  537. * @since 1.6 
  538. * @param object $language 
  539. * @return bool|string Facebook locale, false if no correspondance found 
  540. */ 
  541. static public function get_fb_locale( $language ) { 
  542. static $facebook_locales = array( 
  543. 'af' => 'af_ZA',  
  544. 'ak' => 'ak_GH',  
  545. 'am' => 'am_ET',  
  546. 'ar' => 'ar_AR',  
  547. 'arq' => 'ar_AR',  
  548. 'ary' => 'ar_AR',  
  549. 'as' => 'as_IN',  
  550. 'az' => 'az_AZ',  
  551. 'bel' => 'be_BY',  
  552. 'bg_BG' => 'bg_BG',  
  553. 'bn_BD' => 'bn_IN',  
  554. 'bre' => 'br_FR',  
  555. 'bs_BA' => 'bs_BA',  
  556. 'ca' => 'ca_ES',  
  557. 'ceb' => 'cx_PH',  
  558. 'ckb' => 'cb_IQ',  
  559. 'co' => 'co_FR',  
  560. 'cs_CZ' => 'cs_CZ',  
  561. 'cy' => 'cy_GB',  
  562. 'da_DK' => 'da_DK',  
  563. 'de_CH' => 'de_DE',  
  564. 'de_DE' => 'de_DE',  
  565. 'de_DE_formal' => 'de_DE',  
  566. 'el' => 'el_GR',  
  567. 'en_AU' => 'en_US',  
  568. 'en_CA' => 'en_US',  
  569. 'en_GB' => 'en_GB',  
  570. 'en_NZ' => 'en_US',  
  571. 'en_US' => 'en_US',  
  572. 'en_ZA' => 'en_US',  
  573. 'eo' => 'eo_EO',  
  574. 'es_AR' => 'es_LA',  
  575. 'es_CL' => 'es_CL',  
  576. 'es_CO' => 'es_CO',  
  577. 'es_MX' => 'es_MX',  
  578. 'es_PE' => 'es_LA',  
  579. 'es_ES' => 'es_ES',  
  580. 'es_VE' => 'es_VE',  
  581. 'et' => 'et_EE',  
  582. 'eu' => 'eu_ES',  
  583. 'fa_IR' => 'fa_IR',  
  584. 'fi' => 'fi_FI',  
  585. 'fo' => 'fo_FO',  
  586. 'fr_CA' => 'fr_CA',  
  587. 'fr_FR' => 'fr_FR',  
  588. 'fuc' => 'ff_NG',  
  589. 'fy' => 'fy_NL',  
  590. 'ga' => 'ga_IE',  
  591. 'gl_ES' => 'gl_ES',  
  592. 'gn' => 'gn_PY',  
  593. 'gu' => 'gu_IN',  
  594. 'he_IL' => 'he_IL',  
  595. 'hi_IN' => 'hi_IN',  
  596. 'hr' => 'hr_HR',  
  597. 'hu_HU' => 'hu_HU',  
  598. 'hy' => 'hy_AM',  
  599. 'id_ID' => 'id_ID',  
  600. 'is_IS' => 'is_IS',  
  601. 'it_IT' => 'it_IT',  
  602. 'ja' => 'ja_JP',  
  603. 'jv_ID' => 'jv_ID',  
  604. 'ka_GE' => 'ka_GE',  
  605. 'kin' => 'rw_RW',  
  606. 'kk' => 'kk_KZ',  
  607. 'km' => 'km_kH',  
  608. 'kn' => 'kn_IN',  
  609. 'ko_KR' => 'ko_KR',  
  610. 'ku' => 'ku_TR',  
  611. 'ky_KY' => 'ky_KG',  
  612. 'la' => 'la_Va',  
  613. 'li' => 'li_NL',  
  614. 'lin' => 'ln_CD',  
  615. 'lo' => 'lo_LA',  
  616. 'lt_LT' => 'lt_LT',  
  617. 'lv' => 'lv_LV',  
  618. 'mg_MG' => 'mg_MG',  
  619. 'mk_MK' => 'mk_MK',  
  620. 'ml_IN' => 'ml_IN',  
  621. 'mn' => 'mn_MN',  
  622. 'mr' => 'mr_IN',  
  623. 'mri' => 'mi_NZ',  
  624. 'ms_MY' => 'ms_MY',  
  625. 'my_MM' => 'my_MM',  
  626. 'ne_NP' => 'ne_NP',  
  627. 'nb_NO' => 'nb_NO',  
  628. 'nl_BE' => 'nl_BE',  
  629. 'nl_NL' => 'nl_NL',  
  630. 'nn_NO' => 'nn_NO',  
  631. 'ory' => 'or_IN',  
  632. 'pa_IN' => 'pa_IN',  
  633. 'pl_PL' => 'pl_PL',  
  634. 'ps' => 'ps_AF',  
  635. 'pt_BR' => 'pt_BR',  
  636. 'pt_PT' => 'pt_PT',  
  637. 'ps' => 'ps_AF',  
  638. 'ro_RO' => 'ro_RO',  
  639. 'roh' => 'rm_CH',  
  640. 'ru_RU' => 'ru_RU',  
  641. 'sa_IN' => 'sa_IN',  
  642. 'si_LK' => 'si_LK',  
  643. 'sk_SK' => 'sk_SK',  
  644. 'sl_SI' => 'sl_SI',  
  645. 'so_SO' => 'so_SO',  
  646. 'sq' => 'sq_AL',  
  647. 'sr_RS' => 'sr_RS',  
  648. 'srd' => 'sc_IT',  
  649. 'sv_SE' => 'sv_SE',  
  650. 'sw' => 'sw_KE',  
  651. 'szl' => 'sz_PL',  
  652. 'ta_LK' => 'ta_IN',  
  653. 'ta_IN' => 'ta_IN',  
  654. 'te' => 'te_IN',  
  655. 'tg' => 'tg_TJ',  
  656. 'th' => 'th_TH',  
  657. 'tl' => 'tl_PH',  
  658. 'tuk' => 'tk_TM',  
  659. 'tr_TR' => 'tr_TR',  
  660. 'tt_RU' => 'tt_RU',  
  661. 'tzm' => 'tz_MA',  
  662. 'uk' => 'uk_UA',  
  663. 'ur' => 'ur_PK',  
  664. 'uz_UZ' => 'uz_UZ',  
  665. 'vi' => 'vi_VN',  
  666. 'yor' => 'yo_NG',  
  667. 'zh_CN' => 'zh_CN',  
  668. 'zh_HK' => 'zh_HK',  
  669. 'zh_TW' => 'zh_TW',  
  670. ); 
  671.  
  672. return isset( $facebook_locales[ $language->locale ] ) ? $facebook_locales[ $language->locale ] : false;