initial
This commit is contained in:
commit
9883323161
17470 files changed
+4470592
No files matched your search
+1
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array('react-dom', 'react-jsx-runtime', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-polyfill'), 'version' => '2a33dbc0026f7152568f');
|
||||
+1
@@ -0,0 +1 @@
|
||||
.jetpack-external-connection-settings{align-items:center;display:flex;gap:4px;min-height:30px}.jetpack-external-connection-settings img{width:20px}
|
||||
+1
@@ -0,0 +1 @@
|
||||
(()=>{"use strict";var e={137(e,t,n){n.d(t,{A:()=>s});var r,o=n(467);function i(){this.intervals={},this.monitorInterval=null,this.windowInstance=null,this.onMessage=e=>{e.source===this.windowInstance&&this.emit("message",e.data)}}r=i.prototype,Object.assign(r,o.EventEmitter.prototype),r.emitChange=function(){this.emit("change")},r.off=r.removeListener,i.prototype.open=function(e,t,n){return t=t||Date.now(),this.windowInstance=window.open(e,t,n),this.startMonitoring(t,this.windowInstance),window.addEventListener("message",this.onMessage,!1),this},i.prototype.getScreenCenterSpecs=function(e,t){const n=void 0!==window.screenTop?window.screenTop:window.screenY,r=void 0!==window.screenLeft?window.screenLeft:window.screenX;return["width="+e,"height="+t,"top="+(n+window.innerHeight/2-t/2),"left="+(r+window.innerWidth/2-e/2)].join()},i.prototype.isOpen=function(e){let t=!1;try{t=this.intervals[e]&&this.intervals[e].closed}catch(e){}return!t},i.prototype.checkStatus=function(){for(const e in this.intervals)this.intervals.hasOwnProperty(e)&&!this.isOpen(e)&&(this.emit("close",e),delete this.intervals[e]);0===Object.keys(this.intervals).length&&(clearInterval(this.monitorInterval),delete this.monitorInterval,window.removeEventListener("message",this.onMessage))},i.prototype.startMonitoring=function(e,t){this.monitorInterval||(this.monitorInterval=setInterval(this.checkStatus.bind(this),100)),this.intervals[e]=t};const s=i},754(e,t,n){n.d(t,{A:()=>o});var r=n(137);const o=(e,t)=>{const n=new r.A;let o;n.open(e,null,"toolbar=0,location=0,status=0,menubar=0,"+n.getScreenCenterSpecs(780,700)),n.once("close",()=>{const e={};o&&o.keyring_id&&(e.keyring_id=Number(o.keyring_id),e.id_token=o.id_token,e.user=o.user),t(e)}),n.on("message",e=>o=e)}},467(e){var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise(function(n,r){function o(n){e.removeListener(t,i),r(n)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",o),n([].slice.call(arguments))}d(e,t,i,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&d(e,"error",t,n)}(e,o,{once:!0})})},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var s=10;function c(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function a(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function u(e,t,n,r){var o,i,s,u;if(c(n),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),s=i[t]),void 0===s)s=i[t]=n,++e._eventsCount;else if("function"==typeof s?s=i[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(o=a(e))>0&&s.length>o&&!s.warned){s.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=s.length,u=l,console&&console.warn&&console.warn(u)}return e}function l(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=l.bind(r);return o.listener=n,r.wrapFn=o,o}function f(e,t,n){var r=e._events;if(void 0===r)return[];var o=r[t];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(o):v(o,o.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function v(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function d(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function o(i){r.once&&e.removeEventListener(t,o),n(i)})}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");s=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._Line truncated
|
||||
+1
@@ -0,0 +1 @@
|
||||
.jetpack-external-connection-settings{align-items:center;display:flex;gap:4px;min-height:30px}.jetpack-external-connection-settings img{width:20px}
|
||||
+346
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
/**
|
||||
* Management of external connections.
|
||||
*
|
||||
* @package automattic/jetpack-external-connections
|
||||
*/
|
||||
|
||||
namespace Automattic\Jetpack;
|
||||
|
||||
use Automattic\Jetpack\Connection\Client;
|
||||
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
|
||||
use Automattic\Jetpack\Status\Host;
|
||||
|
||||
/**
|
||||
* Main class.
|
||||
*/
|
||||
class External_Connections {
|
||||
|
||||
const PACKAGE_VERSION = '0.1.34';
|
||||
const BASE_FILE = __FILE__;
|
||||
|
||||
/**
|
||||
* List of services whose connections are managed in settings pages.
|
||||
*
|
||||
* Each item has a key with the slug of the settings page, and a value with an array of services.
|
||||
*
|
||||
* Each service has the following keys:
|
||||
* - service: The service identifier.
|
||||
* - title: The title of the service.
|
||||
* - signup_link: The URL to the service's signup page.
|
||||
* - description: The description of the service.
|
||||
* - support_link: An array with the following keys:
|
||||
* - jetpack: The URL handler registered in jetpack.com/redirect/.
|
||||
* - wpcom: The URL of the support page for the service on WordPress.com.
|
||||
* - script: An optional script handle to enqueue.
|
||||
*
|
||||
* @example
|
||||
* ```php
|
||||
* self::$services = array(
|
||||
* 'media' => array(
|
||||
* array(
|
||||
* 'service' => 'facebook',
|
||||
* 'title' => 'Facebook',
|
||||
* 'signup_link' => 'https://facebook.com/signup?ref=jetpack',
|
||||
* 'description' => 'Connect your site to your Facebook account',
|
||||
* 'support_link' => array(
|
||||
* 'jetpack' => 'facebook-connection',
|
||||
* 'wpcom' => 'https://wordpress.com/support/facebook/',
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* );
|
||||
* ```
|
||||
* @var array
|
||||
*/
|
||||
private static $services = array();
|
||||
|
||||
/**
|
||||
* Gets the connect URL for a given service.
|
||||
*
|
||||
* @param string $service The service identifier.
|
||||
* @return string|null The connect URL, or `null` if the service is not supported.
|
||||
*/
|
||||
public static function get_connect_url( $service ) {
|
||||
if ( ( new Host() )->is_wpcom_simple() ) {
|
||||
require_lib( 'external-connections' );
|
||||
$connections = \WPCOM_External_Connections::init();
|
||||
$service = $connections->get_external_service_item( $service );
|
||||
return $service ? $service['connect_URL'] : null;
|
||||
}
|
||||
|
||||
$site_id = Connection_Manager::get_site_id();
|
||||
if ( is_wp_error( $site_id ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = sprintf( '/sites/%d/external-services', $site_id );
|
||||
$response = Client::wpcom_json_api_request_as_user( $path );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$body = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
|
||||
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
return $body->services->$service->connect_URL ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a connection of the provided service.
|
||||
*
|
||||
* @param string $service The service identifier.
|
||||
* @return array|null The connection details, or `null` if no matching connection is found.
|
||||
*/
|
||||
public static function get_connection( $service ) {
|
||||
if ( ( new Host() )->is_wpcom_simple() ) {
|
||||
require_lib( 'external-media-service/external-media-list' );
|
||||
require_lib( 'external-connections' );
|
||||
|
||||
$connections = \WPCOM_External_Connections::init();
|
||||
$token = \ExternalMediaService::get_service_token( $service, get_current_user_id() );
|
||||
|
||||
if ( ! empty( $token->unique_id ) ) {
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgument -- $token->unique_id is an int.
|
||||
return $connections->get_keyring_connection_item( $token->unique_id );
|
||||
}
|
||||
} else {
|
||||
$response = Client::wpcom_json_api_request_as_user( '/me/connections' );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return null;
|
||||
}
|
||||
$body = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
if ( isset( $body->connections ) && is_array( $body->connections ) ) {
|
||||
foreach ( $body->connections as $connection ) {
|
||||
if ( $service === $connection->service ) {
|
||||
return (array) $connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a connection for the provided service.
|
||||
*
|
||||
* @param string $service The service identifier.
|
||||
* @return boolean Whether the connection was deleted.
|
||||
*/
|
||||
public static function delete_connection( $service ) {
|
||||
$connection = self::get_connection( $service );
|
||||
if ( empty( $connection ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( new Host() )->is_wpcom_simple() ) {
|
||||
if ( get_current_user_id() === $connection['user_ID'] ) {
|
||||
require_lib( 'external-connections' );
|
||||
$connections = \WPCOM_External_Connections::init();
|
||||
return $connections->delete_keyring_connection( $connection['ID'] );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = Client::wpcom_json_api_request_as_user(
|
||||
'/me/connections/' . $connection['ID'],
|
||||
'2',
|
||||
array( 'method' => 'DELETE' )
|
||||
);
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return false;
|
||||
}
|
||||
$body = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
return $body->deleted ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the connection data for the provided service.
|
||||
*
|
||||
* @param string $service The service identifier.
|
||||
* @return array The connection data.
|
||||
*/
|
||||
public static function get_connection_data( $service ) {
|
||||
$connection = self::get_connection( $service );
|
||||
if ( empty( $connection ) ) {
|
||||
return array(
|
||||
'is_connected' => false,
|
||||
'account_name' => '',
|
||||
'profile_image' => '',
|
||||
);
|
||||
}
|
||||
|
||||
$is_connected = isset( $connection['status'] ) && $connection['status'] === 'ok';
|
||||
$account_name = $is_connected ? ( $connection['external_display'] ?? $connection['external_name'] ) : '';
|
||||
$profile_image = $is_connected ? $connection['external_profile_picture'] : '';
|
||||
|
||||
return array(
|
||||
'is_connected' => $is_connected,
|
||||
'account_name' => $account_name,
|
||||
'profile_image' => $profile_image,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers connection settings.
|
||||
*/
|
||||
public static function register_settings() {
|
||||
global $pagenow;
|
||||
$host = new Host();
|
||||
|
||||
if ( ! $host->is_wpcom_simple() ) {
|
||||
$connection = new Connection_Manager( 'jetpack' );
|
||||
$status = new Status();
|
||||
|
||||
if ( $status->is_offline_mode() || ! $connection->has_connected_owner() || ! $connection->is_user_connected() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( self::$services as $page => $services ) {
|
||||
if ( $pagenow !== "options-$page.php" ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
add_settings_section(
|
||||
'jetpack_external_connections_section',
|
||||
__( 'Integrations', 'jetpack-external-connections' ),
|
||||
'__return_false',
|
||||
$page
|
||||
);
|
||||
|
||||
$asset_name = 'jetpack-external-connections-settings';
|
||||
Assets::register_script(
|
||||
$asset_name,
|
||||
"build/$asset_name/$asset_name.js",
|
||||
self::BASE_FILE,
|
||||
array(
|
||||
'in_footer' => true,
|
||||
'textdomain' => 'jetpack-external-connections',
|
||||
)
|
||||
);
|
||||
Assets::enqueue_script( $asset_name );
|
||||
|
||||
$script_data = array();
|
||||
|
||||
foreach ( $services as $service ) {
|
||||
if ( $host->is_wpcom_platform() ) {
|
||||
$support_link = $service['support_link']['wpcom'];
|
||||
if ( function_exists( 'localized_wpcom_url' ) ) {
|
||||
$support_link = localized_wpcom_url( $support_link );
|
||||
}
|
||||
} else {
|
||||
$support_link = Redirect::get_url( $service['support_link']['jetpack'] );
|
||||
}
|
||||
|
||||
$connect_url = self::get_connect_url( $service['service'] );
|
||||
$connection_data = self::get_connection_data( $service['service'] );
|
||||
|
||||
if ( ( empty( $connect_url ) && ! $connection_data['is_connected'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
add_settings_field(
|
||||
'jetpack_external_connections_field_' . $service['service'],
|
||||
$service['title'],
|
||||
function () use ( $service, $support_link ) {
|
||||
?>
|
||||
<div class="jetpack-external-connection" data-service="<?php echo esc_attr( $service['service'] ); ?>"><em><?php esc_html_e( 'Loading…', 'jetpack-external-connections' ); ?></em></div>
|
||||
<p class="description">
|
||||
<?php echo esc_html( $service['description'] ); ?>
|
||||
<a href="<?php echo esc_url( $support_link ); ?>" target="_blank" data-target="wpcom-help-center"><?php esc_html_e( 'Learn more', 'jetpack-external-connections' ); ?></a>
|
||||
</p>
|
||||
<?php
|
||||
},
|
||||
$page,
|
||||
'jetpack_external_connections_section'
|
||||
);
|
||||
|
||||
$script_data[ $service['service'] ] = array(
|
||||
'accountName' => $connection_data['account_name'],
|
||||
'connectUrl' => $connect_url,
|
||||
'deleteNonce' => wp_create_nonce( 'jetpack_delete_external_connection_' . $service['service'] ),
|
||||
'getNonce' => wp_create_nonce( 'jetpack_get_external_connection_' . $service['service'] ),
|
||||
'isConnected' => $connection_data['is_connected'],
|
||||
'profileImage' => $connection_data['profile_image'],
|
||||
'supportLink' => $support_link,
|
||||
'signupLink' => $service['signup_link'] ?? '',
|
||||
);
|
||||
|
||||
if ( isset( $service['script'] ) ) {
|
||||
Assets::enqueue_script( $service['script'] );
|
||||
}
|
||||
}
|
||||
|
||||
wp_add_inline_script(
|
||||
$asset_name,
|
||||
'const jetpackExternalConnectionsData = ' . wp_json_encode( $script_data, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';',
|
||||
'before'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the AJAX request to delete an external connection.
|
||||
*/
|
||||
public static function ajax_delete_connection() {
|
||||
if ( ! isset( $_REQUEST['service'] ) ) {
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.
|
||||
wp_send_json( array( 'deleted' => 'false' ), null, JSON_UNESCAPED_SLASHES );
|
||||
}
|
||||
|
||||
$service = sanitize_text_field( wp_unslash( $_REQUEST['service'] ) );
|
||||
check_ajax_referer( 'jetpack_delete_external_connection_' . $service );
|
||||
|
||||
$is_deleted = self::delete_connection( $service );
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.
|
||||
wp_send_json( array( 'deleted' => $is_deleted ), null, JSON_UNESCAPED_SLASHES );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the AJAX request to delete an external connection.
|
||||
*/
|
||||
public static function ajax_get_connection() {
|
||||
if ( ! isset( $_REQUEST['service'] ) ) {
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.
|
||||
wp_send_json( array( 'isConnected' => 'false' ), null, JSON_UNESCAPED_SLASHES );
|
||||
}
|
||||
|
||||
$service = sanitize_text_field( wp_unslash( $_REQUEST['service'] ) );
|
||||
check_ajax_referer( 'jetpack_get_external_connection_' . $service );
|
||||
|
||||
$connection_data = self::get_connection_data( $service );
|
||||
wp_send_json(
|
||||
array(
|
||||
'accountName' => $connection_data['account_name'],
|
||||
'isConnected' => $connection_data['is_connected'],
|
||||
'profileImage' => $connection_data['profile_image'],
|
||||
),
|
||||
null, // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.
|
||||
JSON_UNESCAPED_SLASHES
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers settings and hooks for a specified service on a given admin page.
|
||||
*
|
||||
* @param string $page The identifier of the admin page where the service settings are added.
|
||||
* @param array $service The service to be associated with the specified admin page.
|
||||
*/
|
||||
public static function add_settings_for_service( $page, $service ) {
|
||||
self::$services[ $page ][] = $service;
|
||||
|
||||
if ( ! has_action( 'admin_init', array( __CLASS__, 'register_settings' ) ) ) {
|
||||
add_action( 'admin_init', array( __CLASS__, 'register_settings' ), 15 );
|
||||
}
|
||||
|
||||
if ( ! has_action( 'wp_ajax_jetpack_delete_external_connection', array( __CLASS__, 'ajax_delete_connection' ) ) ) {
|
||||
add_action( 'wp_ajax_jetpack_delete_external_connection', array( __CLASS__, 'ajax_delete_connection' ) );
|
||||
}
|
||||
|
||||
if ( ! has_action( 'wp_ajax_jetpack_get_external_connection', array( __CLASS__, 'ajax_get_connection' ) ) ) {
|
||||
add_action( 'wp_ajax_jetpack_get_external_connection', array( __CLASS__, 'ajax_get_connection' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
/* global jetpackExternalConnectionsData */
|
||||
|
||||
import requestExternalAccess from '@automattic/request-external-access';
|
||||
import domReady from '@wordpress/dom-ready';
|
||||
import { useState } from '@wordpress/element';
|
||||
import { applyFilters } from '@wordpress/hooks';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
|
||||
const fetchData = async params => {
|
||||
const response = await fetch( '/wp-admin/admin-ajax.php', {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams( params ),
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
} );
|
||||
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents an external connection component for a given service,
|
||||
* allowing users to connect or disconnect from it.
|
||||
*
|
||||
* @param {object} props - The properties for the ExternalConnection component.
|
||||
* @param {string} props.service - The name of the service to be connected or disconnected.
|
||||
* @return {import('react').Component} The ExternalConnection component.
|
||||
*/
|
||||
function ExternalConnection( { service } ) {
|
||||
const config = jetpackExternalConnectionsData[ service ];
|
||||
const [ isConnected, setIsConnected ] = useState( config.isConnected );
|
||||
const [ accountName, setAccountName ] = useState( config.accountName );
|
||||
const [ profileImage, setProfileImage ] = useState( config.profileImage );
|
||||
const [ isTogglingConnection, setTogglingConnection ] = useState( false );
|
||||
|
||||
const toggleConnection = async () => {
|
||||
setTogglingConnection( true );
|
||||
|
||||
if ( isConnected ) {
|
||||
const data = await fetchData( {
|
||||
action: 'jetpack_delete_external_connection',
|
||||
service,
|
||||
_ajax_nonce: config.deleteNonce,
|
||||
} );
|
||||
setTogglingConnection( false );
|
||||
if ( data.deleted ) {
|
||||
setIsConnected( false );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
requestExternalAccess( config.connectUrl, async ( { keyring_id: keyringId } ) => {
|
||||
if ( ! keyringId ) {
|
||||
setTogglingConnection( false );
|
||||
}
|
||||
|
||||
const data = await fetchData( {
|
||||
action: 'jetpack_get_external_connection',
|
||||
service,
|
||||
_ajax_nonce: config.getNonce,
|
||||
} );
|
||||
setIsConnected( data.isConnected );
|
||||
setAccountName( data.accountName );
|
||||
setProfileImage( data.profileImage );
|
||||
setTogglingConnection( false );
|
||||
} );
|
||||
};
|
||||
|
||||
let buttonText;
|
||||
if ( isTogglingConnection ) {
|
||||
buttonText = isConnected
|
||||
? __( 'Disconnecting…', 'jetpack-external-connections' )
|
||||
: __(
|
||||
'Connecting…',
|
||||
'jetpack-external-connections',
|
||||
/* dummy arg to avoid bad minification */ 0
|
||||
);
|
||||
} else {
|
||||
buttonText = isConnected
|
||||
? __( 'Disconnect', 'jetpack-external-connections' )
|
||||
: __(
|
||||
'Connect',
|
||||
'jetpack-external-connections',
|
||||
/* dummy arg to avoid bad minification */ 0
|
||||
);
|
||||
}
|
||||
|
||||
const ExtraSettings = applyFilters( 'jetpack.externalConnections.extraSettings', null, service );
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="jetpack-external-connection-settings">
|
||||
{ isConnected && accountName && (
|
||||
<>
|
||||
{ __( 'Connected as:', 'jetpack-external-connections' ) }
|
||||
{ profileImage && <img src={ profileImage } alt="" /> }
|
||||
<strong>{ accountName } </strong>
|
||||
</>
|
||||
) }
|
||||
{ ! isConnected && config.signupLink && (
|
||||
<a
|
||||
className={ `button-secondary ${ isTogglingConnection ? 'disabled' : '' }` }
|
||||
href={ config.signupLink }
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{ __( 'Sign up', 'jetpack-external-connections' ) }
|
||||
</a>
|
||||
) }
|
||||
<button
|
||||
className="button-secondary"
|
||||
type="button"
|
||||
onClick={ toggleConnection }
|
||||
disabled={ isTogglingConnection }
|
||||
>
|
||||
{ buttonText }
|
||||
</button>
|
||||
</div>
|
||||
{ ExtraSettings && <ExtraSettings isConnected={ isConnected } /> }
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
domReady( () => {
|
||||
const connections = document.querySelectorAll( '.jetpack-external-connection' );
|
||||
if ( ! connections.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
connections.forEach( connection => {
|
||||
const root = createRoot( connection );
|
||||
const service = connection.dataset.service;
|
||||
root.render( <ExternalConnection service={ service } /> );
|
||||
} );
|
||||
} );
|
||||
Reference in new issue
Block a user