PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / jetpack_vendor / automattic / jetpack-publicize / src / class-share-status.php

class-share-status.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.5, at jetpack_vendor/automattic/jetpack-publicize/src/class-share-status.php

73 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Publicize Share Status class.
4 *
5 * @package automattic/jetpack-publicize
6 */
7
8 namespace Automattic\Jetpack\Publicize;
9
10 /**
11 * Publicize Services class.
12 */
13 class Share_Status {
14 const SHARES_META_KEY = '_publicize_shares';
15
16 /**
17 * Gets the share status for a post.
18 *
19 * @param int $post_id The post ID.
20 * @param bool $filter_by_access Whether to filter the shares by access.
21 */
22 public static function get_post_share_status( $post_id, $filter_by_access = true ) {
23
24 $post = get_post( $post_id );
25
26 if ( empty( $post ) || ! metadata_exists( 'post', $post_id, self::SHARES_META_KEY ) ) {
27 return array(
28 'done' => false,
29 'shares' => array(),
30 );
31 }
32
33 $shares = get_post_meta( $post_id, self::SHARES_META_KEY, true );
34
35 // If the data is in an associative array format, we fetch it without true to get all the shares.
36 // This is needed to support the old WPCOM format.
37 if ( isset( $shares ) && is_array( $shares ) && ! array_is_list( $shares ) ) {
38 $shares = get_post_meta( $post_id, self::SHARES_META_KEY, false );
39 }
40
41 // Better safe than sorry.
42 if ( empty( $shares ) ) {
43 $shares = array();
44 }
45
46 if ( $filter_by_access ) {
47 // The site could have multiple admins, editors and authors connected. Load shares information that only the current user has access to.
48 $connection_ids = wp_list_pluck( Connections::get_all_for_user(), 'connection_id', 'connection_id' );
49
50 $shares = array_filter(
51 $shares,
52 function ( $share ) use ( $connection_ids ) {
53 return isset( $share['connection_id'] ) && isset( $connection_ids[ $share['connection_id'] ] );
54 }
55 );
56 }
57
58 usort(
59 $shares,
60 function ( $a, $b ) {
61 return $b['timestamp'] - $a['timestamp'];
62 }
63 );
64
65 $shares = array_values( $shares );
66
67 return array(
68 'shares' => $shares,
69 'done' => true,
70 );
71 }
72 }
73