PluginProbe
Polylang / 2.1.6
Polylang v2.1.6
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 2.1.6, at admin/admin-static-pages.php

109 lines 3.1 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 // Prevents WP resetting the option
30 add_filter( 'pre_update_option_show_on_front', array( $this, 'update_show_on_front' ), 10, 2 );
31 }
32
33 /**
34 * add post state for translations of the front page and posts page
35 *
36 * @since 1.8
37 *
38 * @param array $post_states
39 * @param object $post
40 * @return array
41 */
42 public function display_post_states( $post_states, $post ) {
43 if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) {
44 $post_states['page_on_front'] = __( 'Front Page' );
45 }
46
47 if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_for_posts' ) ) ) ) {
48 $post_states['page_for_posts'] = __( 'Posts Page' );
49 }
50
51 return $post_states;
52 }
53
54 /**
55 * refresh language cache when a static front page has been translated
56 *
57 * @since 1.8
58 *
59 * @param int $post_id not used
60 * @param object $post not used
61 * @param array $translations
62 */
63 public function pll_save_post( $post_id, $post, $translations ) {
64 if ( in_array( $this->page_on_front, $translations ) ) {
65 $this->model->clean_languages_cache();
66 }
67 }
68
69 /**
70 * prevents choosing an untranslated static front page
71 * displays an error message
72 *
73 * @since 1.6
74 *
75 * @param int $page_id new page on front page id
76 * @param int $old_id old page on front page_id
77 * @return int
78 */
79 public function update_page_on_front( $page_id, $old_id ) {
80 if ( $page_id ) {
81 $translations = count( $this->model->post->get_translations( $page_id ) );
82 $languages = count( $this->model->get_languages_list() );
83
84 if ( $languages > 1 && $translations != $languages ) {
85 $page_id = $old_id;
86 add_settings_error( 'reading', 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) );
87 }
88 }
89
90 return $page_id;
91 }
92
93 /**
94 * Prevents WP resetting the option if the admin language filter is active for a language with no pages
95 *
96 * @since 1.9.3
97 *
98 * @param string $value
99 * @param string $old_value
100 * @return string
101 */
102 public function update_show_on_front( $value, $old_value ) {
103 if ( ! empty( $GLOBALS['pagenow'] ) && 'options-reading.php' === $GLOBALS['pagenow'] && 'posts' === $value && ! get_pages() && get_pages( array( 'lang' => '' ) ) ) {
104 $value = $old_value;
105 }
106 return $value;
107 }
108 }
109