| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* Manages the compatibility with WP Sweep. |
| 8 |
* |
| 9 |
* @since 2.8 |
| 10 |
*/ |
| 11 |
class PLL_WP_Sweep { |
| 12 |
/** |
| 13 |
* Setups actions. |
| 14 |
* |
| 15 |
* @since 2.8 |
| 16 |
*/ |
| 17 |
public function init() { |
| 18 |
add_filter( 'wp_sweep_excluded_taxonomies', array( $this, 'wp_sweep_excluded_taxonomies' ) ); |
| 19 |
add_filter( 'wp_sweep_excluded_termids', array( $this, 'wp_sweep_excluded_termids' ), 0 ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Add 'term_language' and 'term_translations' to excluded taxonomies otherwise terms loose their language and translation group. |
| 24 |
* |
| 25 |
* @since 2.0 |
| 26 |
* |
| 27 |
* @param array $excluded_taxonomies List of taxonomies excluded from sweeping. |
| 28 |
* @return array |
| 29 |
*/ |
| 30 |
public function wp_sweep_excluded_taxonomies( $excluded_taxonomies ) { |
| 31 |
return array_merge( $excluded_taxonomies, array( 'term_language', 'term_translations' ) ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Add the translation of the default taxonomy terms and our language terms to the excluded terms. |
| 36 |
* |
| 37 |
* @since 2.9 |
| 38 |
* |
| 39 |
* @param array $excluded_term_ids List of term ids excluded from sweeping. |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
public function wp_sweep_excluded_termids( $excluded_term_ids ) { |
| 43 |
// We got a list of excluded terms (defaults and parents). Let exclude their translations too. |
| 44 |
$_term_ids = array(); |
| 45 |
|
| 46 |
foreach ( $excluded_term_ids as $excluded_term_id ) { |
| 47 |
$_term_ids = array_merge( $_term_ids, array_values( pll_get_term_translations( $excluded_term_id ) ) ); |
| 48 |
} |
| 49 |
|
| 50 |
$excluded_term_ids = array_merge( $excluded_term_ids, $_term_ids ); |
| 51 |
|
| 52 |
// Add the terms of our languages. |
| 53 |
foreach ( PLL()->model->get_languages_list() as $language ) { |
| 54 |
$excluded_term_ids = array_merge( |
| 55 |
$excluded_term_ids, |
| 56 |
array_values( $language->get_tax_props( 'term_id' ) ) |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
return array_unique( $excluded_term_ids ); |
| 61 |
} |
| 62 |
} |
| 63 |
|