| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Manages the static front page and the page for posts on admin side |
| 8 | 5 | * |
| @@ -8,9 +5,8 @@ | ||
| 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 | 11 | * Constructor: setups filters and actions |
| 16 | 12 | * |
| @@ -20,12 +16,9 @@ | ||
| 20 | 16 | */ |
| 21 | 17 | public function __construct( &$polylang ) { |
| 22 | 18 | parent::__construct( $polylang ); |
| 23 | 19 | |
| 24 | - $this->links = &$polylang->links; | |
| 25 | - | |
| 26 | 20 | // 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 | 21 | add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 ); |
| 29 | 22 | |
| 30 | 23 | // Add post state for translations of the front page and posts page |
| 31 | 24 | add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 ); |
| @@ -38,34 +31,11 @@ | ||
| 38 | 31 | add_filter( 'customize_validate_page_on_front', array( $this, 'customize_validate_page_on_front' ), 10, 2 ); |
| 39 | 32 | |
| 40 | 33 | // Prevents WP resetting the option |
| 41 | 34 | 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 | 35 | } |
| 45 | 36 | |
| 46 | 37 | /** |
| 47 | - * Don't use the block editor for the translations of the pages for posts | |
| 48 | - * | |
| 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 | 38 | * Removes the editor for translations of the pages for posts |
| 69 | 39 | * Removes the page template select dropdown in page attributes metabox too |
| 70 | 40 | * |
| 71 | 41 | * @since 2.2.2 |
| @@ -88,19 +58,19 @@ | ||
| 88 | 58 | * Add post state for translations of the front page and posts page |
| 89 | 59 | * |
| 90 | 60 | * @since 1.8 |
| 91 | 61 | * |
| 92 | - * @param array $post_states An array of post display states. | |
| 93 | - * @param object $post The current post object. | |
| 62 | + * @param array $post_states | |
| 63 | + * @param object $post | |
| 94 | 64 | * @return array |
| 95 | 65 | */ |
| 96 | 66 | public function display_post_states( $post_states, $post ) { |
| 97 | 67 | if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) { |
| 98 | - $post_states['page_on_front'] = __( 'Front Page', 'polylang' ); | |
| 68 | + $post_states['page_on_front'] = __( 'Front Page' ); | |
| 99 | 69 | } |
| 100 | 70 | |
| 101 | 71 | if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_for_posts' ) ) ) ) { |
| 102 | - $post_states['page_for_posts'] = __( 'Posts Page', 'polylang' ); | |
| 72 | + $post_states['page_for_posts'] = __( 'Posts Page' ); | |
| 103 | 73 | } |
| 104 | 74 | |
| 105 | 75 | return $post_states; |
| 106 | 76 | } |
| @@ -190,63 +160,6 @@ | ||
| 190 | 160 | if ( ! empty( $GLOBALS['pagenow'] ) && 'options-reading.php' === $GLOBALS['pagenow'] && 'posts' === $value && ! get_pages() && get_pages( array( 'lang' => '' ) ) ) { |
| 191 | 161 | $value = $old_value; |
| 192 | 162 | } |
| 193 | 163 | 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 | 164 | } |
| 252 | 165 | } |