PluginProbe
Polylang / 1.8.2
Polylang v1.8.2
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
polylang / admin / admin-static-pages.php

admin-static-pages.php in Polylang 1.8.2, at admin/admin-static-pages.php

90 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * manages the static front page and the page for posts on admin side
5 *
6 * @since 1.8
7 */
8 class PLL_Admin_Static_Pages extends PLL_Static_Pages {
9
10 /*
11 * constructor: setups filters and actions
12 *
13 * @since 1.8
14 *
15 * @param object $polylang
16 */
17 public function __construct( &$polylang ) {
18 parent::__construct( $polylang );
19
20 // add post state for translations of the front page and posts page
21 add_filter( 'display_post_states', array( &$this, 'display_post_states' ), 10, 2 );
22
23 // refresh language cache when a static front page has been translated
24 add_action( 'pll_save_post', array( &$this, 'pll_save_post' ), 10, 3 );
25
26 // checks if chosen page on front is translated
27 add_filter( 'pre_update_option_page_on_front', array( &$this, 'update_page_on_front' ), 10, 2 );
28 }
29
30 /*
31 * add post state for translations of the front page and posts page
32 *
33 * @since 1.8
34 *
35 * @param array $post_states
36 * @param object $post
37 * @return array
38 */
39 public function display_post_states( $post_states, $post ) {
40 if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) {
41 $post_states['page_on_front'] = __( 'Front Page' );
42 }
43
44 if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_for_posts' ) ) ) ) {
45 $post_states['page_for_posts'] = __( 'Posts Page' );
46 }
47
48 return $post_states;
49 }
50
51 /*
52 * refresh language cache when a static front page has been translated
53 *
54 * @since 1.8
55 *
56 * @param int $post_id not used
57 * @param object $post not used
58 * @param array $translations
59 */
60 public function pll_save_post( $post_id, $post, $translations ) {
61 if ( in_array( $this->page_on_front, $translations ) ) {
62 $this->model->clean_languages_cache();
63 }
64 }
65
66 /*
67 * prevents choosing an untranslated static front page
68 * displays an error message
69 *
70 * @since 1.6
71 *
72 * @param int $page_id new page on front page id
73 * @param int $old_id old page on front page_id
74 * @return int
75 */
76 public function update_page_on_front( $page_id, $old_id ) {
77 if ( $page_id ) {
78 $translations = count( $this->model->post->get_translations( $page_id ) );
79 $languages = count( $this->model->get_languages_list() );
80
81 if ( $languages > 1 && $translations != $languages ) {
82 $page_id = $old_id;
83 add_settings_error( 'reading', 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) );
84 }
85 }
86
87 return $page_id;
88 }
89 }
90