Skip to content

Commit

Permalink
Use publicize for fields for now instead of a new class
Browse files Browse the repository at this point in the history
  • Loading branch information
manzoorwanijk committed Dec 16, 2024
1 parent b6adf61 commit b2e8359
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 181 deletions.
170 changes: 0 additions & 170 deletions projects/packages/publicize/src/class-connection-fields.php

This file was deleted.

26 changes: 26 additions & 0 deletions projects/packages/publicize/src/class-publicize-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,32 @@ public function get_username( $service_name, $connection ) {
return $this->get_display_name( $service_name, $connection );
}

/**
* Returns the external handle for the Connection.
*
* @param string $service_name 'facebook', 'linkedin', etc.
* @param object|array $connection The Connection object (WordPress.com) or array (Jetpack).
* @return string
*/
public function get_external_handle( $service_name, $connection ) {
$cmeta = $this->get_connection_meta( $connection );

switch ( $service_name ) {
case 'mastodon':
return $cmeta['external_display'] ?? '';

case 'bluesky':
case 'threads':
return $cmeta['external_name'] ?? '';

case 'instagram-business':
return $cmeta['connection_data']['meta']['username'] ?? '';

default:
return '';
}
}

/**
* Returns a profile picture for the Connection
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager;
use Automattic\Jetpack\Publicize\Connection_Fields;
use Automattic\Jetpack\Publicize\Publicize;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
Expand Down Expand Up @@ -179,23 +179,23 @@ protected static function get_all_connections( $run_tests = false ) {
foreach ( (array) $publicize->get_services( 'connected' ) as $service_name => $connections ) {
foreach ( $connections as $connection ) {

$connection_id = Connection_Fields::get_connection_id( $connection );
$connection_id = $publicize->get_connection_id( $connection );

$connection_meta = Connection_Fields::get_connection_meta( $connection );
$connection_meta = $publicize->get_connection_meta( $connection );
$connection_data = $connection_meta['connection_data'];

$items[] = array(
'connection_id' => $connection_id,
'display_name' => Connection_Fields::get_display_name( $service_name, $connection ),
'external_handle' => Connection_Fields::get_external_handle( $service_name, $connection ),
'external_id' => Connection_Fields::get_external_id( $connection ),
'profile_link' => Connection_Fields::get_profile_link( $service_name, $connection ),
'profile_picture' => Connection_Fields::get_profile_picture( $connection ),
'service_label' => Connection_Fields::get_service_label( $service_name ),
'display_name' => $publicize->get_display_name( $service_name, $connection ),
'external_handle' => $publicize->get_external_handle( $service_name, $connection ),
'external_id' => $connection_meta['external_id'] ?? '',
'profile_link' => $publicize->get_profile_link( $service_name, $connection ),
'profile_picture' => $publicize->get_profile_picture( $connection ),
'service_label' => Publicize::get_service_label( $service_name ),
'service_name' => $service_name,
'shared' => Connection_Fields::is_shared( $connection ),
'shared' => ! $connection_data['user_id'],
'status' => $test_results[ $connection_id ] ?? 'ok',
'user_id' => Connection_Fields::get_user_id( $connection ),
'user_id' => (int) $connection_data['user_id'],

// Deprecated fields.
'id' => (string) $publicize->get_connection_unique_id( $connection ),
Expand Down

0 comments on commit b2e8359

Please sign in to comment.