PluginProbe
Polylang / 2.2
Polylang v2.2
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.2, at settings/settings-cpt.php

111 lines 3.4 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
10 /**
11 * Constructor
12 *
13 * @since 1.8
14 *
15 * @param object $polylang polylang object
16 */
17 public function __construct( &$polylang ) {
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 ) );
23
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 ) ) );
27 /** This filter is documented in include/model.php */
28 $this->post_types = array_unique( apply_filters( 'pll_get_post_types', $post_types, true ) );
29
30 $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
31 $taxonomies = array_diff( $taxonomies, get_taxonomies( array( '_pll' => true ) ) );
32 /** This filter is documented in include/model.php */
33 $this->taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', $taxonomies , true ) );
34 }
35
36 /**
37 * Tells if the module is active
38 *
39 * @since 1.8
40 *
41 * @return bool
42 */
43 public function is_active() {
44 return ! empty( $this->post_types ) || ! empty( $this->taxonomies );
45 }
46
47 /**
48 * Displays the settings form
49 *
50 * @since 1.8
51 */
52 protected function form() {
53 if ( ! empty( $this->post_types ) ) {?>
54 <h4><?php esc_html_e( 'Custom post types', 'polylang' ); ?></h4>
55 <ul class="pll-inline-block-list">
56 <?php
57 foreach ( $this->post_types as $post_type ) {
58 $pt = get_post_type_object( $post_type );
59 if ( ! empty( $pt ) ) {
60 printf(
61 '<li><label><input name="post_types[%s]" type="checkbox" value="1" %s /> %s</label></li>',
62 esc_attr( $post_type ),
63 in_array( $post_type, $this->options['post_types'] ) ? 'checked="checked"' : '',
64 esc_html( $pt->labels->name )
65 );
66 }
67 }
68 ?>
69 </ul>
70 <p class="description"><?php esc_html_e( 'Activate languages and translations for custom post types.', 'polylang' ); ?></p>
71 <?php
72 }
73
74 if ( ! empty( $this->taxonomies ) ) {
75 ?>
76 <h4><?php esc_html_e( 'Custom taxonomies', 'polylang' ); ?></h4>
77 <ul class="pll-inline-block-list">
78 <?php
79 foreach ( $this->taxonomies as $taxonomy ) {
80 $tax = get_taxonomy( $taxonomy );
81 if ( ! empty( $tax ) ) {
82 printf(
83 '<li><label><input name="taxonomies[%s]" type="checkbox" value="1" %s /> %s</label></li>',
84 esc_attr( $taxonomy ),
85 in_array( $taxonomy, $this->options['taxonomies'] ) ? 'checked="checked"' : '',
86 esc_html( $tax->labels->name )
87 );
88 }
89 }
90 ?>
91 </ul>
92 <p class="description"><?php esc_html_e( 'Activate languages and translations for custom taxonomies.', 'polylang' ); ?></p>
93 <?php
94 }
95 }
96
97 /**
98 * Sanitizes the settings before saving
99 *
100 * @since 1.8
101 *
102 * @param array $options
103 */
104 protected function update( $options ) {
105 foreach ( array( 'post_types', 'taxonomies' ) as $key ) {
106 $newoptions[ $key ] = empty( $options[ $key ] ) ? array() : array_keys( $options[ $key ], 1 );
107 }
108 return $newoptions; // Take care to return only validated options
109 }
110 }
111