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