0

I installed a plugin to be able to display a previous post / next post option in the backend, in the post edit screen. However the code does this for all posts and we really would like to build in a restriction.

I would like to restrict the links to point only to the posts made by the logged in (current) user editing his/her own post at that moment.

The code I would like to alter is this (I already added a current user variable, in case I'd need it)

add_action('admin_print_footer_scripts','amm_edit_next_prev_post_button');
function amm_edit_next_prev_post_button(){
    $screen = get_current_screen();
    //echo "<pre>";
    //print_r($screen);
    $supported_types = array('page', 'post');
    if( strpos($screen->parent_file, 'edit.php') !== FALSE && in_array($screen->id, $supported_types) && in_array($screen->post_type, $supported_types) && $screen->action != 'add'){
        //Prev-Next are arranged acc. to post table so switched next to prev and prev to next
        $next_post = get_previous_post();
        $previous_post = get_next_post();
        $current_user = wp_get_current_user();
        ?>
            <!--<style>body{background-color:red !important}</style>-->
            <script>
                if(window.jQuery) {
                    jQuery(document).ready(function($) {
                        $(window).load(function() { 
                            var is_next_post_available = '<?php echo ($next_post->ID) ? true : false ?>';
                            var is_prev_post_available = '<?php echo ($previous_post->ID) ? true : false ?>';

I did some researching and fond this but would be hesitant if I can combine these two ? Modify previous and next post links to current Authors Other posts

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.