PluginProbe
Polylang / 1.5.5
Polylang v1.5.5
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / plugins-compat.php

plugins-compat.php in Polylang 1.5.5, at include/plugins-compat.php

209 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * manages compatibility with 3rd party plugins (and themes)
5 * this class is available as soon as the plugin is loaded
6 *
7 * @since 1.0
8 */
9 class PLL_Plugins_Compat {
10
11 /*
12 * constructor
13 *
14 * @since 1.0
15 */
16 public function __construct() {
17 // WordPress Importer
18 add_action('init', array(&$this, 'maybe_wordpress_importer'));
19
20 // YARPP
21 // just makes YARPP aware of the language taxonomy (after Polylang registered it)
22 add_action('init', create_function('',"\$GLOBALS['wp_taxonomies']['language']->yarpp_support = 1;"), 20);
23
24 // WordPress SEO by Yoast
25 add_action('pll_language_defined', array(&$this, 'wpseo_translate_options'));
26 add_filter('get_terms_args', array(&$this, 'wpseo_remove_terms_filter'));
27 add_filter('pll_home_url_white_list', create_function('$arr', "return array_merge(\$arr, array(array('file' => 'wordpress-seo')));"));
28
29 // Custom field template
30 add_action('add_meta_boxes', array(&$this, 'cft_copy'), 10, 2);
31
32 // Aqua Resizer
33 add_filter('pll_home_url_black_list', create_function('$arr', "return array_merge(\$arr, array(array('function' => 'aq_resize')));"));
34
35 // Twenty Fourteen
36 add_filter('transient_featured_content_ids', array(&$this, 'twenty_fourteen_featured_content_ids'));
37
38 if (!PLL_ADMIN)
39 add_filter('option_featured-content', array(&$this, 'twenty_fourteen_option_featured_content'));
40
41 // Jetpack 3
42 add_action('jetpack_widget_get_top_posts', array(&$this, 'jetpack_widget_get_top_posts'), 10, 3);
43 add_filter('grunion_contact_form_field_html', array(&$this, 'grunion_contact_form_field_html_filter'), 10, 3);
44 }
45
46 /*
47 * WordPress Importer
48 * if WordPress Importer is active, replace the wordpress_importer_init function
49 *
50 * @since 1.2
51 */
52 function maybe_wordpress_importer() {
53 if (class_exists('WP_Import')) {
54 remove_action('admin_init', 'wordpress_importer_init');
55 add_action('admin_init', array(&$this, 'wordpress_importer_init'));
56 }
57 }
58
59 /*
60 * WordPress Importer
61 * loads our child class PLL_WP_Import instead of WP_Import
62 *
63 * @since 1.2
64 */
65 function wordpress_importer_init() {
66 $class = new ReflectionClass('WP_Import');
67 load_plugin_textdomain( 'wordpress-importer', false, basename(dirname( $class->getFileName() )) . '/languages' );
68
69 $GLOBALS['wp_import'] = new PLL_WP_Import();
70 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' ) );
71 }
72
73 /*
74 * WordPress SEO by Yoast
75 * reloads options once the language has been defined to enable translations
76 * useful only when the language is set from content
77 *
78 * @since 1.2
79 */
80 public function wpseo_translate_options() {
81 if (defined('WPSEO_VERSION') && !PLL_ADMIN && did_action('wp_loaded')) {
82 global $wpseo_front;
83 $options = version_compare(WPSEO_VERSION, '1.5', '<') ? get_wpseo_options_arr() : WPSEO_Options::get_option_names();
84 foreach ( $options as $opt )
85 $wpseo_front->options = array_merge( $wpseo_front->options, (array) get_option( $opt ) );
86 }
87 }
88
89 /*
90 * WordPress SEO by Yoast
91 * removes the language filter for the taxonomy sitemaps
92 *
93 * @since 1.0.3
94 *
95 * @param array $args get_terms arguments
96 * @return array modified list of arguments
97 */
98 public function wpseo_remove_terms_filter($args) {
99 if (defined('WPSEO_VERSION') && isset($GLOBALS['wp_query']->query['sitemap']))
100 $args['lang'] = 0;
101 return $args;
102 }
103
104 /*
105 * Custom field template does check $_REQUEST['post'] to populate the custom fields values
106 *
107 * @since 1.0.2
108 *
109 * @param string $post_type unused
110 * @param object $post current post object
111 */
112 public function cft_copy($post_type, $post) {
113 global $custom_field_template;
114 if (isset($custom_field_template, $_REQUEST['from_post'], $_REQUEST['new_lang']) && !empty($post))
115 $_REQUEST['post'] = $post->ID;
116 }
117
118 /*
119 * rewrites the function Featured_Content::get_featured_post_ids()
120 *
121 * @since 1.4
122 *
123 * @param array $ids featured posts ids
124 * @return array modified featured posts ids (include all languages)
125 */
126 public function twenty_fourteen_featured_content_ids($featured_ids) {
127 if (false !== $featured_ids)
128 return $featured_ids;
129
130 $settings = Featured_Content::get_setting();
131
132 if (!$term = get_term_by( 'name', $settings['tag-name'], 'post_tag' ))
133 return $featured_ids;
134
135 // get featured tag translations
136 $tags = $GLOBALS['polylang']->model->get_translations('term' ,$term->term_id);
137 $ids = array();
138
139 // Query for featured posts in all languages
140 // one query per language to get the correct number of posts per language
141 foreach ($tags as $tag) {
142 $_ids = get_posts(array(
143 'lang' => 0, // avoid language filters
144 'fields' => 'ids',
145 'numberposts' => Featured_Content::$max_posts,
146 'tax_query' => array(array(
147 'taxonomy' => 'post_tag',
148 'terms' => (int) $tag,
149 )),
150 ));
151
152 $ids = array_merge($ids, $_ids);
153 }
154
155 $ids = array_map( 'absint', $ids );
156 set_transient( 'featured_content_ids', $ids );
157
158 return $ids;
159 }
160
161 /*
162 * translates the featured tag id in featured content settings
163 * mainly to allow hiding it when requested in featured content options
164 * acts only on frontend
165 *
166 * @since 1.4
167 *
168 * @param array $settings featured content settings
169 * @return array modified $settings
170 */
171 public function twenty_fourteen_option_featured_content($settings) {
172 if ($settings['tag-id'] && $tr = pll_get_term($settings['tag-id']))
173 $settings['tag-id'] = $tr;
174
175 return $settings;
176 }
177
178 /*
179 * adapted from the same function in jetpack-3.0.2/3rd-party/wpml.php
180 *
181 * @since 1.5.4
182 */
183 public function jetpack_widget_get_top_posts( $posts, $post_ids, $count ) {
184 foreach ( $posts as $k => $post ) {
185 if (pll_current_language() !== pll_get_post_language($post['post_id']))
186 unset( $posts[ $k ] );
187 }
188
189 return $posts;
190 }
191
192 /*
193 * adapted from the same function in jetpack-3.0.2/3rd-party/wpml.php
194 * keeps using 'icl_translate' as the function registers the string
195 *
196 * @since 1.5.4
197 */
198 public function grunion_contact_form_field_html_filter( $r, $field_label, $id ){
199 if ( function_exists( 'icl_translate' ) ) {
200 if ( pll_current_language() !== pll_default_language() ) {
201 $label_translation = icl_translate( 'jetpack ', $field_label . '_label', $field_label );
202 $r = str_replace( $field_label, $label_translation, $r );
203 }
204 }
205
206 return $r;
207 }
208 }
209