PluginProbe
Polylang / 2.0.12
Polylang v2.0.12
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
← All changes | settings/settings-cpt.php +30 -89 2.82.0.12 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Settings class for custom post types and taxonomies language and translation management
8 5 *
@@ -8,80 +5,37 @@
8 5 *
9 6 * @since 1.8
10 7 */
11 8 class PLL_Settings_CPT extends PLL_Settings_Module {
12 - /**
13 - * Stores the display order priority.
14 - *
15 - * @var int
16 - */
17 - public $priority = 40;
18 9
19 10 /**
20 - * The list of post types to show in the form.
11 + * constructor
21 12 *
22 - * @var array
23 - */
24 - private $post_types;
25 -
26 - /**
27 - * The list of post types to disable in the form.
28 - *
29 - * @var array
30 - */
31 - private $disabled_post_types;
32 -
33 - /**
34 - * The list of taxonomies to show in the form.
35 - *
36 - * @var array
37 - */
38 - private $taxonomies;
39 -
40 - /**
41 - * The list of taxonomies to disable in the form.
42 - *
43 - * @var array
44 - */
45 - private $disabled_taxonomies;
46 -
47 - /**
48 - * Constructor
49 - *
50 13 * @since 1.8
51 14 *
52 15 * @param object $polylang polylang object
53 16 */
54 17 public function __construct( &$polylang ) {
55 - parent::__construct(
56 - $polylang,
57 - array(
58 - 'module' => 'cpt',
59 - 'title' => __( 'Custom post types and Taxonomies', 'polylang' ),
60 - 'description' => __( 'Activate languages and translations management for the custom post types and the taxonomies.', 'polylang' ),
61 - )
62 - );
18 + parent::__construct( $polylang, array(
19 + 'module' => 'cpt',
20 + 'title' => __( 'Custom post types and Taxonomies', 'polylang' ),
21 + 'description' => __( 'Activate the languages and translations management for the custom post types and taxonomies.', 'polylang' ),
22 + ) );
63 23
64 - $public_post_types = get_post_types( array( 'public' => true, '_builtin' => false ) );
24 + // FIXME should be OK when the modules will be loaded from the settings page
25 + $post_types = get_post_types( array( 'public' => true, '_builtin' => false ) );
26 + $post_types = array_diff( $post_types, get_post_types( array( '_pll' => true ) ) );
65 27 /** This filter is documented in include/model.php */
66 - $this->post_types = array_unique( apply_filters( 'pll_get_post_types', $public_post_types, true ) );
28 + $this->post_types = array_unique( apply_filters( 'pll_get_post_types', $post_types, true ) );
67 29
30 + $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
31 + $taxonomies = array_diff( $taxonomies, get_taxonomies( array( '_pll' => true ) ) );
68 32 /** This filter is documented in include/model.php */
69 - $programmatically_active_post_types = array_unique( apply_filters( 'pll_get_post_types', array(), false ) );
70 - $this->disabled_post_types = array_intersect( $programmatically_active_post_types, $this->post_types );
71 -
72 - $public_taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
73 - $public_taxonomies = array_diff( $public_taxonomies, get_taxonomies( array( '_pll' => true ) ) );
74 - /** This filter is documented in include/model.php */
75 - $this->taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', $public_taxonomies, true ) );
76 -
77 - /** This filter is documented in include/model.php */
78 - $programmatically_active_taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', array(), false ) );
79 - $this->disabled_taxonomies = array_intersect( $programmatically_active_taxonomies, $this->taxonomies );
33 + $this->taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', $taxonomies , true ) );
80 34 }
81 35
82 36 /**
83 - * Tells if the module is active
37 + * tells if the module is active
84 38 *
85 39 * @since 1.8
86 40 *
87 41 * @return bool
@@ -90,63 +44,52 @@
90 44 return ! empty( $this->post_types ) || ! empty( $this->taxonomies );
91 45 }
92 46
93 47 /**
94 - * Displays the settings form
48 + * displays the settings form
95 49 *
96 50 * @since 1.8
97 51 */
98 52 protected function form() {
99 53 if ( ! empty( $this->post_types ) ) {?>
100 - <h4><?php esc_html_e( 'Custom post types', 'polylang' ); ?></h4>
101 - <ul class="pll-inline-block-list">
102 - <?php
54 + <h4><?php esc_html_e( 'Custom post types', 'polylang' ) ?></h4>
55 + <ul class="pll-inline-block-list"><?php
103 56 foreach ( $this->post_types as $post_type ) {
104 57 $pt = get_post_type_object( $post_type );
105 58 if ( ! empty( $pt ) ) {
106 - $disabled = in_array( $post_type, $this->disabled_post_types );
107 59 printf(
108 - '<li><label><input name="post_types[%s]" type="checkbox" value="1" %s %s/> %s</label></li>',
60 + '<li><label><input name="post_types[%s]" type="checkbox" value="1" %s /> %s</label></li>',
109 61 esc_attr( $post_type ),
110 - checked( in_array( $post_type, $this->options['post_types'] ) || $disabled, true, false ),
111 - disabled( $disabled, true, false ),
62 + in_array( $post_type, $this->options['post_types'] ) ? 'checked="checked"' :'',
112 63 esc_html( $pt->labels->name )
113 64 );
114 65 }
115 - }
116 - ?>
66 + }?>
117 67 </ul>
118 - <p class="description"><?php esc_html_e( 'Activate languages and translations for custom post types.', 'polylang' ); ?></p>
119 - <?php
68 + <p class="description"><?php esc_html_e( 'Activate languages and translations for custom post types.', 'polylang' );?></p><?php
120 69 }
121 70
122 - if ( ! empty( $this->taxonomies ) ) {
123 - ?>
124 - <h4><?php esc_html_e( 'Custom taxonomies', 'polylang' ); ?></h4>
125 - <ul class="pll-inline-block-list">
126 - <?php
71 + if ( ! empty( $this->taxonomies ) ) {?>
72 + <h4><?php esc_html_e( 'Custom taxonomies', 'polylang' ) ?></h4>
73 + <ul class="pll-inline-block-list"><?php
127 74 foreach ( $this->taxonomies as $taxonomy ) {
128 75 $tax = get_taxonomy( $taxonomy );
129 76 if ( ! empty( $tax ) ) {
130 - $disabled = in_array( $taxonomy, $this->disabled_taxonomies );
131 77 printf(
132 - '<li><label><input name="taxonomies[%s]" type="checkbox" value="1" %s %s/> %s</label></li>',
78 + '<li><label><input name="taxonomies[%s]" type="checkbox" value="1" %s /> %s</label></li>',
133 79 esc_attr( $taxonomy ),
134 - checked( in_array( $taxonomy, $this->options['taxonomies'] ) || $disabled, true, false ),
135 - disabled( $disabled, true, false ),
80 + in_array( $taxonomy, $this->options['taxonomies'] ) ? 'checked="checked"' :'',
136 81 esc_html( $tax->labels->name )
137 82 );
138 83 }
139 - }
140 - ?>
84 + }?>
141 85 </ul>
142 - <p class="description"><?php esc_html_e( 'Activate languages and translations for custom taxonomies.', 'polylang' ); ?></p>
143 - <?php
86 + <p class="description"><?php esc_html_e( 'Activate languages and translations for custom taxonomies.', 'polylang' );?></p><?php
144 87 }
145 88 }
146 89
147 90 /**
148 - * Sanitizes the settings before saving
91 + * sanitizes the settings before saving
149 92 *
150 93 * @since 1.8
151 94 *
152 95 * @param array $options
@@ -151,12 +94,10 @@
151 94 *
152 95 * @param array $options
153 96 */
154 97 protected function update( $options ) {
155 - $newoptions = array();
156 -
157 98 foreach ( array( 'post_types', 'taxonomies' ) as $key ) {
158 99 $newoptions[ $key ] = empty( $options[ $key ] ) ? array() : array_keys( $options[ $key ], 1 );
159 100 }
160 - return $newoptions; // Take care to return only validated options
101 + return $newoptions; // take care to return only validated options
161 102 }
162 103 }