0

UPDATE

It seems that get_edit_post_link() is trying to get the Edit url with ?editor, that doesn't exist but if we set manually the url, it will work:

<?php
add_action('init', 'edit_post_please');
function edit_post_please()
{
    if (is_user_logged_in() && current_user_can('edit_posts')) {
        $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        $id = url_to_postid($url);

        $parts = explode("/", $url);
        $editor = end($parts);
        $editor_link = '/wp-admin/post.php?post=' . $id . '&action=edit';

        if ($editor == '?editor') {
            wp_redirect($editor_link);
            exit;
        }
    }
}

If anyone have any suggestions with this idea, please be my guest.


I was thinking in a way to make the editors have a quick way to access the current post editor.

I know we can manage this by showing a Link and make some conditionals to show to some users and login in users, but it would be cool to have something like this.

I thought first in something like:

add_action('init', 'edit_post_please');
function edit_post_please()
{
    if (is_user_logged_in() && current_user_can( 'edit_posts' )) {
        $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    
        $id = url_to_postid($url);


        $parts = explode("/", $url);
        $editor = end($parts);
        $editor_link = get_edit_post_link($id);

        if ($editor == '?editor') {
            wp_redirect($editor_link);
            exit;
        }
    }
}

I haven't think about the security issues or anything else this code does't seem to work at all, I mean it redirects well to Dashboard but not to post I would like to edit.

$editor_link have the correct edit url, but seems that this could be a restriction of WP?

1 Answer 1

0

The reason your code redirects to /wp-admin/edit.php is because the /wp-admin/post.php checks for a referrer using wp_get_referer() before loading.

For this reason, you're best placed using get_edit_post_link() to output links to the page.

If you'd like to continue down the path you started, you'll need to satisfy the referrer conditions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.