Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
Add: Previous and Next buttons on single post screen in admin (#213)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
KTS915 authored Sep 21, 2023
1 parent 6cba33e commit a7be20d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
40 changes: 40 additions & 0 deletions src/wp-admin/edit-form-advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,46 @@
<?php
if ( isset( $post_new_file ) && current_user_can( $post_type_object->cap->create_posts ) ) {
echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>';

/**
* 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 '<span id="adminpostnavspan" class="postbox" style="background: transparent; border: none; box-shadow: none; display: ' . $nav_display . ';">';

if ( ! empty( $previous_post ) ) {

$previous_link = esc_url( admin_url() . 'post.php?post=' . $previous_post->ID . '&amp;action=edit' );

$prev_title = _x( 'Previous post: ', 'Admin Post Navigation' ) . esc_attr( $previous_post->post_title );

echo ' <a href="' . $previous_link . '" id="adminpostnav-prev" title="' . $prev_title . ' " class="add-new-h2">' . _x( '&larr; Previous', 'Admin Post Navigation' ) . '</a>';

}

if ( ! empty( $next_post ) ) {

$next_link = esc_url( admin_url() . 'post.php?post=' . $next_post->ID . '&amp;action=edit' );

$next_title = _x( 'Next post: ', 'Admin Post Navigation' ) . esc_attr( $next_post->post_title );

echo ' <a href="' . $next_link . '" id="adminpostnav-next" title="' . $next_title . ' " class="add-new-h2">' . _x( 'Next &rarr;', 'Admin Post Navigation' ) . '</a>';

}

echo '</span>';
}
?>

Expand Down
27 changes: 24 additions & 3 deletions src/wp-admin/includes/class-wp-screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,30 @@ public function show_screen_options() {
$this->_screen_settings = '';

if ( 'post' === $this->base ) {
$expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
$expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
$expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';

$expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';

$expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . '>';

$expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label>';

/**
* Adds Previous and Next links alongside Add New link.
*
* @since CP-2.0.0
*/
$metaboxhidden = (array) get_user_meta( get_current_user_id(), 'metaboxhidden_' . $this->post_type, true );

$checked = checked( ! in_array( 'adminpostnavspan', $metaboxhidden ), true, false );

$expand .= '<label for="adminpostnav-hide">';

$expand .= '<input id="adminpostnav-hide" class="hide-postbox-tog" name="adminpostnav-hide" type="checkbox" value="adminpostnavspan" ' . esc_attr( $checked ) . '>';

$expand .= _x( 'Enable Previous and Next buttons', 'Admin Post Navigation' );

$expand .= '</label></fieldset>';

$this->_screen_settings = $expand;
}

Expand Down

0 comments on commit a7be20d

Please sign in to comment.