PluginProbe
Polylang / 3.3
Polylang v3.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 +17 -117 2.83.3 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|null
14 + */
12 15 protected $links;
13 16
14 17 /**
15 18 * Constructor: setups filters and actions
@@ -22,22 +25,14 @@
22 25 parent::__construct( $polylang );
23 26
24 27 $this->links = &$polylang->links;
25 28
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 29 // Add post state for translations of the front page and posts page
31 30 add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 );
32 31
33 - // Refresh language cache when a static front page has been translated
32 + // Refreshes the language cache when a static front page or page for for posts has been translated.
34 33 add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 );
35 34
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 35 // Prevents WP resetting the option
41 36 add_filter( 'pre_update_option_show_on_front', array( $this, 'update_show_on_front' ), 10, 2 );
42 37
43 38 add_action( 'admin_notices', array( $this, 'notice_must_translate' ) );
@@ -43,56 +38,15 @@
43 38 add_action( 'admin_notices', array( $this, 'notice_must_translate' ) );
44 39 }
45 40
46 41 /**
47 - * Don't use the block editor for the translations of the pages for posts
42 + * Adds post state for translations of the front page and posts page.
48 43 *
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 44 * @since 1.8
91 45 *
92 - * @param array $post_states An array of post display states.
93 - * @param object $post The current post object.
94 - * @return array
46 + * @param string[] $post_states An array of post display states.
47 + * @param WP_Post $post The current post object.
48 + * @return string[]
95 49 */
96 50 public function display_post_states( $post_states, $post ) {
97 51 if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) {
98 52 $post_states['page_on_front'] = __( 'Front Page', 'polylang' );
@@ -105,80 +59,24 @@
105 59 return $post_states;
106 60 }
107 61
108 62 /**
109 - * Refresh language cache when a static front page has been translated
63 + * Refreshes the language cache when a static front page or page for for posts has been translated.
110 64 *
111 65 * @since 1.8
112 66 *
113 - * @param int $post_id Not used
114 - * @param object $post Not used
115 - * @param array $translations
67 + * @param int $post_id Not used.
68 + * @param WP_Post $post Not used.
69 + * @param int[] $translations Translations of the post being saved.
70 + * @return void
116 71 */
117 72 public function pll_save_post( $post_id, $post, $translations ) {
118 - if ( in_array( $this->page_on_front, $translations ) ) {
73 + if ( in_array( $this->page_on_front, $translations ) || in_array( $this->page_for_posts, $translations ) ) {
119 74 $this->model->clean_languages_cache();
120 75 }
121 76 }
122 77
123 78 /**
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 79 * Prevents WP resetting the option if the admin language filter is active for a language with no pages
182 80 *
183 81 * @since 1.9.3
184 82 *
@@ -198,13 +96,15 @@
198 96 * This is especially useful after a new language is created.
199 97 * The notice is not dismissible and displayed on the Languages pages and the list of pages.
200 98 *
201 99 * @since 2.6
100 + *
101 + * @return void
202 102 */
203 103 public function notice_must_translate() {
204 104 $screen = get_current_screen();
205 105
206 - if ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) {
106 + if ( ! empty( $screen ) && ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) ) {
207 107 $message = $this->get_must_translate_message();
208 108
209 109 if ( ! empty( $message ) ) {
210 110 printf(