PluginProbe
Polylang / 2.1
Polylang v2.1
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
← All changes | include/static-pages.php +19 -94 3.02.1 View file →
@@ -1,59 +1,25 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 - * Base class to manage the static front page and the page for posts
4 + * base class to manage the static front page and the page for posts
8 5 *
9 6 * @since 1.8
10 7 */
11 -class PLL_Static_Pages {
12 - /**
13 - * Id of the page on front.
14 - *
15 - * @var int
16 - */
17 - public $page_on_front;
8 +abstract class PLL_Static_Pages {
9 + public $model, $options;
10 + public $page_on_front, $page_for_posts;
18 11
19 12 /**
20 - * Id of the page for posts.
13 + * constructor: setups filters and actions
21 14 *
22 - * @var int
23 - */
24 - public $page_for_posts;
25 -
26 - /**
27 - * Stores the plugin options.
28 - *
29 - * @var array
30 - */
31 - protected $options;
32 -
33 - /**
34 - * @var PLL_Model
35 - */
36 - protected $model;
37 -
38 - /**
39 - * Current language.
40 - *
41 - * @var PLL_Language
42 - */
43 - protected $curlang;
44 -
45 - /**
46 - * Constructor: setups filters and actions
47 - *
48 15 * @since 1.8
49 16 *
50 17 * @param object $polylang
51 18 */
52 19 public function __construct( &$polylang ) {
53 - $this->model = &$polylang->model;
20 + $this->model = &$polylang->model;
54 21 $this->options = &$polylang->options;
55 - $this->curlang = &$polylang->curlang;
56 22
57 23 $this->init();
58 24
59 25 // Modifies the page link in case the front page is not in the default language
@@ -58,32 +24,28 @@
58 24
59 25 // Modifies the page link in case the front page is not in the default language
60 26 add_filter( 'page_link', array( $this, 'page_link' ), 20, 2 );
61 27
62 - // Clean the languages cache when editing page of front, page for posts
63 - add_action( 'update_option_show_on_front', array( $this->model, 'clean_languages_cache' ) );
28 + // clean the languages cache when editing page of front, page for posts
64 29 add_action( 'update_option_page_on_front', array( $this->model, 'clean_languages_cache' ) );
65 30 add_action( 'update_option_page_for_posts', array( $this->model, 'clean_languages_cache' ) );
66 31
67 - // Refresh rewrite rules when the page on front is modified
32 + // refresh rewrite rules when the page on front is modified
68 33 add_action( 'update_option_page_on_front', 'flush_rewrite_rules' );
69 -
70 - // OEmbed
71 - add_filter( 'oembed_request_post_id', array( $this, 'oembed_request_post_id' ), 10, 2 );
72 34 }
73 35
74 36 /**
75 - * Stores the page on front and page for posts ids
37 + * stores the page on front and page for posts ids
76 38 *
77 39 * @since 1.8
78 - *
79 - * @return void
80 40 */
81 41 public function init() {
82 42 if ( 'page' == get_option( 'show_on_front' ) ) {
83 43 $this->page_on_front = get_option( 'page_on_front' );
84 44 $this->page_for_posts = get_option( 'page_for_posts' );
85 - } else {
45 + }
46 +
47 + else {
86 48 $this->page_on_front = 0;
87 49 $this->page_for_posts = 0;
88 50 }
89 51 }
@@ -97,11 +59,9 @@
97 59 * @param int $id post id of the page
98 60 * @return string modified link
99 61 */
100 62 public function page_link( $link, $id ) {
101 - $lang = $this->model->post->get_language( $id );
102 -
103 - if ( $lang && $id == $lang->page_on_front ) {
63 + if ( ( $lang = $this->model->post->get_language( $id ) ) && $id == $lang->page_on_front ) {
104 64 return $lang->home_url;
105 65 }
106 66 return $link;
107 67 }
@@ -106,55 +66,20 @@
106 66 return $link;
107 67 }
108 68
109 69 /**
110 - * Adds page_on_front and page_for_posts properties to the language objects.
70 + * adds page_on_front and page_for_posts properties to the language objects
111 71 *
112 72 * @since 1.8
113 73 *
114 - * @param PLL_Language[] $languages The list of languages.
115 - * @param PLL_Model $model The instance of PLL_Model.
116 - * @return PLL_Language[]
74 + * @param array $languages
75 + * @param object $model
117 76 */
118 77 public static function pll_languages_list( $languages, $model ) {
119 - if ( 'page' === get_option( 'show_on_front' ) ) {
120 - foreach ( $languages as $k => $language ) {
121 - $languages[ $k ]->page_on_front = $model->post->get( get_option( 'page_on_front' ), $language );
122 - $languages[ $k ]->page_for_posts = $model->post->get( get_option( 'page_for_posts' ), $language );
123 - }
78 + foreach ( $languages as $k => $language ) {
79 + $languages[ $k ]->page_on_front = $model->post->get( get_option( 'page_on_front' ), $language );
80 + $languages[ $k ]->page_for_posts = $model->post->get( get_option( 'page_for_posts' ), $language );
124 81 }
125 82
126 83 return $languages;
127 - }
128 -
129 - /**
130 - * Translates page for posts
131 - *
132 - * @since 1.8
133 - *
134 - * @param int $v page for posts page id
135 - * @return int
136 - */
137 - public function translate_page_for_posts( $v ) {
138 - // Don't attempt to translate in a 'switch_blog' action as there is a risk to call this function while initializing the languages cache
139 - return isset( $this->curlang->page_for_posts ) && ( $this->curlang->page_for_posts ) && ! doing_action( 'switch_blog' ) ? $this->curlang->page_for_posts : $v;
140 - }
141 -
142 - /**
143 - * Fixes the oembed for the translated static front page
144 - * when the language page is redirected to the front page
145 - *
146 - * @since 2.6
147 - *
148 - * @param int $post_id The post ID.
149 - * @param string $url The requested URL.
150 - * @return int
151 - */
152 - public function oembed_request_post_id( $post_id, $url ) {
153 - foreach ( $this->model->get_languages_list() as $lang ) {
154 - if ( trailingslashit( $url ) === trailingslashit( $lang->home_url ) ) {
155 - $post_id = $lang->page_on_front;
156 - }
157 - }
158 - return $post_id;
159 84 }
160 85 }