PluginProbe
Polylang / 2.3
Polylang v2.3
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 +14 -38 2.82.3 View file →
@@ -1,20 +1,17 @@
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 {
8 +abstract class PLL_Static_Pages {
12 9 public $model, $options;
13 10 public $page_on_front, $page_for_posts;
14 11
15 12 /**
16 - * Constructor: setups filters and actions
13 + * constructor: setups filters and actions
17 14 *
18 15 * @since 1.8
19 16 *
20 17 * @param object $polylang
@@ -19,9 +16,9 @@
19 16 *
20 17 * @param object $polylang
21 18 */
22 19 public function __construct( &$polylang ) {
23 - $this->model = &$polylang->model;
20 + $this->model = &$polylang->model;
24 21 $this->options = &$polylang->options;
25 22 $this->curlang = &$polylang->curlang;
26 23
27 24 $this->init();
@@ -28,22 +25,19 @@
28 25
29 26 // Modifies the page link in case the front page is not in the default language
30 27 add_filter( 'page_link', array( $this, 'page_link' ), 20, 2 );
31 28
32 - // Clean the languages cache when editing page of front, page for posts
29 + // clean the languages cache when editing page of front, page for posts
33 30 add_action( 'update_option_show_on_front', array( $this->model, 'clean_languages_cache' ) );
34 31 add_action( 'update_option_page_on_front', array( $this->model, 'clean_languages_cache' ) );
35 32 add_action( 'update_option_page_for_posts', array( $this->model, 'clean_languages_cache' ) );
36 33
37 - // Refresh rewrite rules when the page on front is modified
34 + // refresh rewrite rules when the page on front is modified
38 35 add_action( 'update_option_page_on_front', 'flush_rewrite_rules' );
39 -
40 - // OEmbed
41 - add_filter( 'oembed_request_post_id', array( $this, 'oembed_request_post_id' ), 10, 2 );
42 36 }
43 37
44 38 /**
45 - * Stores the page on front and page for posts ids
39 + * stores the page on front and page for posts ids
46 40 *
47 41 * @since 1.8
48 42 */
49 43 public function init() {
@@ -49,9 +43,11 @@
49 43 public function init() {
50 44 if ( 'page' == get_option( 'show_on_front' ) ) {
51 45 $this->page_on_front = get_option( 'page_on_front' );
52 46 $this->page_for_posts = get_option( 'page_for_posts' );
53 - } else {
47 + }
48 +
49 + else {
54 50 $this->page_on_front = 0;
55 51 $this->page_for_posts = 0;
56 52 }
57 53 }
@@ -65,11 +61,9 @@
65 61 * @param int $id post id of the page
66 62 * @return string modified link
67 63 */
68 64 public function page_link( $link, $id ) {
69 - $lang = $this->model->post->get_language( $id );
70 -
71 - if ( $lang && $id == $lang->page_on_front ) {
65 + if ( ( $lang = $this->model->post->get_language( $id ) ) && $id == $lang->page_on_front ) {
72 66 return $lang->home_url;
73 67 }
74 68 return $link;
75 69 }
@@ -74,9 +68,9 @@
74 68 return $link;
75 69 }
76 70
77 71 /**
78 - * Adds page_on_front and page_for_posts properties to the language objects
72 + * adds page_on_front and page_for_posts properties to the language objects
79 73 *
80 74 * @since 1.8
81 75 *
82 76 * @param array $languages
@@ -101,26 +95,8 @@
101 95 * @param int $v page for posts page id
102 96 * @return int
103 97 */
104 98 public function translate_page_for_posts( $v ) {
105 - // Don't attempt to translate in a 'switch_blog' action as there is a risk to call this function while initializing the languages cache
106 - return isset( $this->curlang->page_for_posts ) && ! doing_action( 'switch_blog' ) ? $this->curlang->page_for_posts : $v;
107 - }
108 -
109 - /**
110 - * Fixes the oembed for the translated static front page
111 - * when the language page is redirected to the front page
112 - *
113 - * @since 2.6
114 - *
115 - * @param int $post_id The post ID.
116 - * @param string $url The requested URL.
117 - */
118 - public function oembed_request_post_id( $post_id, $url ) {
119 - foreach ( $this->model->get_languages_list() as $lang ) {
120 - if ( trailingslashit( $url ) === trailingslashit( $lang->home_url ) ) {
121 - $post_id = $lang->page_on_front;
122 - }
123 - }
124 - return $post_id;
99 + // Returns the current page if there is no translation to avoid ugly notices
100 + return isset( $this->curlang->page_for_posts ) ? $this->curlang->page_for_posts : $v;
125 101 }
126 102 }