PLL_Static_Pages

Base class to manage the static front page and the page for posts.

Defined (1)

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

/include/static-pages.php  
  1. abstract class PLL_Static_Pages { 
  2. public $model, $options; 
  3. public $page_on_front, $page_for_posts; 
  4.  
  5. /** 
  6. * constructor: setups filters and actions 
  7. * @since 1.8 
  8. * @param object $polylang 
  9. */ 
  10. public function __construct( &$polylang ) { 
  11. $this->model = &$polylang->model; 
  12. $this->options = &$polylang->options; 
  13.  
  14. $this->init(); 
  15.  
  16. // Modifies the page link in case the front page is not in the default language 
  17. add_filter( 'page_link', array( $this, 'page_link' ), 20, 2 ); 
  18.  
  19. // clean the languages cache when editing page of front, page for posts 
  20. add_action( 'update_option_page_on_front', array( $this->model, 'clean_languages_cache' ) ); 
  21. add_action( 'update_option_page_for_posts', array( $this->model, 'clean_languages_cache' ) ); 
  22.  
  23. // refresh rewrite rules when the page on front is modified 
  24. add_action( 'update_option_page_on_front', 'flush_rewrite_rules' ); 
  25.  
  26. /** 
  27. * stores the page on front and page for posts ids 
  28. * @since 1.8 
  29. */ 
  30. public function init() { 
  31. if ( 'page' == get_option( 'show_on_front' ) ) { 
  32. $this->page_on_front = get_option( 'page_on_front' ); 
  33. $this->page_for_posts = get_option( 'page_for_posts' ); 
  34.  
  35. else { 
  36. $this->page_on_front = 0; 
  37. $this->page_for_posts = 0; 
  38.  
  39. /** 
  40. * Modifies the page link in case the front page is not in the default language 
  41. * @since 0.7.2 
  42. * @param string $link link to the page 
  43. * @param int $id post id of the page 
  44. * @return string modified link 
  45. */ 
  46. public function page_link( $link, $id ) { 
  47. if ( ( $lang = $this->model->post->get_language( $id ) ) && $id == $lang->page_on_front ) { 
  48. return $lang->home_url; 
  49. return $link; 
  50.  
  51. /** 
  52. * adds page_on_front and page_for_posts properties to the language objects 
  53. * @since 1.8 
  54. * @param array $languages 
  55. * @param object $model 
  56. */ 
  57. public static function pll_languages_list( $languages, $model ) { 
  58. foreach ( $languages as $k => $language ) { 
  59. $languages[ $k ]->page_on_front = $model->post->get( get_option( 'page_on_front' ), $language ); 
  60. $languages[ $k ]->page_for_posts = $model->post->get( get_option( 'page_for_posts' ), $language ); 
  61.  
  62. return $languages;