PLL_Admin_Static_Pages

Manages the static front page and the page for posts on admin side.

Defined (1)

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

/admin/admin-static-pages.php  
  1. class PLL_Admin_Static_Pages extends PLL_Static_Pages { 
  2.  
  3. /** 
  4. * constructor: setups filters and actions 
  5. * @since 1.8 
  6. * @param object $polylang 
  7. */ 
  8. public function __construct( &$polylang ) { 
  9. parent::__construct( $polylang ); 
  10.  
  11. // add post state for translations of the front page and posts page 
  12. add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 ); 
  13.  
  14. // refresh language cache when a static front page has been translated 
  15. add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 ); 
  16.  
  17. // checks if chosen page on front is translated 
  18. add_filter( 'pre_update_option_page_on_front', array( $this, 'update_page_on_front' ), 10, 2 ); 
  19.  
  20. // Prevents WP resetting the option 
  21. add_filter( 'pre_update_option_show_on_front', array( $this, 'update_show_on_front' ), 10, 2 ); 
  22.  
  23. /** 
  24. * add post state for translations of the front page and posts page 
  25. * @since 1.8 
  26. * @param array $post_states 
  27. * @param object $post 
  28. * @return array 
  29. */ 
  30. public function display_post_states( $post_states, $post ) { 
  31. if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) { 
  32. $post_states['page_on_front'] = __( 'Front Page' ); 
  33.  
  34. if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_for_posts' ) ) ) ) { 
  35. $post_states['page_for_posts'] = __( 'Posts Page' ); 
  36.  
  37. return $post_states; 
  38.  
  39. /** 
  40. * refresh language cache when a static front page has been translated 
  41. * @since 1.8 
  42. * @param int $post_id not used 
  43. * @param object $post not used 
  44. * @param array $translations 
  45. */ 
  46. public function pll_save_post( $post_id, $post, $translations ) { 
  47. if ( in_array( $this->page_on_front, $translations ) ) { 
  48. $this->model->clean_languages_cache(); 
  49.  
  50. /** 
  51. * prevents choosing an untranslated static front page 
  52. * displays an error message 
  53. * @since 1.6 
  54. * @param int $page_id new page on front page id 
  55. * @param int $old_id old page on front page_id 
  56. * @return int 
  57. */ 
  58. public function update_page_on_front( $page_id, $old_id ) { 
  59. if ( $page_id ) { 
  60. $translations = count( $this->model->post->get_translations( $page_id ) ); 
  61. $languages = count( $this->model->get_languages_list() ); 
  62.  
  63. if ( $languages > 1 && $translations != $languages ) { 
  64. $page_id = $old_id; 
  65. add_settings_error( 'reading', 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) ); 
  66.  
  67. return $page_id; 
  68.  
  69. /** 
  70. * Prevents WP resetting the option if the admin language filter is active for a language with no pages 
  71. * @since 1.9.3 
  72. * @param string $value 
  73. * @param string $old_value 
  74. * @return string 
  75. */ 
  76. public function update_show_on_front( $value, $old_value ) { 
  77. if ( ! empty( $GLOBALS['pagenow'] ) && 'options-reading.php' === $GLOBALS['pagenow'] && 'posts' === $value && ! get_pages() && get_pages( array( 'lang' => '' ) ) ) { 
  78. $value = $old_value; 
  79. return $value;