PluginProbe
Polylang / 1.4.4
Polylang v1.4.4
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.4.4, at include/plugins-compat.php

189 lines 5.8 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 add_action('widgets_init', array(&$this, 'twenty_fourteen_widgets_init'), 20);
42 }
43
44 /*
45 * WordPress Importer
46 * if WordPress Importer is active, replace the wordpress_importer_init function
47 *
48 * @since 1.2
49 */
50 function maybe_wordpress_importer() {
51 if (class_exists('WP_Import')) {
52 remove_action('admin_init', 'wordpress_importer_init');
53 add_action('admin_init', array(&$this, 'wordpress_importer_init'));
54 }
55 }
56
57 /*
58 * WordPress Importer
59 * loads our child class PLL_WP_Import instead of WP_Import
60 *
61 * @since 1.2
62 */
63 function wordpress_importer_init() {
64 $class = new ReflectionClass('WP_Import');
65 load_plugin_textdomain( 'wordpress-importer', false, basename(dirname( $class->getFileName() )) . '/languages' );
66
67 $GLOBALS['wp_import'] = new PLL_WP_Import();
68 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' ) );
69 }
70
71 /*
72 * WordPress SEO by Yoast
73 * reloads options once the language has been defined to enable translations
74 * useful only when the language is set from content
75 *
76 * @since 1.2
77 */
78 public function wpseo_translate_options() {
79 if (defined('WPSEO_VERSION') && !PLL_ADMIN && did_action('wp_loaded')) {
80 global $wpseo_front;
81 foreach ( get_wpseo_options_arr() as $opt )
82 $wpseo_front->options = array_merge( $wpseo_front->options, (array) get_option( $opt ) );
83 }
84 }
85
86 /*
87 * WordPress SEO by Yoast
88 * removes the language filter for the taxonomy sitemaps
89 *
90 * @since 1.0.3
91 *
92 * @param array $args get_terms arguments
93 * @return array modified list of arguments
94 */
95 public function wpseo_remove_terms_filter($args) {
96 if (defined('WPSEO_VERSION') && isset($GLOBALS['wp_query']->query['sitemap']))
97 $args['lang'] = 0;
98 return $args;
99 }
100
101 /*
102 * Custom field template does check $_REQUEST['post'] to populate the custom fields values
103 *
104 * @since 1.0.2
105 *
106 * @param string $post_type unused
107 * @param object $post current post object
108 */
109 public function cft_copy($post_type, $post) {
110 global $custom_field_template;
111 if (isset($custom_field_template, $_REQUEST['from_post'], $_REQUEST['new_lang']) && !empty($post))
112 $_REQUEST['post'] = $post->ID;
113 }
114
115 /*
116 * rewrites the function Featured_Content::get_featured_post_ids()
117 *
118 * @since 1.4
119 *
120 * @param array $ids featured posts ids
121 * @return array modified featured posts ids (include all languages)
122 */
123 public function twenty_fourteen_featured_content_ids($featured_ids) {
124 if (false !== $featured_ids)
125 return $featured_ids;
126
127 $settings = Featured_Content::get_setting();
128
129 if (!$term = get_term_by( 'name', $settings['tag-name'], 'post_tag' ))
130 return $featured_ids;
131
132 // get fearured tag translations
133 $tags = $GLOBALS['polylang']->model->get_translations('term' ,$term->term_id);
134 $ids = array();
135
136 // Query for featured posts in all languages
137 // one query per language to get the correct number of posts per language
138 foreach ($tags as $tag) {
139 $_ids = get_posts(array(
140 'lang' => 0, // avoid language filters
141 'fields' => 'ids',
142 'numberposts' => $settings['quantity'],
143 'tax_query' => array(array(
144 'taxonomy' => 'post_tag',
145 'terms' => (int) $tag,
146 )),
147 ));
148
149 $ids = array_merge($ids, $_ids);
150 }
151
152 $ids = array_map( 'absint', $ids );
153 set_transient( 'featured_content_ids', $ids );
154
155 return $ids;
156 }
157
158 /*
159 * translates the featured tag id in featured content settings
160 * mainly to allow hiding it when requested in featured content options
161 * acts only on frontend
162 *
163 * @since 1.4
164 *
165 * @param array $settings featured content settings
166 * @return array modified $settings
167 */
168 public function twenty_fourteen_option_featured_content($settings) {
169 if ($settings['tag-id'] && $tr = pll_get_term($settings['tag-id']))
170 $settings['tag-id'] = $tr;
171
172 return $settings;
173 }
174
175 /*
176 * overwrites the Twenty Fourteen Ephemera widget to allow translating strings when setting the language by content
177 *
178 * @since 1.4.1
179 */
180 public function twenty_fourteen_widgets_init() {
181 // overwrites the Twenty Fourteen Ephemera widget to allow translating strings when setting the language by content
182 // FIXME should be removed when WP >= 3.9 See http://core.trac.wordpress.org/ticket/27069
183 if (class_exists('Twenty_Fourteen_Ephemera_Widget')) {
184 unregister_widget('Twenty_Fourteen_Ephemera_Widget');
185 register_widget('PLL_Widget_Twenty_Fourteen_Ephemera');
186 }
187 }
188 }
189