PluginProbe
Polylang / 3.1
Polylang v3.1
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 +20 -74 2.83.1 View file →
@@ -8,8 +8,11 @@
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 + */
12 15 protected $links;
13 16
14 17 /**
15 18 * Constructor: setups filters and actions
@@ -32,12 +35,8 @@
32 35
33 36 // Refresh language cache when a static front page has been translated
34 37 add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 );
35 38
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 -
40 39 // Prevents WP resetting the option
41 40 add_filter( 'pre_update_option_show_on_front', array( $this, 'update_show_on_front' ), 10, 2 );
42 41
43 42 add_action( 'admin_notices', array( $this, 'notice_must_translate' ) );
@@ -64,15 +63,16 @@
64 63 return $use_block_editor;
65 64 }
66 65
67 66 /**
68 - * Removes the editor for translations of the pages for posts
69 - * Removes the page template select dropdown in page attributes metabox too
67 + * Removes the editor for the translations of the pages for posts.
68 + * Removes the page template select dropdown in page attributes metabox too.
70 69 *
71 70 * @since 2.2.2
72 71 *
73 - * @param string $post_type Current post type
74 - * @param object $post Current post
72 + * @param string $post_type Current post type.
73 + * @param WP_Post $post Current post.
74 + * @return void
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 - * Add post state for translations of the front page and posts page
88 + * Adds post state for translations of the front page and posts page.
89 89 *
90 90 * @since 1.8
91 91 *
92 - * @param array $post_states An array of post display states.
93 - * @param object $post The current post object.
94 - * @return array
92 + * @param string[] $post_states An array of post display states.
93 + * @param WP_Post $post The current post object.
94 + * @return string[]
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,15 +105,16 @@
105 105 return $post_states;
106 106 }
107 107
108 108 /**
109 - * Refresh language cache when a static front page has been translated
109 + * Refreshes the 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 object $post Not used
115 - * @param array $translations
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
116 117 */
117 118 public function pll_save_post( $post_id, $post, $translations ) {
118 119 if ( in_array( $this->page_on_front, $translations ) ) {
119 120 $this->model->clean_languages_cache();
@@ -120,65 +121,8 @@
120 121 }
121 122 }
122 123
123 124 /**
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 - /**
181 125 * Prevents WP resetting the option if the admin language filter is active for a language with no pages
182 126 *
183 127 * @since 1.9.3
184 128 *
@@ -198,13 +142,15 @@
198 142 * This is especially useful after a new language is created.
199 143 * The notice is not dismissible and displayed on the Languages pages and the list of pages.
200 144 *
201 145 * @since 2.6
146 + *
147 + * @return void
202 148 */
203 149 public function notice_must_translate() {
204 150 $screen = get_current_screen();
205 151
206 - if ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) {
152 + if ( ! empty( $screen ) && ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) ) {
207 153 $message = $this->get_must_translate_message();
208 154
209 155 if ( ! empty( $message ) ) {
210 156 printf(