PluginProbe
Polylang / 2.3.9
Polylang v2.3.9
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 / settings / settings-cpt.php

settings-cpt.php in Polylang 2.3.9, at settings/settings-cpt.php

122 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Settings class for custom post types and taxonomies language and translation management
5 *
6 * @since 1.8
7 */
8 class PLL_Settings_CPT extends PLL_Settings_Module {
9 private $post_types, $disabled_post_types, $taxonomies, $disabled_taxonomies;
10
11 /**
12 * Constructor
13 *
14 * @since 1.8
15 *
16 * @param object $polylang polylang object
17 */
18 public function __construct( &$polylang ) {
19 parent::__construct( $polylang, array(
20 'module' => 'cpt',
21 'title' => __( 'Custom post types and Taxonomies', 'polylang' ),
22 'description' => __( 'Activate the languages and translations management for the custom post types and taxonomies.', 'polylang' ),
23 ) );
24
25 $public_post_types = get_post_types( array( 'public' => true, '_builtin' => false ) );
26 /** This filter is documented in include/model.php */
27 $this->post_types = array_unique( apply_filters( 'pll_get_post_types', $public_post_types, true ) );
28
29 $programmatically_active_post_types = array_unique( apply_filters( 'pll_get_post_types', array(), false ) );
30 /** This filter is documented in include/model.php */
31 $this->disabled_post_types = array_intersect( $programmatically_active_post_types, $this->post_types );
32
33 $public_taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
34 $public_taxonomies = array_diff( $public_taxonomies, get_taxonomies( array( '_pll' => true ) ) );
35 /** This filter is documented in include/model.php */
36 $this->taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', $public_taxonomies, true ) );
37
38 $programmatically_active_taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', array(), false ) );
39 /** This filter is documented in include/model.php */
40 $this->disabled_taxonomies = array_intersect( $programmatically_active_taxonomies, $this->taxonomies );
41 }
42
43 /**
44 * Tells if the module is active
45 *
46 * @since 1.8
47 *
48 * @return bool
49 */
50 public function is_active() {
51 return ! empty( $this->post_types ) || ! empty( $this->taxonomies );
52 }
53
54 /**
55 * Displays the settings form
56 *
57 * @since 1.8
58 */
59 protected function form() {
60 if ( ! empty( $this->post_types ) ) {?>
61 <h4><?php esc_html_e( 'Custom post types', 'polylang' ); ?></h4>
62 <ul class="pll-inline-block-list">
63 <?php
64 foreach ( $this->post_types as $post_type ) {
65 $pt = get_post_type_object( $post_type );
66 if ( ! empty( $pt ) ) {
67 $disabled = in_array( $post_type, $this->disabled_post_types );
68 printf(
69 '<li><label><input name="post_types[%s]" type="checkbox" value="1" %s %s/> %s</label></li>',
70 esc_attr( $post_type ),
71 in_array( $post_type, $this->options['post_types'] ) || $disabled ? 'checked="checked"' : '',
72 $disabled ? 'disabled="disabled"' : '',
73 esc_html( $pt->labels->name )
74 );
75 }
76 }
77 ?>
78 </ul>
79 <p class="description"><?php esc_html_e( 'Activate languages and translations for custom post types.', 'polylang' ); ?></p>
80 <?php
81 }
82
83 if ( ! empty( $this->taxonomies ) ) {
84 ?>
85 <h4><?php esc_html_e( 'Custom taxonomies', 'polylang' ); ?></h4>
86 <ul class="pll-inline-block-list">
87 <?php
88 foreach ( $this->taxonomies as $taxonomy ) {
89 $tax = get_taxonomy( $taxonomy );
90 if ( ! empty( $tax ) ) {
91 $disabled = in_array( $taxonomy, $this->disabled_taxonomies );
92 printf(
93 '<li><label><input name="taxonomies[%s]" type="checkbox" value="1" %s %s/> %s</label></li>',
94 esc_attr( $taxonomy ),
95 in_array( $taxonomy, $this->options['taxonomies'] ) || $disabled ? 'checked="checked"' : '',
96 $disabled ? 'disabled="disabled"' : '',
97 esc_html( $tax->labels->name )
98 );
99 }
100 }
101 ?>
102 </ul>
103 <p class="description"><?php esc_html_e( 'Activate languages and translations for custom taxonomies.', 'polylang' ); ?></p>
104 <?php
105 }
106 }
107
108 /**
109 * Sanitizes the settings before saving
110 *
111 * @since 1.8
112 *
113 * @param array $options
114 */
115 protected function update( $options ) {
116 foreach ( array( 'post_types', 'taxonomies' ) as $key ) {
117 $newoptions[ $key ] = empty( $options[ $key ] ) ? array() : array_keys( $options[ $key ], 1 );
118 }
119 return $newoptions; // Take care to return only validated options
120 }
121 }
122