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