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