Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //edit single post via /edit on post
- function redirect_to_editor() {
- // Check if the request contains /edit
- if (strpos($_SERVER['REQUEST_URI'], '/edit') !== false) {
- // Get the current URL without the /edit part
- $current_url = $_SERVER['REQUEST_URI'];
- $edit_url = str_replace('/edit', '', $current_url);
- // Remove any trailing slashes to prevent issues
- $edit_url = rtrim($edit_url, '/');
- // Log the edit URL for debugging
- error_log('Edit URL: ' . $edit_url);
- // Get the post ID from the URL
- $post_id = url_to_postid($edit_url);
- // Log the post ID for debugging
- error_log('Post ID: ' . $post_id);
- // Check if a valid post ID is found
- if ($post_id) {
- // Redirect to the post editor
- wp_redirect(admin_url('post.php?post=' . $post_id . '&action=edit'));
- exit;
- } else {
- // If post ID is not found, return a 404
- global $wp_query;
- $wp_query->set_404();
- status_header(404);
- nocache_headers();
- include(get_404_template());
- exit;
- }
- }
- }
- add_action('template_redirect', 'redirect_to_editor');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement