| @@ -1,14 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - | |
| 4 | 3 | namespace FL\Assistant\Data\Transformers; |
| 5 | 4 | |
| 6 | 5 | use FL\Assistant\Data\Repository\NotationsRepository; |
| 7 | 6 | use FL\Assistant\Data\Repository\TermsRepository; |
| 8 | 7 | use FL\Assistant\System\Integrations\BeaverBuilder; |
| 8 | +use FL\Assistant\Helpers\PreviewHelper; | |
| 9 | 9 | |
| 10 | - | |
| 11 | 10 | /** |
| 12 | 11 | * Class PostTransformer |
| 13 | 12 | * |
| 14 | 13 | * Convert a WP_Post object to array suitable for REST output |
| @@ -49,8 +48,23 @@ | ||
| 49 | 48 | |
| 50 | 49 | /** |
| 51 | 50 | * @param \WP_Post $post |
| 52 | 51 | * |
| 52 | + * @return string | |
| 53 | + */ | |
| 54 | + public function get_edit_post_link( \WP_Post $post ) { | |
| 55 | + | |
| 56 | + if ( strstr( $post->post_type, 'wp_template' ) ) { | |
| 57 | + $id = get_stylesheet() . '//' . $post->post_name; | |
| 58 | + return admin_url( "/site-editor.php?postType={$post->post_type}&postId={$id}" ); | |
| 59 | + } | |
| 60 | + | |
| 61 | + return get_edit_post_link( $post->ID, '' ); | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * @param \WP_Post $post | |
| 66 | + * | |
| 53 | 67 | * @return array |
| 54 | 68 | */ |
| 55 | 69 | public function transform( \WP_Post $post ) { |
| 56 | 70 | $author = get_the_author_meta( 'display_name', $post->post_author ); |
| @@ -59,14 +73,27 @@ | ||
| 59 | 73 | |
| 60 | 74 | $thumb_id = get_post_thumbnail_id( $post ); |
| 61 | 75 | $thumb_data = wp_prepare_attachment_for_js( $thumb_id ); |
| 62 | 76 | |
| 77 | + $all_users = get_users( [ 'who' => 'authors' ] ); | |
| 78 | + $users = []; | |
| 79 | + | |
| 80 | + foreach ( $all_users as $user ) { | |
| 81 | + $users[ $user->ID ] = $user->display_name; | |
| 82 | + } | |
| 83 | + | |
| 84 | + if ( ! function_exists( 'wp_check_post_lock' ) ) { | |
| 85 | + require_once ABSPATH . 'wp-admin/includes/post.php'; | |
| 86 | + } | |
| 87 | + | |
| 63 | 88 | $response = [ |
| 64 | 89 | 'author' => $author, |
| 90 | + 'post_author' => $post->post_author, | |
| 65 | 91 | 'commentsAllowed' => 'open' === $post->comment_status ? true : false, |
| 66 | 92 | 'excerpt' => $post->post_excerpt, |
| 67 | 93 | 'date' => $date, |
| 68 | - 'editUrl' => get_edit_post_link( $post->ID, '' ), | |
| 94 | + 'editUrl' => $this->get_edit_post_link( $post ), | |
| 95 | + 'previewUrl' => PreviewHelper::get_post_preview_url( $post ), | |
| 69 | 96 | 'id' => $post->ID, |
| 70 | 97 | 'labels' => [], |
| 71 | 98 | 'order' => $post->menu_order, |
| 72 | 99 | 'parent' => $post->post_parent, |
| @@ -84,8 +111,10 @@ | ||
| 84 | 111 | 'url' => get_permalink( $post ), |
| 85 | 112 | 'visibility' => 'public', |
| 86 | 113 | 'commentsCount' => get_comments_number( $post->ID ), |
| 87 | 114 | 'isSticky' => is_sticky( $post->ID ), |
| 115 | + 'authorList' => $users, | |
| 116 | + 'hasLock' => wp_check_post_lock( $post->ID ), | |
| 88 | 117 | ]; |
| 89 | 118 | |
| 90 | 119 | // Post visibility. |
| 91 | 120 | if ( 'private' === $post->post_status ) { |