| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
defined( 'ABSPATH' ) || exit; |
| 7 |
|
| 8 |
/** |
| 9 |
* Trait to use for objects that can have one or more types. |
| 10 |
* This must be used with {@see PLL_Translatable_Object_With_Types_Interface}. |
| 11 |
* |
| 12 |
* @since 3.4 |
| 13 |
*/ |
| 14 |
trait PLL_Translatable_Object_With_Types_Trait { |
| 15 |
|
| 16 |
/** |
| 17 |
* Fetches the IDs of the objects without language. |
| 18 |
* |
| 19 |
* @since 3.7 |
| 20 |
* |
| 21 |
* @param int[] $language_ids List of language `term_taxonomy_id`. |
| 22 |
* @param int $limit Max number of objects to return. `-1` to return all of them. |
| 23 |
* @param array $args An array of translated object types. |
| 24 |
* @return string[] |
| 25 |
* |
| 26 |
* @phpstan-param array<positive-int> $language_ids |
| 27 |
* @phpstan-param -1|positive-int $limit |
| 28 |
* @phpstan-param array<string> $args |
| 29 |
*/ |
| 30 |
protected function get_raw_objects_with_no_lang( array $language_ids, $limit, array $args = array() ) { |
| 31 |
global $wpdb; |
| 32 |
|
| 33 |
if ( empty( $args ) ) { |
| 34 |
$args = $this->get_translated_object_types(); |
| 35 |
} |
| 36 |
|
| 37 |
$db = $this->get_db_infos(); |
| 38 |
|
| 39 |
return $wpdb->get_col( |
| 40 |
$wpdb->prepare( |
| 41 |
sprintf( |
| 42 |
"SELECT %%i FROM %%i |
| 43 |
WHERE %%i NOT IN ( |
| 44 |
SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (%s) |
| 45 |
) |
| 46 |
AND %%i IN (%s) |
| 47 |
LIMIT %%d", |
| 48 |
implode( ',', array_fill( 0, count( $language_ids ), '%d' ) ), |
| 49 |
implode( ',', array_fill( 0, count( $args ), '%s' ) ) |
| 50 |
), |
| 51 |
array_merge( |
| 52 |
array( $db['id_column'], $db['table'], $db['id_column'] ), |
| 53 |
$language_ids, |
| 54 |
array( $db['type_column'] ), |
| 55 |
$args, |
| 56 |
array( $limit >= 1 ? $limit : 4294967295 ) |
| 57 |
) |
| 58 |
) |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Returns true if Polylang manages languages for this object type. |
| 64 |
* |
| 65 |
* @since 3.4 |
| 66 |
* |
| 67 |
* @param string|string[] $object_type Object type (taxonomy name) name or array of object type names. |
| 68 |
* @return bool |
| 69 |
*/ |
| 70 |
public function is_translated_object_type( $object_type ) { |
| 71 |
$object_types = $this->get_translated_object_types( false ); |
| 72 |
return ! empty( array_intersect( (array) $object_type, $object_types ) ); |
| 73 |
} |
| 74 |
} |
| 75 |
|