| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Base class to manage the static front page and the page for posts |
| 8 | 5 | * |
| @@ -7,9 +4,9 @@ | ||
| 7 | 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 | /** |
| @@ -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(); |
| @@ -35,11 +32,8 @@ | ||
| 35 | 32 | add_action( 'update_option_page_for_posts', array( $this->model, 'clean_languages_cache' ) ); |
| 36 | 33 | |
| 37 | 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 | 39 | * Stores the page on front and page for posts ids |
| @@ -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 | } |
| @@ -102,25 +96,7 @@ | ||
| 102 | 96 | * @return int |
| 103 | 97 | */ |
| 104 | 98 | public function translate_page_for_posts( $v ) { |
| 105 | 99 | // 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 ) && ( $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; | |
| 100 | + return isset( $this->curlang->page_for_posts ) && ! doing_action( 'switch_blog' ) ? $this->curlang->page_for_posts : $v; | |
| 125 | 101 | } |
| 126 | 102 | } |