PluginProbe
Polylang / trunk
Polylang vtrunk
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 / src / translatable-object-with-types-trait.php

translatable-object-with-types-trait.php in Polylang trunk, at src/translatable-object-with-types-trait.php

75 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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