PluginProbe
Parse.ly / 3.8.4
Parse.ly v3.8.4
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
← All changes | src/Endpoints/class-analytics-posts-api-proxy.php +25 -1 3.16.33.8.4 View file →
@@ -12,9 +12,12 @@
12 12
13 13 use stdClass;
14 14 use WP_REST_Request;
15 15 use WP_Error;
16 +use Parsely\Parsely;
16 17
18 +use function Parsely\Utils\get_date_format;
19 +
17 20 /**
18 21 * Configures the `/stats/posts` REST API endpoint.
19 22 */
20 23 final class Analytics_Posts_API_Proxy extends Base_API_Proxy {
@@ -29,8 +32,9 @@
29 32 /**
30 33 * Cached "proxy" to the Parse.ly `/analytics/posts` API endpoint.
31 34 *
32 35 * @param WP_REST_Request $request The request object.
36 + *
33 37 * @return stdClass|WP_Error stdClass containing the data or a WP_Error object on failure.
34 38 */
35 39 public function get_items( WP_REST_Request $request ) {
36 40 return $this->get_data( $request );
@@ -42,7 +46,27 @@
42 46 * @param array<stdClass> $response The response received by the proxy.
43 47 * @return array<stdClass> The generated data.
44 48 */
45 49 protected function generate_data( $response ): array {
46 - return $this->generate_post_data( $response );
50 + $date_format = get_date_format();
51 + $site_id = $this->parsely->get_site_id();
52 +
53 + return array_map(
54 + static function( stdClass $item ) use ( $date_format, $site_id ) {
55 + return (object) array(
56 + 'author' => $item->author,
57 + 'dashUrl' => Parsely::get_dash_url( $site_id, $item->url ),
58 + 'date' => $item->pub_date ? wp_date( $date_format, strtotime( $item->pub_date ) ) : null,
59 + // Unique ID (can be replaced by Parse.ly API ID if it becomes available).
60 + 'id' => $item->url,
61 + // WordPress Post ID (0 if the post cannot be found, might not be unique).
62 + 'postId' => url_to_postid( $item->url ), // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.url_to_postid_url_to_postid
63 + 'thumbUrlMedium' => $item->thumb_url_medium,
64 + 'title' => $item->title,
65 + 'url' => $item->url,
66 + 'views' => $item->metrics->views,
67 + );
68 + },
69 + $response
70 + );
47 71 }
48 72 }