| 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 |
// clean the languages cache when editing page of front, page for posts |
| 26 |
add_action( 'update_option_page_on_front', array( &$this->model, 'clean_languages_cache' ) ); |
| 27 |
add_action( 'update_option_page_for_posts', array( &$this->model, 'clean_languages_cache' ) ); |
| 28 |
|
| 29 |
// refresh rewrite rules when the page on front is modified |
| 30 |
add_action( 'update_option_page_on_front', 'flush_rewrite_rules' ); |
| 31 |
} |
| 32 |
|
| 33 |
/* |
| 34 |
* stores the page on front and page for posts ids |
| 35 |
* |
| 36 |
* @since 1.8 |
| 37 |
*/ |
| 38 |
public function init() { |
| 39 |
if ( 'page' == get_option( 'show_on_front' ) ) { |
| 40 |
$this->page_on_front = get_option( 'page_on_front' ); |
| 41 |
$this->page_for_posts = get_option( 'page_for_posts' ); |
| 42 |
} |
| 43 |
|
| 44 |
else { |
| 45 |
$this->page_on_front = 0; |
| 46 |
$this->page_for_posts = 0; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/* |
| 51 |
* adds page_on_front and page_for_posts properties to the language objects |
| 52 |
* |
| 53 |
* @since 1.8 |
| 54 |
* |
| 55 |
* @param array $languages |
| 56 |
* @param object $model |
| 57 |
*/ |
| 58 |
public static function pll_languages_list( $languages, $model ) { |
| 59 |
foreach ( $languages as $k => $language ) { |
| 60 |
$languages[ $k ]->page_on_front = $model->post->get( get_option( 'page_on_front' ), $language ); |
| 61 |
$languages[ $k ]->page_for_posts = $model->post->get( get_option( 'page_for_posts' ), $language ); |
| 62 |
} |
| 63 |
|
| 64 |
return $languages; |
| 65 |
} |
| 66 |
} |
| 67 |
|