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
polylang / settings / settings-cpt.php

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

104 lines 3.3 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"><?php
56 foreach ( $this->post_types as $post_type ) {
57 $pt = get_post_type_object( $post_type );
58 if ( ! empty( $pt ) ) {
59 printf(
60 '<li><label><input name="post_types[%s]" type="checkbox" value="1" %s /> %s</label></li>',
61 esc_attr( $post_type ),
62 in_array( $post_type, $this->options['post_types'] ) ? 'checked="checked"' :'',
63 esc_html( $pt->labels->name )
64 );
65 }
66 }?>
67 </ul>
68 <p class="description"><?php esc_html_e( 'Activate languages and translations for custom post types.', 'polylang' );?></p><?php
69 }
70
71 if ( ! empty( $this->taxonomies ) ) {?>
72 <h4><?php esc_html_e( 'Custom taxonomies', 'polylang' ) ?></h4>
73 <ul class="pll-inline-block-list"><?php
74 foreach ( $this->taxonomies as $taxonomy ) {
75 $tax = get_taxonomy( $taxonomy );
76 if ( ! empty( $tax ) ) {
77 printf(
78 '<li><label><input name="taxonomies[%s]" type="checkbox" value="1" %s /> %s</label></li>',
79 esc_attr( $taxonomy ),
80 in_array( $taxonomy, $this->options['taxonomies'] ) ? 'checked="checked"' :'',
81 esc_html( $tax->labels->name )
82 );
83 }
84 }?>
85 </ul>
86 <p class="description"><?php esc_html_e( 'Activate languages and translations for custom taxonomies.', 'polylang' );?></p><?php
87 }
88 }
89
90 /**
91 * sanitizes the settings before saving
92 *
93 * @since 1.8
94 *
95 * @param array $options
96 */
97 protected function update( $options ) {
98 foreach ( array( 'post_types', 'taxonomies' ) as $key ) {
99 $newoptions[ $key ] = empty( $options[ $key ] ) ? array() : array_keys( $options[ $key ], 1 );
100 }
101 return $newoptions; // take care to return only validated options
102 }
103 }
104