PluginProbe
Polylang / 3.8.8
Polylang v3.8.8
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 / Model / Post_Types.php

Post_Types.php in Polylang 3.8.8, at src/Model/Post_Types.php

70 lines 1.9 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 namespace WP_Syntex\Polylang\Model;
7
8 use PLL_Translated_Post;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Model for post types translated by Polylang.
14 *
15 * @since 3.7
16 */
17 class Post_Types {
18 /**
19 * Translated post model.
20 *
21 * @var PLL_Translated_Post
22 */
23 public $translated_object;
24
25 /**
26 * Constructor.
27 *
28 * @since 3.7
29 *
30 * @param PLL_Translated_Post $translated_object Posts model.
31 */
32 public function __construct( PLL_Translated_Post $translated_object ) {
33 $this->translated_object = $translated_object;
34 }
35
36 /**
37 * Returns post types that need to be translated.
38 * The post types list is cached for better better performance.
39 * The method waits for 'after_setup_theme' to apply the cache
40 * to allow themes adding the filter in functions.php.
41 *
42 * @since 1.2
43 * @since 3.7 Moved from `PLL_Model::get_translated_post_types()` to `WP_Syntex\Polylang\Model\Taxonomies::get_translated()`.
44 *
45 * @param bool $filter True if we should return only valid registered post types.
46 * @return string[] Post type names for which Polylang manages languages and translations.
47 */
48 public function get_translated( $filter = true ): array {
49 return $this->translated_object->get_translated_object_types( $filter );
50 }
51
52 /**
53 * Returns true if Polylang manages languages and translations for this post type.
54 *
55 * @since 1.2
56 * @since 3.7 Moved from `PLL_Model::is_translated_post_type()` to `WP_Syntex\Polylang\Model\Taxonomies::is_translated()`.
57 *
58 * @param string|string[] $post_type Post type name or array of post type names.
59 * @return bool
60 */
61 public function is_translated( $post_type ): bool {
62 if ( empty( array_filter( (array) $post_type ) ) ) {
63 return false;
64 }
65
66 /** @phpstan-var non-empty-array<non-empty-string>|non-empty-string $post_type */
67 return $this->translated_object->is_translated_object_type( $post_type );
68 }
69 }
70