| 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 |
* Returns SQL query that fetches the IDs of the objects without language. |
| 18 |
* |
| 19 |
* @since 3.4 |
| 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_objects_with_no_lang_sql( array $language_ids, $limit, array $args = array() ) { |
| 31 |
if ( empty( $args ) ) { |
| 32 |
$args = $this->get_translated_object_types(); |
| 33 |
} |
| 34 |
|
| 35 |
$db = $this->get_db_infos(); |
| 36 |
|
| 37 |
return sprintf( |
| 38 |
"SELECT {$db['table']}.{$db['id_column']} FROM {$db['table']} |
| 39 |
WHERE {$db['table']}.{$db['id_column']} NOT IN ( |
| 40 |
SELECT object_id FROM {$GLOBALS['wpdb']->term_relationships} WHERE term_taxonomy_id IN (%s) |
| 41 |
) |
| 42 |
AND {$db['type_column']} IN (%s) |
| 43 |
%s", |
| 44 |
PLL_Db_Tools::prepare_values_list( $language_ids ), |
| 45 |
PLL_Db_Tools::prepare_values_list( $args ), |
| 46 |
$limit >= 1 ? sprintf( 'LIMIT %d', $limit ) : '' |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Returns true if Polylang manages languages for this object type. |
| 52 |
* |
| 53 |
* @since 3.4 |
| 54 |
* |
| 55 |
* @param string|string[] $object_type Object type (taxonomy name) name or array of object type names. |
| 56 |
* @return bool |
| 57 |
* |
| 58 |
* @phpstan-param non-empty-string|non-empty-string[] $object_type |
| 59 |
*/ |
| 60 |
public function is_translated_object_type( $object_type ) { |
| 61 |
$object_types = $this->get_translated_object_types( false ); |
| 62 |
return ! empty( array_intersect( (array) $object_type, $object_types ) ); |
| 63 |
} |
| 64 |
} |
| 65 |
|