From 706ba079e445b45bf7eb69e0df286469829d00f0 Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Wed, 22 Jan 2025 21:55:13 -0800 Subject: [PATCH] Social | Fix profile links for LinkedIn connections (#40873) --- .../fix-social-linkedin-profile-links | 4 +++ .../publicize/src/class-publicize-base.php | 35 +++++++------------ .../fix-social-linkedin-profile-links | 4 +++ .../fix-social-linkedin-profile-links | 4 +++ 4 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 projects/packages/publicize/changelog/fix-social-linkedin-profile-links create mode 100644 projects/plugins/jetpack/changelog/fix-social-linkedin-profile-links create mode 100644 projects/plugins/social/changelog/fix-social-linkedin-profile-links diff --git a/projects/packages/publicize/changelog/fix-social-linkedin-profile-links b/projects/packages/publicize/changelog/fix-social-linkedin-profile-links new file mode 100644 index 0000000000000..e043639911d3a --- /dev/null +++ b/projects/packages/publicize/changelog/fix-social-linkedin-profile-links @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Social: Fix profile links for LinkedIn connections diff --git a/projects/packages/publicize/src/class-publicize-base.php b/projects/packages/publicize/src/class-publicize-base.php index d707968be7b2f..613e7b2ceddff 100644 --- a/projects/packages/publicize/src/class-publicize-base.php +++ b/projects/packages/publicize/src/class-publicize-base.php @@ -497,6 +497,19 @@ public function get_profile_link( $service_name, $connection ) { return 'https://instagram.com/' . $cmeta['connection_data']['meta']['username']; } + if ( 'linkedin' === $service_name ) { + + $entity_type = $cmeta['connection_data']['meta']['entity_type'] ?? 'person'; + + if ( 'organization' === $entity_type && ! empty( $cmeta['connection_data']['meta']['external_name'] ) ) { + return 'https://www.linkedin.com/company/' . $cmeta['connection_data']['meta']['external_name']; + } + + if ( 'person' === $entity_type && ! empty( $cmeta['external_name'] ) ) { + return 'https://www.linkedin.com/in/' . $cmeta['external_name']; + } + } + if ( 'threads' === $service_name && isset( $cmeta['external_name'] ) ) { return 'https://www.threads.net/@' . $cmeta['external_name']; } @@ -521,28 +534,6 @@ public function get_profile_link( $service_name, $connection ) { return 'https://bsky.app/profile/' . $cmeta['external_id']; } - if ( 'linkedin' === $service_name ) { - if ( ! isset( $cmeta['connection_data']['meta']['profile_url'] ) ) { - return false; - } - - $profile_url_query = wp_parse_url( $cmeta['connection_data']['meta']['profile_url'], PHP_URL_QUERY ); - $profile_url_query_args = array(); - wp_parse_str( $profile_url_query, $profile_url_query_args ); - - $id = null; - - if ( isset( $profile_url_query_args['key'] ) ) { - $id = $profile_url_query_args['key']; - } elseif ( isset( $profile_url_query_args['id'] ) ) { - $id = $profile_url_query_args['id']; - } else { - return false; - } - - return esc_url_raw( add_query_arg( 'id', rawurlencode( $id ), 'https://www.linkedin.com/profile/view' ) ); - } - return false; // no fallback. we just won't link it. } diff --git a/projects/plugins/jetpack/changelog/fix-social-linkedin-profile-links b/projects/plugins/jetpack/changelog/fix-social-linkedin-profile-links new file mode 100644 index 0000000000000..06f9ff81b9f67 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-social-linkedin-profile-links @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Social: Fix profile links for LinkedIn connections diff --git a/projects/plugins/social/changelog/fix-social-linkedin-profile-links b/projects/plugins/social/changelog/fix-social-linkedin-profile-links new file mode 100644 index 0000000000000..fbcf7bc784a02 --- /dev/null +++ b/projects/plugins/social/changelog/fix-social-linkedin-profile-links @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed profile links for LinkedIn connections