PLL_Admin_Filters_Post_Base

Some common code for PLL_Admin_Filters_Post and PLL_Admin_Filters_Media.

Defined (1)

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

/admin/admin-filters-post-base.php  
  1. abstract class PLL_Admin_Filters_Post_Base { 
  2. public $links, $model, $pref_lang; 
  3.  
  4. /** 
  5. * constructor: setups filters and actions 
  6. * @since 1.2 
  7. * @param object $polylang 
  8. */ 
  9. public function __construct( &$polylang ) { 
  10. $this->links = &$polylang->links; 
  11. $this->model = &$polylang->model; 
  12. $this->pref_lang = &$polylang->pref_lang; 
  13.  
  14. /** 
  15. * allows to set a language by default for posts if it has no language yet 
  16. * @since 1.5 
  17. * @param int $post_id 
  18. */ 
  19. public function set_default_language( $post_id ) { 
  20. if ( ! $this->model->post->get_language( $post_id ) ) { 
  21. if ( isset( $_GET['new_lang'] ) && $lang = $this->model->get_language( $_GET['new_lang'] ) ) { 
  22. $this->model->post->set_language( $post_id, $lang ); 
  23.  
  24. elseif ( ( $parent_id = wp_get_post_parent_id( $post_id ) ) && $parent_lang = $this->model->post->get_language( $parent_id ) ) { 
  25. $this->model->post->set_language( $post_id, $parent_lang ); 
  26.  
  27. else { 
  28. $this->model->post->set_language( $post_id, $this->pref_lang ); 
  29.  
  30. /** 
  31. * save translations from language metabox 
  32. * @since 1.5 
  33. * @param int $post_id 
  34. * @param array $arr 
  35. * @return array 
  36. */ 
  37. protected function save_translations( $post_id, $arr ) { 
  38. // security check 
  39. // as 'wp_insert_post' can be called from outside WP admin 
  40. check_admin_referer( 'pll_language', '_pll_nonce' ); 
  41.  
  42. // save translations after checking the translated post is in the right language 
  43. foreach ( $arr as $lang => $tr_id ) { 
  44. $translations[ $lang ] = ( $tr_id && $this->model->post->get_language( (int) $tr_id )->slug == $lang ) ? (int) $tr_id : 0; 
  45.  
  46. $this->model->post->save_translations( $post_id, $translations ); 
  47. return $translations;