editor – Edit Post with a parameter in URL


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') {

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?

Locke 1 year 2021-07-24T16:27:07-05:00 0 Answers 0 views 0

Leave an answer