PluginProbe
Polylang / 2.8
Polylang v2.8
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 +74 -20 3.02.8 View file →
@@ -8,11 +8,8 @@
8 8 *
9 9 * @since 1.8
10 10 */
11 11 class PLL_Admin_Static_Pages extends PLL_Static_Pages {
12 - /**
13 - * @var PLL_Admin_Links
14 - */
15 12 protected $links;
16 13
17 14 /**
18 15 * Constructor: setups filters and actions
@@ -35,8 +32,12 @@
35 32
36 33 // Refresh language cache when a static front page has been translated
37 34 add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 );
38 35
36 + // Checks if chosen page on front is translated
37 + 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 +
39 40 // Prevents WP resetting the option
40 41 add_filter( 'pre_update_option_show_on_front', array( $this, 'update_show_on_front' ), 10, 2 );
41 42
42 43 add_action( 'admin_notices', array( $this, 'notice_must_translate' ) );
@@ -63,16 +64,15 @@
63 64 return $use_block_editor;
64 65 }
65 66
66 67 /**
67 - * Removes the editor for the translations of the pages for posts.
68 - * Removes the page template select dropdown in page attributes metabox too.
68 + * Removes the editor for translations of the pages for posts
69 + * Removes the page template select dropdown in page attributes metabox too
69 70 *
70 71 * @since 2.2.2
71 72 *
72 - * @param string $post_type Current post type.
73 - * @param WP_Post $post Current post.
74 - * @return void
73 + * @param string $post_type Current post type
74 + * @param object $post Current post
75 75 */
76 76 public function add_meta_boxes( $post_type, $post ) {
77 77 if ( 'page' === $post_type ) {
78 78 add_filter( 'option_page_for_posts', array( $this, 'translate_page_for_posts' ) );
@@ -84,15 +84,15 @@
84 84 }
85 85 }
86 86
87 87 /**
88 - * Adds post state for translations of the front page and posts page.
88 + * Add post state for translations of the front page and posts page
89 89 *
90 90 * @since 1.8
91 91 *
92 - * @param string[] $post_states An array of post display states.
93 - * @param WP_Post $post The current post object.
94 - * @return string[]
92 + * @param array $post_states An array of post display states.
93 + * @param object $post The current post object.
94 + * @return array
95 95 */
96 96 public function display_post_states( $post_states, $post ) {
97 97 if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) {
98 98 $post_states['page_on_front'] = __( 'Front Page', 'polylang' );
@@ -105,16 +105,15 @@
105 105 return $post_states;
106 106 }
107 107
108 108 /**
109 - * Refreshes the language cache when a static front page has been translated.
109 + * Refresh language cache when a static front page has been translated
110 110 *
111 111 * @since 1.8
112 112 *
113 - * @param int $post_id Not used.
114 - * @param WP_Post $post Not used.
115 - * @param int[] $translations Translations of the post being saved.
116 - * @return void
113 + * @param int $post_id Not used
114 + * @param object $post Not used
115 + * @param array $translations
117 116 */
118 117 public function pll_save_post( $post_id, $post, $translations ) {
119 118 if ( in_array( $this->page_on_front, $translations ) ) {
120 119 $this->model->clean_languages_cache();
@@ -121,8 +120,65 @@
121 120 }
122 121 }
123 122
124 123 /**
124 + * Checks if a page is translated in all languages
125 + *
126 + * @since 2.2
127 + *
128 + * @param int $page_id
129 + * @return bool
130 + */
131 + protected function is_page_translated( $page_id ) {
132 + if ( $page_id ) {
133 + $translations = count( $this->model->post->get_translations( $page_id ) );
134 + $languages = count( $this->model->get_languages_list() );
135 +
136 + if ( $languages > 1 && $translations != $languages ) {
137 + return false;
138 + }
139 + }
140 +
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 + return $page_id;
161 + }
162 +
163 + /**
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 + /**
125 181 * Prevents WP resetting the option if the admin language filter is active for a language with no pages
126 182 *
127 183 * @since 1.9.3
128 184 *
@@ -142,15 +198,13 @@
142 198 * This is especially useful after a new language is created.
143 199 * The notice is not dismissible and displayed on the Languages pages and the list of pages.
144 200 *
145 201 * @since 2.6
146 - *
147 - * @return void
148 202 */
149 203 public function notice_must_translate() {
150 204 $screen = get_current_screen();
151 205
152 - if ( ! empty( $screen ) && ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) ) {
206 + if ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) {
153 207 $message = $this->get_must_translate_message();
154 208
155 209 if ( ! empty( $message ) ) {
156 210 printf(