PluginProbe
Polylang / 2.1.6
Polylang v2.1.6
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 / include / static-pages.php

static-pages.php in Polylang 2.1.6, at include/static-pages.php

89 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * base class to manage the static front page and the page for posts
5 *
6 * @since 1.8
7 */
8 abstract class PLL_Static_Pages {
9 public $model, $options;
10 public $page_on_front, $page_for_posts;
11
12 /**
13 * constructor: setups filters and actions
14 *
15 * @since 1.8
16 *
17 * @param object $polylang
18 */
19 public function __construct( &$polylang ) {
20 $this->model = &$polylang->model;
21 $this->options = &$polylang->options;
22
23 $this->init();
24
25 // Modifies the page link in case the front page is not in the default language
26 add_filter( 'page_link', array( $this, 'page_link' ), 20, 2 );
27
28 // clean the languages cache when editing page of front, page for posts
29 add_action( 'update_option_show_on_front', array( $this->model, 'clean_languages_cache' ) );
30 add_action( 'update_option_page_on_front', array( $this->model, 'clean_languages_cache' ) );
31 add_action( 'update_option_page_for_posts', array( $this->model, 'clean_languages_cache' ) );
32
33 // refresh rewrite rules when the page on front is modified
34 add_action( 'update_option_page_on_front', 'flush_rewrite_rules' );
35 }
36
37 /**
38 * stores the page on front and page for posts ids
39 *
40 * @since 1.8
41 */
42 public function init() {
43 if ( 'page' == get_option( 'show_on_front' ) ) {
44 $this->page_on_front = get_option( 'page_on_front' );
45 $this->page_for_posts = get_option( 'page_for_posts' );
46 }
47
48 else {
49 $this->page_on_front = 0;
50 $this->page_for_posts = 0;
51 }
52 }
53
54 /**
55 * Modifies the page link in case the front page is not in the default language
56 *
57 * @since 0.7.2
58 *
59 * @param string $link link to the page
60 * @param int $id post id of the page
61 * @return string modified link
62 */
63 public function page_link( $link, $id ) {
64 if ( ( $lang = $this->model->post->get_language( $id ) ) && $id == $lang->page_on_front ) {
65 return $lang->home_url;
66 }
67 return $link;
68 }
69
70 /**
71 * adds page_on_front and page_for_posts properties to the language objects
72 *
73 * @since 1.8
74 *
75 * @param array $languages
76 * @param object $model
77 */
78 public static function pll_languages_list( $languages, $model ) {
79 if ( 'page' === get_option( 'show_on_front' ) ) {
80 foreach ( $languages as $k => $language ) {
81 $languages[ $k ]->page_on_front = $model->post->get( get_option( 'page_on_front' ), $language );
82 $languages[ $k ]->page_for_posts = $model->post->get( get_option( 'page_for_posts' ), $language );
83 }
84 }
85
86 return $languages;
87 }
88 }
89