2022-04-02 10:26:41 +02:00
< ? php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Publicize class .
*
* @ package automattic / jetpack
*/
2019-11-15 23:26:29 +01:00
2021-04-27 08:32:47 +02:00
use Automattic\Jetpack\Connection\Tokens ;
2020-05-06 17:20:49 +02:00
use Automattic\Jetpack\Redirect ;
2022-04-02 10:26:41 +02:00
/**
* Extend the base class with Jetpack - specific functionality .
*/
2019-11-15 23:26:29 +01:00
class Publicize extends Publicize_Base {
2022-04-02 10:26:41 +02:00
const CONNECTION_REFRESH_WAIT_TRANSIENT = 'jetpack_publicize_connection_refresh_wait' ;
/**
* Add hooks .
*/
public function __construct () {
2019-11-15 23:26:29 +01:00
parent :: __construct ();
2020-11-18 09:10:44 +01:00
add_filter ( 'jetpack_xmlrpc_unauthenticated_methods' , array ( $this , 'register_update_publicize_connections_xmlrpc_method' ) );
2019-11-15 23:26:29 +01:00
add_action ( 'load-settings_page_sharing' , array ( $this , 'admin_page_load' ), 9 );
add_action ( 'wp_ajax_publicize_tumblr_options_page' , array ( $this , 'options_page_tumblr' ) );
add_action ( 'wp_ajax_publicize_facebook_options_page' , array ( $this , 'options_page_facebook' ) );
add_action ( 'wp_ajax_publicize_twitter_options_page' , array ( $this , 'options_page_twitter' ) );
add_action ( 'wp_ajax_publicize_linkedin_options_page' , array ( $this , 'options_page_linkedin' ) );
add_action ( 'wp_ajax_publicize_tumblr_options_save' , array ( $this , 'options_save_tumblr' ) );
add_action ( 'wp_ajax_publicize_facebook_options_save' , array ( $this , 'options_save_facebook' ) );
add_action ( 'wp_ajax_publicize_twitter_options_save' , array ( $this , 'options_save_twitter' ) );
add_action ( 'wp_ajax_publicize_linkedin_options_save' , array ( $this , 'options_save_linkedin' ) );
add_action ( 'load-settings_page_sharing' , array ( $this , 'force_user_connection' ) );
add_filter ( 'jetpack_published_post_flags' , array ( $this , 'set_post_flags' ), 10 , 2 );
2022-04-02 10:26:41 +02:00
add_action ( 'wp_insert_post' , array ( $this , 'save_publicized' ), 11 , 2 );
2019-11-15 23:26:29 +01:00
add_filter ( 'jetpack_twitter_cards_site_tag' , array ( $this , 'enhaced_twitter_cards_site_tag' ) );
add_action ( 'publicize_save_meta' , array ( $this , 'save_publicized_twitter_account' ), 10 , 4 );
add_action ( 'publicize_save_meta' , array ( $this , 'save_publicized_facebook_account' ), 10 , 4 );
add_action ( 'connection_disconnected' , array ( $this , 'add_disconnect_notice' ) );
add_filter ( 'jetpack_sharing_twitter_via' , array ( $this , 'get_publicized_twitter_account' ), 10 , 2 );
2022-04-02 10:26:41 +02:00
add_action ( 'updating_jetpack_version' , array ( $this , 'init_refresh_transient' ) );
2019-11-15 23:26:29 +01:00
jetpack_require_lib ( 'class.jetpack-keyring-service-helper' );
}
2022-04-02 10:26:41 +02:00
/**
* Add a notice when a connection has been disconnected .
*/
public function add_disconnect_notice () {
2019-11-15 23:26:29 +01:00
add_action ( 'admin_notices' , array ( $this , 'display_disconnected' ) );
}
2022-04-02 10:26:41 +02:00
/**
* Force user connection before showing the Publicize UI .
*/
public function force_user_connection () {
2019-11-15 23:26:29 +01:00
global $current_user ;
2022-04-02 10:26:41 +02:00
2021-04-27 08:32:47 +02:00
$user_token = ( new Tokens () ) -> get_access_token ( $current_user -> ID );
2019-11-15 23:26:29 +01:00
$is_user_connected = $user_token && ! is_wp_error ( $user_token );
2022-04-02 10:26:41 +02:00
// If the user is already connected via Jetpack, then we're good.
2019-11-15 23:26:29 +01:00
if ( $is_user_connected ) {
return ;
}
2022-04-02 10:26:41 +02:00
// If they're not connected, then remove the Publicize UI and tell them they need to connect first.
2019-11-15 23:26:29 +01:00
global $publicize_ui ;
remove_action ( 'pre_admin_screen_sharing' , array ( $publicize_ui , 'admin_page' ) );
// Do we really need `admin_styles`? With the new admin UI, it's breaking some bits.
2022-04-02 10:26:41 +02:00
// Jetpack::init()->admin_styles();.
2019-11-15 23:26:29 +01:00
add_action ( 'pre_admin_screen_sharing' , array ( $this , 'admin_page_warning' ), 1 );
}
2022-04-02 10:26:41 +02:00
/**
* Show a warning when Publicize does not have a connection .
*/
public function admin_page_warning () {
2019-11-15 23:26:29 +01:00
$jetpack = Jetpack :: init ();
$blog_name = get_bloginfo ( 'blogname' );
if ( empty ( $blog_name ) ) {
$blog_name = home_url ( '/' );
}
?>
< div id = " message " class = " updated jetpack-message jp-connect " >
< div class = " jetpack-wrap-container " >
< div class = " jetpack-text-container " >
2022-04-02 10:26:41 +02:00
< p >
< ? php
printf (
/* translators: %s is the name of the blog */
esc_html ( wptexturize ( __ ( " To use Publicize, you'll need to link your %s account to your WordPress.com account using the link below. " , 'jetpack' ) ) ),
'<strong>' . esc_html ( $blog_name ) . '</strong>'
);
?>
</ p >
2019-11-15 23:26:29 +01:00
< p >< ? php echo esc_html ( wptexturize ( __ ( " If you don't have a WordPress.com account yet, you can sign up for free in just a few seconds. " , 'jetpack' ) ) ); ?> </p>
</ div >
< div class = " jetpack-install-container " >
< p class = " submit " >< a
2022-04-02 10:26:41 +02:00
href = " <?php echo esc_url( $jetpack->build_connect_url ( false, menu_page_url( 'sharing', false ) ) ); ?> "
2019-11-15 23:26:29 +01:00
class = " button-connector "
id = " wpcom-connect " >< ? php esc_html_e ( 'Link account with WordPress.com' , 'jetpack' ); ?> </a>
</ p >
< p class = " jetpack-install-blurb " >
< ? php jetpack_render_tos_blurb (); ?>
</ p >
</ div >
</ div >
</ div >
< ? php
}
/**
2022-04-02 10:26:41 +02:00
* Remove a Publicize Connection .
*
* @ param string $service_name 'facebook' , 'twitter' , etc .
* @ param string $connection_id Connection ID .
* @ param false | int $_blog_id The blog ID . Use false ( default ) for the current blog .
* @ param false | int $_user_id The user ID . Use false ( default ) for the current user .
* @ param bool $force_delete Whether to skip permissions checks .
* @ return false | void False on failure . Void on success .
2019-11-15 23:26:29 +01:00
*/
2022-04-02 10:26:41 +02:00
public function disconnect ( $service_name , $connection_id , $_blog_id = false , $_user_id = false , $force_delete = false ) {
2019-11-15 23:26:29 +01:00
return Jetpack_Keyring_Service_Helper :: disconnect ( $service_name , $connection_id , $_blog_id , $_user_id , $force_delete );
}
2022-04-02 10:26:41 +02:00
/**
* Set updated Publicize conntections .
*
* @ param mixed $publicize_connections Updated connections .
* @ return true
*/
public function receive_updated_publicize_connections ( $publicize_connections ) {
2019-11-15 23:26:29 +01:00
Jetpack_Options :: update_option ( 'publicize_connections' , $publicize_connections );
return true ;
}
2022-04-02 10:26:41 +02:00
/**
* Add method to update Publicize connections .
*
* @ param array $methods Array of registered methods .
* @ return array
*/
public function register_update_publicize_connections_xmlrpc_method ( $methods ) {
return array_merge (
$methods ,
array (
'jetpack.updatePublicizeConnections' => array ( $this , 'receive_updated_publicize_connections' ),
)
);
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
/**
* Get a list of all connections .
*
* @ return array
*/
public function get_all_connections () {
$this -> refresh_connections ();
2019-11-15 23:26:29 +01:00
$connections = Jetpack_Options :: get_option ( 'publicize_connections' );
if ( isset ( $connections [ 'google_plus' ] ) ) {
unset ( $connections [ 'google_plus' ] );
}
return $connections ;
}
2022-04-02 10:26:41 +02:00
/**
* Get connections for a specific service .
*
* @ param string $service_name 'facebook' , 'twitter' , etc .
* @ param false | int $_blog_id The blog ID . Use false ( default ) for the current blog .
* @ param false | int $_user_id The user ID . Use false ( default ) for the current user .
* @ return false | object [] | array []
*/
public function get_connections ( $service_name , $_blog_id = false , $_user_id = false ) {
2019-11-15 23:26:29 +01:00
if ( false === $_user_id ) {
$_user_id = $this -> user_id ();
}
$connections = $this -> get_all_connections ();
$connections_to_return = array ();
if ( ! empty ( $connections ) && is_array ( $connections ) ) {
if ( ! empty ( $connections [ $service_name ] ) ) {
foreach ( $connections [ $service_name ] as $id => $connection ) {
2022-04-02 10:26:41 +02:00
if ( $this -> is_global_connection ( $connection ) || $_user_id === ( int ) $connection [ 'connection_data' ][ 'user_id' ] ) {
2019-11-15 23:26:29 +01:00
$connections_to_return [ $id ] = $connection ;
}
}
}
return $connections_to_return ;
}
return false ;
}
2022-04-02 10:26:41 +02:00
/**
* Get all connections for a specific user .
*
* @ return array | false
*/
public function get_all_connections_for_user () {
2019-11-15 23:26:29 +01:00
$connections = $this -> get_all_connections ();
$connections_to_return = array ();
if ( ! empty ( $connections ) ) {
foreach ( ( array ) $connections as $service_name => $connections_for_service ) {
foreach ( $connections_for_service as $id => $connection ) {
2020-11-18 09:10:44 +01:00
$user_id = ( int ) $connection [ 'connection_data' ][ 'user_id' ];
2019-11-15 23:26:29 +01:00
// phpcs:ignore WordPress.PHP.YodaConditions.NotYoda
if ( $user_id === 0 || $this -> user_id () === $user_id ) {
$connections_to_return [ $service_name ][ $id ] = $connection ;
}
}
}
return $connections_to_return ;
}
return false ;
}
2022-04-02 10:26:41 +02:00
/**
* Get the ID of a connection .
*
* @ param array $connection The connection .
* @ return string
*/
public function get_connection_id ( $connection ) {
2019-11-15 23:26:29 +01:00
return $connection [ 'connection_data' ][ 'id' ];
}
2022-04-02 10:26:41 +02:00
/**
* Get the unique ID of a connection .
*
* @ param array $connection The connection .
* @ return string
*/
public function get_connection_unique_id ( $connection ) {
2019-11-15 23:26:29 +01:00
return $connection [ 'connection_data' ][ 'token_id' ];
}
2022-04-02 10:26:41 +02:00
/**
* Get the meta of a connection .
*
* @ param array $connection The connection .
* @ return array
*/
public function get_connection_meta ( $connection ) {
$connection [ 'user_id' ] = $connection [ 'connection_data' ][ 'user_id' ]; // Allows for shared connections.
2019-11-15 23:26:29 +01:00
return $connection ;
}
2022-04-02 10:26:41 +02:00
/**
* Show error on settings page if applicable .
*/
public function admin_page_load () {
2022-06-16 14:01:47 +02:00
$action = isset ( $_GET [ 'action' ] ) ? sanitize_text_field ( wp_unslash ( $_GET [ 'action' ] ) ) : null ; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
2022-04-02 10:26:41 +02:00
2022-06-16 14:01:47 +02:00
if ( 'error' === $action ) {
2022-04-02 10:26:41 +02:00
add_action ( 'pre_admin_screen_sharing' , array ( $this , 'display_connection_error' ), 9 );
2019-11-15 23:26:29 +01:00
}
}
2022-04-02 10:26:41 +02:00
/**
* Display an error message .
*/
public function display_connection_error () {
2019-11-15 23:26:29 +01:00
$code = false ;
2022-04-02 10:26:41 +02:00
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$service = isset ( $_GET [ 'service' ] ) ? sanitize_text_field ( wp_unslash ( $_GET [ 'service' ] ) ) : null ;
$publicize_error = isset ( $_GET [ 'publicize_error' ] ) ? sanitize_text_field ( wp_unslash ( $_GET [ 'publicize_error' ] ) ) : null ;
// phpcs:enable WordPress.Security.NonceVerification.Recommended
if ( $service ) {
/* translators: %s is the name of the Publicize service (e.g. Facebook, Twitter) */
$error = sprintf ( __ ( 'There was a problem connecting to %s to create an authorized connection. Please try again in a moment.' , 'jetpack' ), self :: get_service_label ( $service ) );
2019-11-15 23:26:29 +01:00
} else {
2022-04-02 10:26:41 +02:00
if ( $publicize_error ) {
$code = strtolower ( $publicize_error );
2019-11-15 23:26:29 +01:00
switch ( $code ) {
case '400' :
$error = __ ( 'An invalid request was made. This normally means that something intercepted or corrupted the request from your server to the Jetpack Server. Try again and see if it works this time.' , 'jetpack' );
break ;
case 'secret_mismatch' :
$error = __ ( 'We could not verify that your server is making an authorized request. Please try again, and make sure there is nothing interfering with requests from your server to the Jetpack Server.' , 'jetpack' );
break ;
case 'empty_blog_id' :
$error = __ ( 'No blog_id was included in your request. Please try disconnecting Jetpack from WordPress.com and then reconnecting it. Once you have done that, try connecting Publicize again.' , 'jetpack' );
break ;
case 'empty_state' :
2022-04-02 10:26:41 +02:00
/* translators: %s is the URL of the Jetpack admin page */
2019-11-15 23:26:29 +01:00
$error = sprintf ( __ ( 'No user information was included in your request. Please make sure that your user account has connected to Jetpack. Connect your user account by going to the <a href="%s">Jetpack page</a> within wp-admin.' , 'jetpack' ), Jetpack :: admin_url () );
break ;
default :
$error = __ ( 'Something which should never happen, happened. Sorry about that. If you try again, maybe it will work.' , 'jetpack' );
break ;
}
} else {
$error = __ ( 'There was a problem connecting with Publicize. Please try again in a moment.' , 'jetpack' );
}
}
2022-04-02 10:26:41 +02:00
// Using the same formatting/style as Jetpack::admin_notices() error.
2019-11-15 23:26:29 +01:00
?>
< div id = " message " class = " jetpack-message jetpack-err " >
< div class = " squeezer " >
2022-04-02 10:26:41 +02:00
< h2 >
< ? php
echo wp_kses (
$error ,
array (
'a' => array (
'href' => true ,
),
'code' => true ,
'strong' => true ,
'br' => true ,
'b' => true ,
)
);
?>
</ h2 >
2019-11-15 23:26:29 +01:00
< ? php if ( $code ) : ?>
2022-04-02 10:26:41 +02:00
< p >
< ? php
printf (
/* translators: %s is the name of the error */
esc_html__ ( 'Error code: %s' , 'jetpack' ),
esc_html ( stripslashes ( $code ) )
);
?>
</ p >
2019-11-15 23:26:29 +01:00
< ? php endif ; ?>
</ div >
</ div >
< ? php
}
2022-04-02 10:26:41 +02:00
/**
* Show a message that the connection has been removed .
*/
public function display_disconnected () {
2019-11-15 23:26:29 +01:00
echo " <div class='updated'> \n " ;
echo '<p>' . esc_html ( __ ( 'That connection has been removed.' , 'jetpack' ) ) . " </p> \n " ;
echo " </div> \n \n " ;
}
2022-04-02 10:26:41 +02:00
/**
* If applicable , globalize a connection .
*
* @ param string $connection_id Connection ID .
*/
public function globalization ( $connection_id ) {
2022-06-16 14:01:47 +02:00
if ( isset ( $_REQUEST [ 'global' ] ) && 'on' === $_REQUEST [ 'global' ] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce check happens earlier in the process before we get here
2022-04-02 10:26:41 +02:00
if ( ! current_user_can ( $this -> GLOBAL_CAP ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2019-11-15 23:26:29 +01:00
return ;
}
2022-04-02 10:26:41 +02:00
$this -> globalize_connection ( $connection_id );
2019-11-15 23:26:29 +01:00
}
}
2022-04-02 10:26:41 +02:00
/**
* Globalize a connection .
*
* @ param string $connection_id Connection ID .
*/
public function globalize_connection ( $connection_id ) {
2019-11-15 23:26:29 +01:00
$xml = new Jetpack_IXR_Client ();
$xml -> query ( 'jetpack.globalizePublicizeConnection' , $connection_id , 'globalize' );
if ( ! $xml -> isError () ) {
$response = $xml -> getResponse ();
$this -> receive_updated_publicize_connections ( $response );
}
}
2022-04-02 10:26:41 +02:00
/**
* Unglobalize a connection .
*
* @ param string $connection_id Connection ID .
*/
public function unglobalize_connection ( $connection_id ) {
2019-11-15 23:26:29 +01:00
$xml = new Jetpack_IXR_Client ();
$xml -> query ( 'jetpack.globalizePublicizeConnection' , $connection_id , 'unglobalize' );
if ( ! $xml -> isError () ) {
$response = $xml -> getResponse ();
$this -> receive_updated_publicize_connections ( $response );
}
}
2022-04-02 10:26:41 +02:00
/**
* As Jetpack updates set the refresh transient to a random amount
* in order to spread out updates to the connection data .
*
* @ param string $version The Jetpack version being updated to .
*/
public function init_refresh_transient ( $version ) {
if ( version_compare ( $version , '10.2.1' , '>=' ) && ! get_transient ( self :: CONNECTION_REFRESH_WAIT_TRANSIENT ) ) {
$this -> set_refresh_wait_transient ( wp_rand ( 10 , HOUR_IN_SECONDS * 24 ) );
}
}
/**
* Grabs a fresh copy of the publicize connections data .
* Only refreshes once every 12 hours or retries after an hour with an error .
*/
public function refresh_connections () {
if ( get_transient ( self :: CONNECTION_REFRESH_WAIT_TRANSIENT ) ) {
return ;
}
$xml = new Jetpack_IXR_Client ();
$xml -> query ( 'jetpack.fetchPublicizeConnections' );
$wait_time = HOUR_IN_SECONDS * 24 ;
if ( ! $xml -> isError () ) {
$response = $xml -> getResponse ();
$this -> receive_updated_publicize_connections ( $response );
} else {
// Retry a bit quicker, but still wait.
$wait_time = HOUR_IN_SECONDS ;
}
$this -> set_refresh_wait_transient ( $wait_time );
}
/**
* Sets the transient to expire at the specified time in seconds .
* This prevents us from attempting to refresh the data too often .
*
* @ param int $wait_time The number of seconds before the transient should expire .
*/
public function set_refresh_wait_transient ( $wait_time ) {
set_transient ( self :: CONNECTION_REFRESH_WAIT_TRANSIENT , microtime ( true ), $wait_time );
}
/**
* Get the Publicize connect URL from Keyring .
*
* @ param string $service_name Name of the service to get connect URL for .
* @ param string $for What the URL is for . Default 'publicize' .
* @ return string
*/
public function connect_url ( $service_name , $for = 'publicize' ) {
2019-11-15 23:26:29 +01:00
return Jetpack_Keyring_Service_Helper :: connect_url ( $service_name , $for );
}
2022-04-02 10:26:41 +02:00
/**
* Get the Publicize refresh URL from Keyring .
*
* @ param string $service_name Name of the service to get refresh URL for .
* @ param string $for What the URL is for . Default 'publicize' .
* @ return string
*/
public function refresh_url ( $service_name , $for = 'publicize' ) {
2019-11-15 23:26:29 +01:00
return Jetpack_Keyring_Service_Helper :: refresh_url ( $service_name , $for );
}
2022-04-02 10:26:41 +02:00
/**
* Get the Publicize disconnect URL from Keyring .
*
* @ param string $service_name Name of the service to get disconnect URL for .
* @ param mixed $id ID of the conenction to disconnect .
* @ return string
*/
public function disconnect_url ( $service_name , $id ) {
2019-11-15 23:26:29 +01:00
return Jetpack_Keyring_Service_Helper :: disconnect_url ( $service_name , $id );
}
/**
* Get social networks , either all available or only those that the site is connected to .
*
* @ since 2.0 . 0
* @ since 6.6 . 0 Removed Path . Service closed October 2018.
*
2022-04-02 10:26:41 +02:00
* @ param string $filter Select the list of services that will be returned . Defaults to 'all' , accepts 'connected' .
* @ param false | int $_blog_id Get services for a specific blog by ID , or set to false for current blog . Default false .
* @ param false | int $_user_id Get services for a specific user by ID , or set to false for current user . Default false .
2019-11-15 23:26:29 +01:00
* @ return array List of social networks .
*/
2022-04-02 10:26:41 +02:00
public function get_services ( $filter = 'all' , $_blog_id = false , $_user_id = false ) {
2019-11-15 23:26:29 +01:00
$services = array (
2022-04-02 10:26:41 +02:00
'facebook' => array (),
'twitter' => array (),
'linkedin' => array (),
'tumblr' => array (),
2019-11-15 23:26:29 +01:00
);
2022-04-02 10:26:41 +02:00
if ( 'all' === $filter ) {
2019-11-15 23:26:29 +01:00
return $services ;
2022-04-02 10:26:41 +02:00
}
$connected_services = array ();
foreach ( $services as $service_name => $empty ) {
$connections = $this -> get_connections ( $service_name , $_blog_id , $_user_id );
if ( $connections ) {
$connected_services [ $service_name ] = $connections ;
2019-11-15 23:26:29 +01:00
}
}
2022-04-02 10:26:41 +02:00
return $connected_services ;
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
/**
* Get a specific connection . Stub .
*
* @ param string $service_name 'facebook' , 'twitter' , etc .
* @ param string $connection_id Connection ID .
* @ param false | int $_blog_id The blog ID . Use false ( default ) for the current blog .
* @ param false | int $_user_id The user ID . Use false ( default ) for the current user .
* @ return void
*/
public function get_connection ( $service_name , $connection_id , $_blog_id = false , $_user_id = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
// Stub.
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
/**
* Flag a post for Publicize after publishing .
*
* @ param string $new_status New status of the post .
* @ param string $old_status Old status of the post .
* @ param WP_Post $post Post object .
*/
public function flag_post_for_publicize ( $new_status , $old_status , $post ) {
2019-11-15 23:26:29 +01:00
if ( ! $this -> post_type_is_publicizeable ( $post -> post_type ) ) {
return ;
}
2022-06-16 14:01:47 +02:00
$should_publicize = $this -> should_submit_post_pre_checks ( $post );
2022-04-02 10:26:41 +02:00
if ( 'publish' === $new_status && 'publish' !== $old_status ) {
2019-11-15 23:26:29 +01:00
/**
* Determines whether a post being published gets publicized .
*
* Side - note : Possibly our most alliterative filter name .
*
* @ module publicize
*
* @ since 4.1 . 0
2022-06-16 14:01:47 +02:00
* @ since 10.9 No longer defaults to true . Adds checks to not publicize based on different contexts .
2019-11-15 23:26:29 +01:00
*
* @ param bool $should_publicize Should the post be publicized ? Default to true .
* @ param WP_POST $post Current Post object .
*/
2022-06-16 14:01:47 +02:00
$should_publicize = apply_filters ( 'publicize_should_publicize_published_post' , $should_publicize , $post );
2019-11-15 23:26:29 +01:00
if ( $should_publicize ) {
2022-04-02 10:26:41 +02:00
update_post_meta ( $post -> ID , $this -> PENDING , true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2019-11-15 23:26:29 +01:00
}
}
}
2022-04-02 10:26:41 +02:00
/**
* Test a connection .
*
* @ param string $service_name Name of the service .
* @ param array $connection Connection to be tested .
*/
public function test_connection ( $service_name , $connection ) {
2019-11-15 23:26:29 +01:00
$id = $this -> get_connection_id ( $connection );
$xml = new Jetpack_IXR_Client ();
$xml -> query ( 'jetpack.testPublicizeConnection' , $id );
2022-04-02 10:26:41 +02:00
// Bail if all is well.
2019-11-15 23:26:29 +01:00
if ( ! $xml -> isError () ) {
return true ;
}
$xml_response = $xml -> getResponse ();
$connection_test_message = $xml_response [ 'faultString' ];
2022-04-02 10:26:41 +02:00
// Set up refresh if the user can.
$user_can_refresh = current_user_can ( $this -> GLOBAL_CAP ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2019-11-15 23:26:29 +01:00
if ( $user_can_refresh ) {
2022-04-02 10:26:41 +02:00
/* translators: %s is the name of a social media service */
2019-11-15 23:26:29 +01:00
$refresh_text = sprintf ( _x ( 'Refresh connection with %s' , 'Refresh connection with {social media service}' , 'jetpack' ), $this -> get_service_label ( $service_name ) );
$refresh_url = $this -> refresh_url ( $service_name );
}
$error_data = array (
'user_can_refresh' => $user_can_refresh ,
'refresh_text' => $refresh_text ,
2022-04-02 10:26:41 +02:00
'refresh_url' => $refresh_url ,
2019-11-15 23:26:29 +01:00
);
return new WP_Error ( 'pub_conn_test_failed' , $connection_test_message , $error_data );
}
/**
* Checks if post has already been shared by Publicize in the past .
*
* Jetpack uses two methods :
* 1. A POST_DONE . 'all' postmeta flag , or
* 2. if the post has already been published .
*
* @ since 6.7 . 0
*
* @ param integer $post_id Optional . Post ID to query connection status for : will use current post if missing .
*
* @ return bool True if post has already been shared by Publicize , false otherwise .
*/
public function post_is_done_sharing ( $post_id = null ) {
// Defaults to current post if $post_id is null.
$post = get_post ( $post_id );
2022-06-16 14:01:47 +02:00
if ( $post === null ) {
2019-11-15 23:26:29 +01:00
return false ;
}
2022-04-02 10:26:41 +02:00
return 'publish' === $post -> post_status || get_post_meta ( $post -> ID , $this -> POST_DONE . 'all' , true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2019-11-15 23:26:29 +01:00
}
/**
* Save a flag locally to indicate that this post has already been Publicized via the selected
* connections .
2022-04-02 10:26:41 +02:00
*
* @ param int $post_ID Post ID .
* @ param \WP_Post $post Post object .
2019-11-15 23:26:29 +01:00
*/
2022-04-02 10:26:41 +02:00
public function save_publicized ( $post_ID , $post = null ) {
2022-06-16 14:01:47 +02:00
if ( $post === null ) {
2019-11-15 23:26:29 +01:00
return ;
}
2022-04-02 10:26:41 +02:00
// Only do this when a post transitions to being published.
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2019-11-15 23:26:29 +01:00
if ( get_post_meta ( $post -> ID , $this -> PENDING ) && $this -> post_type_is_publicizeable ( $post -> post_type ) ) {
delete_post_meta ( $post -> ID , $this -> PENDING );
update_post_meta ( $post -> ID , $this -> POST_DONE . 'all' , true );
}
2022-04-02 10:26:41 +02:00
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
/**
* Set post flags for Publicize .
*
* @ param array $flags List of flags .
* @ param \WP_Post $post Post object .
* @ return array
*/
public function set_post_flags ( $flags , $post ) {
2019-11-15 23:26:29 +01:00
$flags [ 'publicize_post' ] = false ;
if ( ! $this -> post_type_is_publicizeable ( $post -> post_type ) ) {
return $flags ;
}
2022-06-16 14:01:47 +02:00
$should_publicize = $this -> should_submit_post_pre_checks ( $post );
2019-11-15 23:26:29 +01:00
/** This filter is already documented in modules/publicize/publicize-jetpack.php */
2022-06-16 14:01:47 +02:00
if ( ! apply_filters ( 'publicize_should_publicize_published_post' , $should_publicize , $post ) ) {
2019-11-15 23:26:29 +01:00
return $flags ;
}
$connected_services = $this -> get_all_connections ();
if ( empty ( $connected_services ) ) {
return $flags ;
}
$flags [ 'publicize_post' ] = true ;
return $flags ;
}
/**
2022-04-02 10:26:41 +02:00
* Render Facebook options .
2019-11-15 23:26:29 +01:00
*/
2022-04-02 10:26:41 +02:00
public function options_page_facebook () {
2022-06-16 14:01:47 +02:00
$connection_name = isset ( $_REQUEST [ 'connection' ] ) ? filter_var ( wp_unslash ( $_REQUEST [ 'connection' ] ) ) : '' ;
2022-04-02 10:26:41 +02:00
// Nonce check.
2022-06-16 14:01:47 +02:00
check_admin_referer ( 'options_page_facebook_' . $connection_name );
2019-11-15 23:26:29 +01:00
$connected_services = $this -> get_all_connections ();
2022-06-16 14:01:47 +02:00
$connection = $connected_services [ 'facebook' ][ $connection_name ];
2019-11-15 23:26:29 +01:00
$options_to_show = ( ! empty ( $connection [ 'connection_data' ][ 'meta' ][ 'options_responses' ] ) ? $connection [ 'connection_data' ][ 'meta' ][ 'options_responses' ] : false );
$pages = ( ! empty ( $options_to_show [ 1 ][ 'data' ] ) ? $options_to_show [ 1 ][ 'data' ] : false );
2022-04-02 10:26:41 +02:00
$page_selected = false ;
2019-11-15 23:26:29 +01:00
if ( ! empty ( $connection [ 'connection_data' ][ 'meta' ][ 'facebook_page' ] ) ) {
$found = false ;
2022-04-02 10:26:41 +02:00
if ( $pages && isset ( $pages -> data ) && is_array ( $pages -> data ) ) {
2019-11-15 23:26:29 +01:00
foreach ( $pages -> data as $page ) {
2022-04-02 10:26:41 +02:00
if ( $page -> id === ( int ) $connection [ 'connection_data' ][ 'meta' ][ 'facebook_page' ] ) {
2019-11-15 23:26:29 +01:00
$found = true ;
break ;
}
}
}
if ( $found ) {
2022-04-02 10:26:41 +02:00
$page_selected = $connection [ 'connection_data' ][ 'meta' ][ 'facebook_page' ];
2019-11-15 23:26:29 +01:00
}
}
?>
< div id = " thickbox-content " >
< ? php
ob_start ();
Publicize_UI :: connected_notice ( 'Facebook' );
$update_notice = ob_get_clean ();
if ( ! empty ( $update_notice ) ) {
2022-04-02 10:26:41 +02:00
echo wp_kses_post ( $update_notice );
2019-11-15 23:26:29 +01:00
}
$page_info_message = sprintf (
2022-04-02 10:26:41 +02:00
wp_kses (
/* translators: %s is the link to the support page about using Facebook with Publicize */
__ ( 'Facebook supports Publicize connections to Facebook Pages, but not to Facebook Profiles. <a href="%s">Learn More about Publicize for Facebook</a>' , 'jetpack' ),
array ( 'a' => array ( 'href' ) )
),
2020-05-06 17:20:49 +02:00
esc_url ( Redirect :: get_url ( 'jetpack-support-publicize-facebook' ) )
2019-11-15 23:26:29 +01:00
);
2022-04-02 10:26:41 +02:00
if ( $pages ) :
?>
< p >
< ? php
echo wp_kses (
__ ( 'Publicize to my <strong>Facebook Page</strong>:' , 'jetpack' ),
array ( 'strong' )
);
?>
</ p >
2019-11-15 23:26:29 +01:00
< table id = " option-fb-fanpage " >
< tbody >
< ? php foreach ( $pages as $i => $page ) : ?>
< ? php if ( ! ( $i % 2 ) ) : ?>
< tr >
< ? php endif ; ?>
2022-04-02 10:26:41 +02:00
< td class = " radio " >
< input
type = " radio "
name = " option "
data - type = " page "
id = " <?php echo esc_attr( $page['id'] ); ?> "
value = " <?php echo esc_attr( $page['id'] ); ?> "
< ? php checked ( $page_selected && ( int ) $page_selected === ( int ) $page [ 'id' ], true ); ?> />
2019-11-15 23:26:29 +01:00
</ td >
2022-04-02 10:26:41 +02:00
< td class = " thumbnail " >< label for = " <?php echo esc_attr( $page['id'] ); ?> " >< img
src = " <?php echo esc_url( str_replace( '_s', '_q', $page['picture'] ['data']['url'] ) ); ?> "
2019-11-15 23:26:29 +01:00
width = " 50 " height = " 50 " /></ label ></ td >
< td class = " details " >
2022-04-02 10:26:41 +02:00
< label for = " <?php echo esc_attr( $page['id'] ); ?> " >
< span class = " name " >< ? php echo esc_html ( $page [ 'name' ] ); ?> </span><br/>
< span class = " category " >< ? php echo esc_html ( $page [ 'category' ] ); ?> </span>
2019-11-15 23:26:29 +01:00
</ label >
</ td >
2022-04-02 10:26:41 +02:00
< ? php if ( ( $i % 2 ) || ( count ( $pages ) - 1 === $i ) ) : ?>
2019-11-15 23:26:29 +01:00
</ tr >
< ? php endif ; ?>
< ? php endforeach ; ?>
</ tbody >
</ table >
2022-06-16 14:01:47 +02:00
< ? php Publicize_UI :: global_checkbox ( 'facebook' , $connection_name ); ?>
2019-11-15 23:26:29 +01:00
< p style = " text-align: center; " >
2022-04-02 10:26:41 +02:00
< input type = " submit " value = " <?php esc_attr_e( 'OK', 'jetpack' ); ?> "
class = " button fb-options save-options " name = " save "
2022-06-16 14:01:47 +02:00
data - connection = " <?php echo esc_attr( $connection_name ); ?> "
rel = " <?php echo esc_attr( wp_create_nonce( 'save_fb_token_' . $connection_name ) ); ?> " />
2019-11-15 23:26:29 +01:00
</ p >< br />
2022-04-02 10:26:41 +02:00
< ? php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
2019-11-15 23:26:29 +01:00
< p >< ? php echo $page_info_message ; ?> </p>
2022-04-02 10:26:41 +02:00
< ? php else : ?>
2019-11-15 23:26:29 +01:00
< div >
2022-04-02 10:26:41 +02:00
< ? php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
2019-11-15 23:26:29 +01:00
< p >< ? php echo $page_info_message ; ?> </p>
2022-04-02 10:26:41 +02:00
< p >
< ? php
echo wp_kses (
sprintf (
/* translators: %1$s is the link to Facebook documentation to create a page, %2$s is the target of the link */
__ ( '<a class="button" href="%1$s" target="%2$s">Create a Facebook page</a> to get started.' , 'jetpack' ),
'https://www.facebook.com/pages/creation/' ,
'_blank noopener noreferrer'
),
array ( 'a' => array ( 'class' , 'href' , 'target' ) )
);
?>
</ p >
2019-11-15 23:26:29 +01:00
</ div >
< ? php endif ; ?>
</ div >
< ? php
}
2022-04-02 10:26:41 +02:00
/**
* Save Facebook options .
*/
public function options_save_facebook () {
2022-06-16 14:01:47 +02:00
$connection_name = isset ( $_REQUEST [ 'connection' ] ) ? filter_var ( wp_unslash ( $_REQUEST [ 'connection' ] ) ) : '' ;
2022-04-02 10:26:41 +02:00
// Nonce check.
2022-06-16 14:01:47 +02:00
check_admin_referer ( 'save_fb_token_' . $connection_name );
if ( ! isset ( $_POST [ 'type' ] ) || 'page' !== $_POST [ 'type' ] || ! isset ( $_POST [ 'selected_id' ] ) ) {
return ;
}
2019-11-15 23:26:29 +01:00
2022-04-02 10:26:41 +02:00
// Check for a numeric page ID.
2022-06-16 14:01:47 +02:00
$page_id = $_POST [ 'selected_id' ]; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Manually validated just below
2019-11-15 23:26:29 +01:00
if ( ! ctype_digit ( $page_id ) ) {
die ( 'Security check' );
}
2022-04-02 10:26:41 +02:00
// Publish to Page.
2019-11-15 23:26:29 +01:00
$options = array (
'facebook_page' => $page_id ,
2022-04-02 10:26:41 +02:00
'facebook_profile' => null ,
2019-11-15 23:26:29 +01:00
);
2022-06-16 14:01:47 +02:00
$this -> set_remote_publicize_options ( $connection_name , $options );
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
/**
* Render Tumblr options .
*/
public function options_page_tumblr () {
2022-06-16 14:01:47 +02:00
$connection_name = isset ( $_REQUEST [ 'connection' ] ) ? filter_var ( wp_unslash ( $_REQUEST [ 'connection' ] ) ) : '' ;
2022-04-02 10:26:41 +02:00
// Nonce check.
2022-06-16 14:01:47 +02:00
check_admin_referer ( 'options_page_tumblr_' . $connection_name );
2019-11-15 23:26:29 +01:00
$connected_services = $this -> get_all_connections ();
2022-06-16 14:01:47 +02:00
$connection = $connected_services [ 'tumblr' ][ $connection_name ];
2019-11-15 23:26:29 +01:00
$options_to_show = $connection [ 'connection_data' ][ 'meta' ][ 'options_responses' ];
$request = $options_to_show [ 0 ];
$blogs = $request [ 'response' ][ 'user' ][ 'blogs' ];
$blog_selected = false ;
if ( ! empty ( $connection [ 'connection_data' ][ 'meta' ][ 'tumblr_base_hostname' ] ) ) {
foreach ( $blogs as $blog ) {
2022-04-02 10:26:41 +02:00
if ( $connection [ 'connection_data' ][ 'meta' ][ 'tumblr_base_hostname' ] === $this -> get_basehostname ( $blog [ 'url' ] ) ) {
2019-11-15 23:26:29 +01:00
$blog_selected = $connection [ 'connection_data' ][ 'meta' ][ 'tumblr_base_hostname' ];
break ;
}
}
}
2022-04-02 10:26:41 +02:00
// Use their Primary blog if they haven't selected one yet.
2019-11-15 23:26:29 +01:00
if ( ! $blog_selected ) {
foreach ( $blogs as $blog ) {
if ( $blog [ 'primary' ] ) {
$blog_selected = $this -> get_basehostname ( $blog [ 'url' ] );
}
}
2022-04-02 10:26:41 +02:00
}
?>
2019-11-15 23:26:29 +01:00
< div id = " thickbox-content " >
< ? php
ob_start ();
Publicize_UI :: connected_notice ( 'Tumblr' );
$update_notice = ob_get_clean ();
if ( ! empty ( $update_notice ) ) {
2022-04-02 10:26:41 +02:00
echo wp_kses_post ( $update_notice );
2019-11-15 23:26:29 +01:00
}
?>
2022-04-02 10:26:41 +02:00
< p >< ? php echo wp_kses ( __ ( 'Publicize to my <strong>Tumblr blog</strong>:' , 'jetpack' ), array ( 'strong' ) ); ?> </p>
2019-11-15 23:26:29 +01:00
< ul id = " option-tumblr-blog " >
< ? php
foreach ( $blogs as $blog ) {
2022-04-02 10:26:41 +02:00
$url = $this -> get_basehostname ( $blog [ 'url' ] );
?>
2019-11-15 23:26:29 +01:00
< li >
2022-04-02 10:26:41 +02:00
< input type = " radio " name = " option " data - type = " blog " id = " <?php echo esc_attr( $url ); ?> "
value = " <?php echo esc_attr( $url ); ?> " < ? php checked ( $blog_selected === $url , true ); ?> />
< label for = " <?php echo esc_attr( $url ); ?> " >< span
class = " name " >< ? php echo esc_html ( $blog [ 'title' ] ); ?> </span></label>
2019-11-15 23:26:29 +01:00
</ li >
< ? php } ?>
</ ul >
2022-06-16 14:01:47 +02:00
< ? php Publicize_UI :: global_checkbox ( 'tumblr' , $connection_name ); ?>
2019-11-15 23:26:29 +01:00
< p style = " text-align: center; " >
2022-04-02 10:26:41 +02:00
< input type = " submit " value = " <?php esc_attr_e( 'OK', 'jetpack' ); ?> "
class = " button tumblr-options save-options " name = " save "
2022-06-16 14:01:47 +02:00
data - connection = " <?php echo esc_attr( $connection_name ); ?> "
rel = " <?php echo esc_attr( wp_create_nonce( 'save_tumblr_blog_' . $connection_name ) ); ?> " />
2019-11-15 23:26:29 +01:00
</ p > < br />
</ div >
< ? php
}
2022-04-02 10:26:41 +02:00
/**
* Get the hostname from a URL .
*
* @ param string $url The URL to extract the hostname from .
* @ return string | false | null
*/
public function get_basehostname ( $url ) {
2019-11-15 23:26:29 +01:00
return wp_parse_url ( $url , PHP_URL_HOST );
}
2022-04-02 10:26:41 +02:00
/**
* Save Tumblr options .
*/
public function options_save_tumblr () {
2022-06-16 14:01:47 +02:00
$connection_name = isset ( $_REQUEST [ 'connection' ] ) ? filter_var ( wp_unslash ( $_REQUEST [ 'connection' ] ) ) : '' ;
2022-04-02 10:26:41 +02:00
// Nonce check.
2022-06-16 14:01:47 +02:00
check_admin_referer ( 'save_tumblr_blog_' . $connection_name );
$options = array ( 'tumblr_base_hostname' => isset ( $_POST [ 'selected_id' ] ) ? sanitize_text_field ( wp_unslash ( $_POST [ 'selected_id' ] ) ) : null );
2019-11-15 23:26:29 +01:00
2022-06-16 14:01:47 +02:00
$this -> set_remote_publicize_options ( $connection_name , $options );
2019-11-15 23:26:29 +01:00
}
2022-04-02 10:26:41 +02:00
/**
* Set remote Publicize options .
*
* @ param int $id Connection ID .
* @ param array $options Options to set .
*/
public function set_remote_publicize_options ( $id , $options ) {
2019-11-15 23:26:29 +01:00
$xml = new Jetpack_IXR_Client ();
$xml -> query ( 'jetpack.setPublicizeOptions' , $id , $options );
if ( ! $xml -> isError () ) {
$response = $xml -> getResponse ();
Jetpack_Options :: update_option ( 'publicize_connections' , $response );
2022-04-02 10:26:41 +02:00
$this -> globalization ( $id );
2019-11-15 23:26:29 +01:00
}
}
2022-04-02 10:26:41 +02:00
/**
* Render the options page for Twitter .
*/
public function options_page_twitter () {
2019-11-15 23:26:29 +01:00
Publicize_UI :: options_page_other ( 'twitter' );
}
2022-04-02 10:26:41 +02:00
/**
* Render the options page for LinkedIn .
*/
public function options_page_linkedin () {
2019-11-15 23:26:29 +01:00
Publicize_UI :: options_page_other ( 'linkedin' );
}
2022-04-02 10:26:41 +02:00
/**
* Save the options page for Twitter .
*/
public function options_save_twitter () {
2019-11-15 23:26:29 +01:00
$this -> options_save_other ( 'twitter' );
}
2022-04-02 10:26:41 +02:00
/**
* Save the options page for LinkedIn .
*/
public function options_save_linkedin () {
2019-11-15 23:26:29 +01:00
$this -> options_save_other ( 'linkedin' );
}
2022-04-02 10:26:41 +02:00
/**
* Save the options page for a service .
*
* @ param string $service_name Name of the service to save options for .
*/
public function options_save_other ( $service_name ) {
2022-06-16 14:01:47 +02:00
$connection_name = isset ( $_REQUEST [ 'connection' ] ) ? filter_var ( wp_unslash ( $_REQUEST [ 'connection' ] ) ) : '' ;
2022-04-02 10:26:41 +02:00
// Nonce check.
2022-06-16 14:01:47 +02:00
check_admin_referer ( 'save_' . $service_name . '_token_' . $connection_name );
2022-04-02 10:26:41 +02:00
2022-06-16 14:01:47 +02:00
$this -> globalization ( $connection_name );
2019-11-15 23:26:29 +01:00
}
/**
* If there ' s only one shared connection to Twitter set it as twitter : site tag .
2022-04-02 10:26:41 +02:00
*
* @ param string $tag Tag .
2019-11-15 23:26:29 +01:00
*/
2022-04-02 10:26:41 +02:00
public function enhaced_twitter_cards_site_tag ( $tag ) {
2019-11-15 23:26:29 +01:00
$custom_site_tag = get_option ( 'jetpack-twitter-cards-site-tag' );
if ( ! empty ( $custom_site_tag ) ) {
return $tag ;
}
if ( ! $this -> is_enabled ( 'twitter' ) ) {
return $tag ;
}
$connections = $this -> get_connections ( 'twitter' );
foreach ( $connections as $connection ) {
$connection_meta = $this -> get_connection_meta ( $connection );
2022-04-02 10:26:41 +02:00
if ( $this -> is_global_connection ( $connection_meta ) ) {
// If the connection is shared.
2019-11-15 23:26:29 +01:00
return $this -> get_display_name ( 'twitter' , $connection );
}
}
return $tag ;
}
2022-04-02 10:26:41 +02:00
/**
* Save the Publicized Twitter account when publishing a post .
*
* @ param bool $submit_post Should the post be publicized .
* @ param int $post_id Post ID .
* @ param string $service_name Service name .
* @ param array $connection Array of connection details .
*/
public function save_publicized_twitter_account ( $submit_post , $post_id , $service_name , $connection ) {
if ( 'twitter' === $service_name && $submit_post ) {
2019-11-15 23:26:29 +01:00
$connection_meta = $this -> get_connection_meta ( $connection );
$publicize_twitter_user = get_post_meta ( $post_id , '_publicize_twitter_user' );
2022-04-02 10:26:41 +02:00
if ( empty ( $publicize_twitter_user ) || ! $this -> is_global_connection ( $connection_meta ) ) {
2019-11-15 23:26:29 +01:00
update_post_meta ( $post_id , '_publicize_twitter_user' , $this -> get_display_name ( 'twitter' , $connection ) );
}
}
}
2022-04-02 10:26:41 +02:00
/**
* Get the Twitter username .
*
* @ param string $account Twitter username .
* @ param int $post_id ID of the post .
* @ return string
*/
public function get_publicized_twitter_account ( $account , $post_id ) {
2019-11-15 23:26:29 +01:00
if ( ! empty ( $account ) ) {
return $account ;
}
$account = get_post_meta ( $post_id , '_publicize_twitter_user' , true );
if ( ! empty ( $account ) ) {
return $account ;
}
return '' ;
}
/**
* Save the Publicized Facebook account when publishing a post
* Use only Personal accounts , not Facebook Pages
2022-04-02 10:26:41 +02:00
*
* @ param bool $submit_post Should the post be publicized .
* @ param int $post_id Post ID .
* @ param string $service_name Service name .
* @ param array $connection Array of connection details .
2019-11-15 23:26:29 +01:00
*/
2022-04-02 10:26:41 +02:00
public function save_publicized_facebook_account ( $submit_post , $post_id , $service_name , $connection ) {
2019-11-15 23:26:29 +01:00
$connection_meta = $this -> get_connection_meta ( $connection );
2022-04-02 10:26:41 +02:00
if ( 'facebook' === $service_name && isset ( $connection_meta [ 'connection_data' ][ 'meta' ][ 'facebook_profile' ] ) && $submit_post ) {
2019-11-15 23:26:29 +01:00
$publicize_facebook_user = get_post_meta ( $post_id , '_publicize_facebook_user' );
2022-04-02 10:26:41 +02:00
if ( empty ( $publicize_facebook_user ) || ! $this -> is_global_connection ( $connection_meta ) ) {
2019-11-15 23:26:29 +01:00
$profile_link = $this -> get_profile_link ( 'facebook' , $connection );
if ( false !== $profile_link ) {
update_post_meta ( $post_id , '_publicize_facebook_user' , $profile_link );
}
}
}
}
}