false, 'shares' => array(), ); } $shares = get_post_meta( $post_id, self::SHARES_META_KEY, true ); // If the data is in an associative array format, we fetch it without true to get all the shares. // This is needed to support the old WPCOM format. if ( isset( $shares ) && is_array( $shares ) && ! array_is_list( $shares ) ) { $shares = get_post_meta( $post_id, self::SHARES_META_KEY, false ); } // Better safe than sorry. if ( empty( $shares ) ) { $shares = array(); } if ( $filter_by_access ) { // The site could have multiple admins, editors and authors connected. Load shares information that only the current user has access to. $connection_ids = wp_list_pluck( Connections::get_all_for_user(), 'connection_id', 'connection_id' ); $shares = array_filter( $shares, function ( $share ) use ( $connection_ids ) { return isset( $share['connection_id'] ) && isset( $connection_ids[ $share['connection_id'] ] ); } ); } usort( $shares, function ( $a, $b ) { return $b['timestamp'] - $a['timestamp']; } ); $shares = array_values( $shares ); return array( 'shares' => $shares, 'done' => true, ); } }