Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publicize: Move the publicize-connections endpoint to the package #40637

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Publicize: Move the publicize-connections endpoint to the package
28 changes: 18 additions & 10 deletions projects/packages/publicize/src/class-publicize-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ public function get_profile_link( $service_name, $connection ) {
return 'https://instagram.com/' . $cmeta['connection_data']['meta']['username'];
}

if ( 'threads' === $service_name && isset( $connection['external_name'] ) ) {
return 'https://www.threads.net/@' . $connection['external_name'];
if ( 'threads' === $service_name && isset( $cmeta['external_name'] ) ) {
return 'https://www.threads.net/@' . $cmeta['external_name'];
}

if ( 'mastodon' === $service_name && isset( $cmeta['external_name'] ) ) {
Expand Down Expand Up @@ -527,7 +527,7 @@ public function get_profile_link( $service_name, $connection ) {
}

$profile_url_query = wp_parse_url( $cmeta['connection_data']['meta']['profile_url'], PHP_URL_QUERY );
$profile_url_query_args = null;
$profile_url_query_args = array();
wp_parse_str( $profile_url_query, $profile_url_query_args );

$id = null;
Expand Down Expand Up @@ -589,17 +589,25 @@ public function get_display_name( $service_name, $connection ) {
* @return string
*/
public function get_username( $service_name, $connection ) {
$cmeta = $this->get_connection_meta( $connection );
$cmeta = $this->get_connection_meta( $connection );
$username = '';
Comment on lines -592 to +593
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since username field is deprecated in favour of external_handle, we don't need to update it. We are going to remove it anyway in the future.


if ( 'mastodon' === $service_name && isset( $cmeta['external_display'] ) ) {
return $cmeta['external_display'];
switch ( $service_name ) {
case 'mastodon':
$username = $cmeta['external_display'] ?? '';
break;
case 'bluesky':
case 'threads':
$username = $cmeta['external_name'] ?? '';
break;
}

if ( isset( $cmeta['connection_data']['meta']['username'] ) ) {
return $cmeta['connection_data']['meta']['username'];
if ( empty( $username ) ) {
$username = $cmeta['connection-data']['meta']['username'] ?? '';
$username = empty( $username ) ? $this->get_display_name( $service_name, $connection ) : $username;
}

return $this->get_display_name( $service_name, $connection );
return $username;
}

/**
Expand All @@ -608,7 +616,7 @@ public function get_username( $service_name, $connection ) {
* @param object|array $connection The Connection object (WordPress.com) or array (Jetpack).
* @return string
*/
private function get_profile_picture( $connection ) {
public function get_profile_picture( $connection ) {
$cmeta = $this->get_connection_meta( $connection );

if ( isset( $cmeta['profile_picture'] ) ) {
Expand Down
3 changes: 3 additions & 0 deletions projects/packages/publicize/src/class-publicize-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public static function on_jetpack_feature_publicize_enabled() {

}

// @phan-suppress-next-line PhanNoopNew
new REST_API\Connections_Controller();

// Adding on a higher priority to make sure we're the first field registered.
// The priority parameter can be removed once we deprecate WPCOM_REST_API_V2_Post_Publicize_Connections_Field
add_action( 'rest_api_init', array( new Connections_Post_Field(), 'register_fields' ), 5 );
Expand Down
Loading
Loading