From a7be20d01835c576eb7db76de52808f34d5e35df Mon Sep 17 00:00:00 2001 From: Tim Kaye Date: Thu, 21 Sep 2023 11:30:57 -0400 Subject: [PATCH] Add: Previous and Next buttons on single post screen in admin (#213) * Adds Previous and Next buttons on single post screen in admin Adds Previous and Next buttons alongside Add New button on single post screen in admin * Update class-wp-screen.php Creates toggle switch to show or hide Previous and Next buttons on single post screen in admin * Update class-wp-screen.php Ensure checked does not print to the screen unless intended * Update edit-form-advanced.php * Update class-wp-screen.php --- src/wp-admin/edit-form-advanced.php | 40 +++++++++++++++++++++++ src/wp-admin/includes/class-wp-screen.php | 27 +++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/edit-form-advanced.php b/src/wp-admin/edit-form-advanced.php index ed65d3a63a..c5893dd0b8 100644 --- a/src/wp-admin/edit-form-advanced.php +++ b/src/wp-admin/edit-form-advanced.php @@ -431,6 +431,46 @@ cap->create_posts ) ) { echo ' ' . esc_html( $post_type_object->labels->add_new ) . ''; + + /** + * Adds Previous and Next links alongside Add New link. + * Setting works per user per post type. + * + * @since CP-2.0.0 + */ + $nav_display = 'inline'; + $metaboxhidden = (array) get_user_meta( get_current_user_id(), 'metaboxhidden_' . $post_type_object->name, true ); + + if ( in_array( 'adminpostnavspan', $metaboxhidden ) ) { + $nav_display = 'none'; + } + + $next_post = get_next_post(); + $previous_post = get_previous_post(); + + echo ''; + + if ( ! empty( $previous_post ) ) { + + $previous_link = esc_url( admin_url() . 'post.php?post=' . $previous_post->ID . '&action=edit' ); + + $prev_title = _x( 'Previous post: ', 'Admin Post Navigation' ) . esc_attr( $previous_post->post_title ); + + echo ' ' . _x( '← Previous', 'Admin Post Navigation' ) . ''; + + } + + if ( ! empty( $next_post ) ) { + + $next_link = esc_url( admin_url() . 'post.php?post=' . $next_post->ID . '&action=edit' ); + + $next_title = _x( 'Next post: ', 'Admin Post Navigation' ) . esc_attr( $next_post->post_title ); + + echo ' ' . _x( 'Next →', 'Admin Post Navigation' ) . ''; + + } + + echo ''; } ?> diff --git a/src/wp-admin/includes/class-wp-screen.php b/src/wp-admin/includes/class-wp-screen.php index d978593a4c..68be789f19 100644 --- a/src/wp-admin/includes/class-wp-screen.php +++ b/src/wp-admin/includes/class-wp-screen.php @@ -975,9 +975,30 @@ public function show_screen_options() { $this->_screen_settings = ''; if ( 'post' === $this->base ) { - $expand = ''; + + $expand = ''; + $this->_screen_settings = $expand; }