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