| @@ -598,11 +598,34 @@ | ||
| 598 | 598 | return rest_ensure_response( |
| 599 | 599 | array( |
| 600 | 600 | 'noteId' => (int) $post->ID, |
| 601 | 601 | 'postId' => (int) $new_post_id, |
| 602 | - 'editUrl' => (string) get_edit_post_link( $new_post_id, 'raw' ), | |
| 602 | + 'editUrl' => openstation_notes_draft_edit_url( (int) $new_post_id ), | |
| 603 | 603 | ) |
| 604 | 604 | ); |
| 605 | +} | |
| 606 | + | |
| 607 | +/** | |
| 608 | + * The admin edit URL for the draft a note became. | |
| 609 | + * | |
| 610 | + * `get_edit_post_link()` is the canonical answer, and it is filterable: | |
| 611 | + * a host can point it off-site (WordPress.com routes post edit links to | |
| 612 | + * its own editor) or a capability filter can blank it, and the client | |
| 613 | + * opens the URL inside a window that can only ever show THIS site's | |
| 614 | + * wp-admin. So this always answers with the on-site `post.php` URL the | |
| 615 | + * post type registers, whatever a filter made of the pretty one. | |
| 616 | + * | |
| 617 | + * @param int $post_id The draft post id. | |
| 618 | + * @return string Absolute admin URL, or '' when the post is gone. | |
| 619 | + */ | |
| 620 | +function openstation_notes_draft_edit_url( $post_id ) { | |
| 621 | + $draft = get_post( $post_id ); | |
| 622 | + if ( ! $draft instanceof WP_Post ) { | |
| 623 | + return ''; | |
| 624 | + } | |
| 625 | + $type_object = get_post_type_object( $draft->post_type ); | |
| 626 | + $edit_link = $type_object && ! empty( $type_object->_edit_link ) ? $type_object->_edit_link : 'post.php?post=%d'; | |
| 627 | + return admin_url( sprintf( $edit_link, $draft->ID ) . '&action=edit' ); | |
| 605 | 628 | } |
| 606 | 629 | |
| 607 | 630 | /** |
| 608 | 631 | * Whether the current user's desktop would show any pinned notes. |