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?