PluginProbe
Polylang / 2.0.3
Polylang v2.0.3
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 | admin/admin-static-pages.php +23 -143 2.72.0.3 View file →
@@ -1,16 +1,15 @@
1 1 <?php
2 2
3 3 /**
4 - * Manages the static front page and the page for posts on admin side
4 + * manages the static front page and the page for posts on admin side
5 5 *
6 6 * @since 1.8
7 7 */
8 8 class PLL_Admin_Static_Pages extends PLL_Static_Pages {
9 - protected $links;
10 9
11 10 /**
12 - * Constructor: setups filters and actions
11 + * constructor: setups filters and actions
13 12 *
14 13 * @since 1.8
15 14 *
16 15 * @param object $polylang
@@ -17,87 +16,37 @@
17 16 */
18 17 public function __construct( &$polylang ) {
19 18 parent::__construct( $polylang );
20 19
21 - $this->links = &$polylang->links;
22 -
23 - // Removes the editor and the template select dropdown for pages for posts
24 - add_filter( 'use_block_editor_for_post', array( $this, 'use_block_editor_for_post' ), 10, 2 ); // Since WP 5.0
25 - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
26 -
27 - // Add post state for translations of the front page and posts page
20 + // add post state for translations of the front page and posts page
28 21 add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 );
29 22
30 - // Refresh language cache when a static front page has been translated
23 + // refresh language cache when a static front page has been translated
31 24 add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 );
32 25
33 - // Checks if chosen page on front is translated
26 + // checks if chosen page on front is translated
34 27 add_filter( 'pre_update_option_page_on_front', array( $this, 'update_page_on_front' ), 10, 2 );
35 - add_filter( 'customize_validate_page_on_front', array( $this, 'customize_validate_page_on_front' ), 10, 2 );
36 28
37 29 // Prevents WP resetting the option
38 30 add_filter( 'pre_update_option_show_on_front', array( $this, 'update_show_on_front' ), 10, 2 );
39 -
40 - add_action( 'admin_notices', array( $this, 'notice_must_translate' ) );
41 31 }
42 32
43 33 /**
44 - * Don't use the block editor for the translations of the pages for posts
34 + * add post state for translations of the front page and posts page
45 35 *
46 - * @since 2.5
47 - *
48 - * @param bool $use_block_editor Whether the post can be edited or not.
49 - * @param WP_Post $post The post being checked.
50 - * @return bool
51 - */
52 - public function use_block_editor_for_post( $use_block_editor, $post ) {
53 - if ( 'page' === $post->post_type ) {
54 - add_filter( 'option_page_for_posts', array( $this, 'translate_page_for_posts' ) );
55 -
56 - if ( ( get_option( 'page_for_posts' ) == $post->ID ) && empty( $post->post_content ) ) {
57 - return false;
58 - }
59 - }
60 -
61 - return $use_block_editor;
62 - }
63 -
64 - /**
65 - * Removes the editor for translations of the pages for posts
66 - * Removes the page template select dropdown in page attributes metabox too
67 - *
68 - * @since 2.2.2
69 - *
70 - * @param string $post_type Current post type
71 - * @param object $post Current post
72 - */
73 - public function add_meta_boxes( $post_type, $post ) {
74 - if ( 'page' === $post_type ) {
75 - add_filter( 'option_page_for_posts', array( $this, 'translate_page_for_posts' ) );
76 -
77 - if ( ( get_option( 'page_for_posts' ) == $post->ID ) && empty( $post->post_content ) ) {
78 - add_action( 'edit_form_after_title', '_wp_posts_page_notice' );
79 - remove_post_type_support( $post_type, 'editor' );
80 - }
81 - }
82 - }
83 -
84 - /**
85 - * Add post state for translations of the front page and posts page
86 - *
87 36 * @since 1.8
88 37 *
89 - * @param array $post_states An array of post display states.
90 - * @param object $post The current post object.
38 + * @param array $post_states
39 + * @param object $post
91 40 * @return array
92 41 */
93 42 public function display_post_states( $post_states, $post ) {
94 43 if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) {
95 - $post_states['page_on_front'] = __( 'Front Page', 'polylang' );
44 + $post_states['page_on_front'] = __( 'Front Page' );
96 45 }
97 46
98 47 if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_for_posts' ) ) ) ) {
99 - $post_states['page_for_posts'] = __( 'Posts Page', 'polylang' );
48 + $post_states['page_for_posts'] = __( 'Posts Page' );
100 49 }
101 50
102 51 return $post_states;
103 52 }
@@ -102,15 +51,15 @@
102 51 return $post_states;
103 52 }
104 53
105 54 /**
106 - * Refresh language cache when a static front page has been translated
55 + * refresh language cache when a static front page has been translated
107 56 *
108 57 * @since 1.8
109 58 *
110 - * @param int $post_id Not used
111 - * @param object $post Not used
112 - * @param array $translations
59 + * @param int $post_id not used
60 + * @param object $post not used
61 + * @param array $translations
113 62 */
114 63 public function pll_save_post( $post_id, $post, $translations ) {
115 64 if ( in_array( $this->page_on_front, $translations ) ) {
116 65 $this->model->clean_languages_cache();
@@ -117,65 +66,32 @@
117 66 }
118 67 }
119 68
120 69 /**
121 - * Checks if a page is translated in all languages
70 + * prevents choosing an untranslated static front page
71 + * displays an error message
122 72 *
123 - * @since 2.2
73 + * @since 1.6
124 74 *
125 - * @param int $page_id
126 - * @return bool
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
127 78 */
128 - protected function is_page_translated( $page_id ) {
79 + public function update_page_on_front( $page_id, $old_id ) {
129 80 if ( $page_id ) {
130 81 $translations = count( $this->model->post->get_translations( $page_id ) );
131 82 $languages = count( $this->model->get_languages_list() );
132 83
133 84 if ( $languages > 1 && $translations != $languages ) {
134 - return false;
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' ) );
135 87 }
136 88 }
137 89
138 - return true;
139 - }
140 -
141 - /**
142 - * Prevents choosing an untranslated static front page
143 - * Displays an error message
144 - *
145 - * @since 1.6
146 - *
147 - * @param int $page_id New page on front page id
148 - * @param int $old_id Old page on front page_id
149 - * @return int
150 - */
151 - public function update_page_on_front( $page_id, $old_id ) {
152 - if ( ! $this->is_page_translated( $page_id ) ) {
153 - $page_id = $old_id;
154 - add_settings_error( 'reading', 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) );
155 - }
156 -
157 90 return $page_id;
158 91 }
159 92
160 93 /**
161 - * Displays an error message in the customizer when choosing an untranslated static front page
162 - *
163 - * @since 2.2
164 - *
165 - * @param object $validity WP_Error object
166 - * @param int $page_id New page on front page id
167 - * @return object
168 - */
169 - public function customize_validate_page_on_front( $validity, $page_id ) {
170 - if ( ! $this->is_page_translated( $page_id ) ) {
171 - return new WP_Error( 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) );
172 - }
173 -
174 - return $validity;
175 - }
176 -
177 - /**
178 94 * Prevents WP resetting the option if the admin language filter is active for a language with no pages
179 95 *
180 96 * @since 1.9.3
181 97 *
@@ -187,42 +103,6 @@
187 103 if ( ! empty( $GLOBALS['pagenow'] ) && 'options-reading.php' === $GLOBALS['pagenow'] && 'posts' === $value && ! get_pages() && get_pages( array( 'lang' => '' ) ) ) {
188 104 $value = $old_value;
189 105 }
190 106 return $value;
191 - }
192 -
193 - /**
194 - * Add a notice to translate the static front page if it is not translated in all languages
195 - * This is especially useful after a new language is created.
196 - * The notice is not dismissible and displayed on the Languages pages and the list of pages.
197 - *
198 - * @since 2.6
199 - */
200 - public function notice_must_translate() {
201 - $screen = get_current_screen();
202 -
203 - if ( $this->page_on_front && ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) ) {
204 - $untranslated = array();
205 -
206 - foreach ( $this->model->get_languages_list() as $language ) {
207 - if ( ! $this->model->post->get( $this->page_on_front, $language ) ) {
208 - $untranslated[] = sprintf(
209 - '<a href="%s">%s</a>',
210 - esc_url( $this->links->get_new_post_translation_link( $this->page_on_front, $language ) ),
211 - esc_html( $language->name )
212 - );
213 - }
214 - }
215 -
216 - if ( ! empty( $untranslated ) ) {
217 - printf(
218 - '<div class="error"><p>%s</p></div>',
219 - sprintf(
220 - /* translators: %s is a comma separated list of native language names */
221 - esc_html__( 'You must translate your static front page in %s.', 'polylang' ),
222 - implode( ', ', $untranslated ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
223 - )
224 - );
225 - }
226 - }
227 107 }
228 108 }