PluginProbe
Assistant – Every Day Productivity Apps / 1.1.0
Assistant – Every Day Productivity Apps v1.1.0
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
← All changes | backend/src/Data/Transformers/PostTransformer.php +32 -3 0.41.1.0 View file →
@@ -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 ) {