PLL_Settings_CPT

Settings class for custom post types and taxonomies language and translation management.

Defined (1)

The class is defined in the following location(s).

/settings/settings-cpt.php  
  1. class PLL_Settings_CPT extends PLL_Settings_Module { 
  2.  
  3. /** 
  4. * constructor 
  5. * @since 1.8 
  6. * @param object $polylang polylang object 
  7. */ 
  8. public function __construct( &$polylang ) { 
  9. parent::__construct( $polylang, array( 
  10. 'module' => 'cpt',  
  11. 'title' => __( 'Custom post types and Taxonomies', 'polylang' ),  
  12. 'description' => __( 'Activate the languages and translations management for the custom post types and taxonomies.', 'polylang' ),  
  13. ) ); 
  14.  
  15. // FIXME should be OK when the modules will be loaded from the settings page 
  16. $post_types = get_post_types( array( 'public' => true, '_builtin' => false ) ); 
  17. $post_types = array_diff( $post_types, get_post_types( array( '_pll' => true ) ) ); 
  18. /** This filter is documented in include/model.php */ 
  19. $this->post_types = array_unique( apply_filters( 'pll_get_post_types', $post_types, true ) ); 
  20.  
  21. $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) ); 
  22. $taxonomies = array_diff( $taxonomies, get_taxonomies( array( '_pll' => true ) ) ); 
  23. /** This filter is documented in include/model.php */ 
  24. $this->taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', $taxonomies , true ) ); 
  25.  
  26. /** 
  27. * tells if the module is active 
  28. * @since 1.8 
  29. * @return bool 
  30. */ 
  31. public function is_active() { 
  32. return ! empty( $this->post_types ) || ! empty( $this->taxonomies ); 
  33.  
  34. /** 
  35. * displays the settings form 
  36. * @since 1.8 
  37. */ 
  38. protected function form() { 
  39. if ( ! empty( $this->post_types ) ) {?> 
  40. <h4><?php esc_html_e( 'Custom post types', 'polylang' ) ?></h4> 
  41. <ul class="pll-inline-block-list"><?php 
  42. foreach ( $this->post_types as $post_type ) { 
  43. $pt = get_post_type_object( $post_type ); 
  44. if ( ! empty( $pt ) ) { 
  45. printf( 
  46. '<li><label><input name="post_types[%s]" type="checkbox" value="1" %s /> %s</label></li>',  
  47. esc_attr( $post_type ),  
  48. in_array( $post_type, $this->options['post_types'] ) ? 'checked="checked"' :'',  
  49. esc_html( $pt->labels->name ) 
  50. ); 
  51. }?> 
  52. </ul> 
  53. <p class="description"><?php esc_html_e( 'Activate languages and translations for custom post types.', 'polylang' );?></p><?php 
  54.  
  55. if ( ! empty( $this->taxonomies ) ) {?> 
  56. <h4><?php esc_html_e( 'Custom taxonomies', 'polylang' ) ?></h4> 
  57. <ul class="pll-inline-block-list"><?php 
  58. foreach ( $this->taxonomies as $taxonomy ) { 
  59. $tax = get_taxonomy( $taxonomy ); 
  60. if ( ! empty( $tax ) ) { 
  61. printf( 
  62. '<li><label><input name="taxonomies[%s]" type="checkbox" value="1" %s /> %s</label></li>',  
  63. esc_attr( $taxonomy ),  
  64. in_array( $taxonomy, $this->options['taxonomies'] ) ? 'checked="checked"' :'',  
  65. esc_html( $tax->labels->name ) 
  66. ); 
  67. }?> 
  68. </ul> 
  69. <p class="description"><?php esc_html_e( 'Activate languages and translations for custom taxonomies.', 'polylang' );?></p><?php 
  70.  
  71. /** 
  72. * sanitizes the settings before saving 
  73. * @since 1.8 
  74. * @param array $options 
  75. */ 
  76. protected function update( $options ) { 
  77. foreach ( array( 'post_types', 'taxonomies' ) as $key ) { 
  78. $newoptions[ $key ] = empty( $options[ $key ] ) ? array() : array_keys( $options[ $key ], 1 ); 
  79. return $newoptions; // take care to return only validated options