Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack
File: class.jetpack-network.php
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFilename
[0] Fix | Delete
/**
[1] Fix | Delete
* Jetpack Network Manager class file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
use Automattic\Jetpack\Assets\Logo;
[7] Fix | Delete
use Automattic\Jetpack\Connection\Manager;
[8] Fix | Delete
use Automattic\Jetpack\Connection\Tokens;
[9] Fix | Delete
use Automattic\Jetpack\Status;
[10] Fix | Delete
use Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection_Shared_Functions;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Used to manage Jetpack installation on Multisite Network installs
[14] Fix | Delete
*
[15] Fix | Delete
* SINGLETON: To use call Jetpack_Network::init()
[16] Fix | Delete
*
[17] Fix | Delete
* DO NOT USE ANY STATIC METHODS IN THIS CLASS!!!!!!
[18] Fix | Delete
*
[19] Fix | Delete
* @since 2.9
[20] Fix | Delete
*/
[21] Fix | Delete
class Jetpack_Network {
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Holds a static copy of Jetpack_Network for the singleton
[25] Fix | Delete
*
[26] Fix | Delete
* @since 2.9
[27] Fix | Delete
* @var Jetpack_Network
[28] Fix | Delete
*/
[29] Fix | Delete
private static $instance = null;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* An instance of the connection manager object.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 7.7
[35] Fix | Delete
* @var Automattic\Jetpack\Connection\Manager
[36] Fix | Delete
*/
[37] Fix | Delete
private $connection;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Name of the network wide settings
[41] Fix | Delete
*
[42] Fix | Delete
* @since 2.9
[43] Fix | Delete
* @var string
[44] Fix | Delete
*/
[45] Fix | Delete
private $settings_name = 'jetpack-network-settings';
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Defaults for settings found on the Jetpack > Settings page
[49] Fix | Delete
*
[50] Fix | Delete
* @since 2.9
[51] Fix | Delete
* @var array
[52] Fix | Delete
*/
[53] Fix | Delete
private $setting_defaults = array(
[54] Fix | Delete
'auto-connect' => 0,
[55] Fix | Delete
'sub-site-connection-override' => 1,
[56] Fix | Delete
);
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Constructor
[60] Fix | Delete
*
[61] Fix | Delete
* @since 2.9
[62] Fix | Delete
*/
[63] Fix | Delete
private function __construct() {
[64] Fix | Delete
require_once ABSPATH . '/wp-admin/includes/plugin.php'; // For the is_plugin... check.
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Sanity check to ensure the install is Multisite and we
[68] Fix | Delete
* are in Network Admin
[69] Fix | Delete
*/
[70] Fix | Delete
if ( is_multisite() && is_network_admin() ) {
[71] Fix | Delete
add_action( 'network_admin_menu', array( $this, 'add_network_admin_menu' ) );
[72] Fix | Delete
add_action( 'network_admin_edit_jetpack-network-settings', array( $this, 'save_network_settings_page' ), 10, 0 );
[73] Fix | Delete
add_filter( 'admin_body_class', array( $this, 'body_class' ) );
[74] Fix | Delete
[75] Fix | Delete
if ( isset( $_GET['page'] ) && 'jetpack' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
[76] Fix | Delete
add_action( 'admin_init', array( $this, 'jetpack_sites_list' ) );
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/*
[81] Fix | Delete
* Things that should only run on multisite
[82] Fix | Delete
*/
[83] Fix | Delete
if ( is_multisite() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) {
[84] Fix | Delete
add_action( 'wp_before_admin_bar_render', array( $this, 'add_to_menubar' ) );
[85] Fix | Delete
add_filter( 'jetpack_disconnect_cap', array( $this, 'set_multisite_disconnect_cap' ) );
[86] Fix | Delete
[87] Fix | Delete
/*
[88] Fix | Delete
* If admin wants to automagically register new sites set the hook here
[89] Fix | Delete
*
[90] Fix | Delete
* This is a hacky way because xmlrpc is not available on wp_initialize_site
[91] Fix | Delete
*/
[92] Fix | Delete
if ( 1 === $this->get_option( 'auto-connect' ) ) {
[93] Fix | Delete
add_action( 'wp_initialize_site', array( $this, 'do_automatically_add_new_site' ) );
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Sets a connection object.
[100] Fix | Delete
*
[101] Fix | Delete
* @param Automattic\Jetpack\Connection\Manager $connection the connection manager object.
[102] Fix | Delete
*/
[103] Fix | Delete
public function set_connection( Manager $connection ) {
[104] Fix | Delete
$this->connection = $connection;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Registers new sites upon creation
[109] Fix | Delete
*
[110] Fix | Delete
* @since 2.9
[111] Fix | Delete
* @since 7.4.0 Uses a WP_Site object.
[112] Fix | Delete
* @uses wp_initialize_site
[113] Fix | Delete
*
[114] Fix | Delete
* @param WP_Site $site the WordPress site object.
[115] Fix | Delete
**/
[116] Fix | Delete
public function do_automatically_add_new_site( $site ) {
[117] Fix | Delete
if ( is_a( $site, 'WP_Site' ) ) {
[118] Fix | Delete
$this->do_subsiteregister( $site->id );
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Adds .network-admin class to the body tag
[124] Fix | Delete
* Helps distinguish network admin JP styles from regular site JP styles
[125] Fix | Delete
*
[126] Fix | Delete
* @since 2.9
[127] Fix | Delete
*
[128] Fix | Delete
* @param String $classes current assigned body classes.
[129] Fix | Delete
* @return String amended class string.
[130] Fix | Delete
*/
[131] Fix | Delete
public function body_class( $classes ) {
[132] Fix | Delete
return trim( $classes ) . ' network-admin ';
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Provides access to an instance of Jetpack_Network
[137] Fix | Delete
*
[138] Fix | Delete
* This is how the Jetpack_Network object should *always* be accessed
[139] Fix | Delete
*
[140] Fix | Delete
* @since 2.9
[141] Fix | Delete
* @return Jetpack_Network
[142] Fix | Delete
*/
[143] Fix | Delete
public static function init() {
[144] Fix | Delete
if ( ! self::$instance || ! is_a( self::$instance, 'Jetpack_Network' ) ) {
[145] Fix | Delete
self::$instance = new Jetpack_Network();
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
return self::$instance;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Registers the Multisite admin bar menu item shortcut.
[153] Fix | Delete
* This shortcut helps users quickly and easily navigate to the Jetpack Network Admin
[154] Fix | Delete
* menu from anywhere in their network.
[155] Fix | Delete
*
[156] Fix | Delete
* @since 2.9
[157] Fix | Delete
*/
[158] Fix | Delete
public function register_menubar() {
[159] Fix | Delete
add_action( 'wp_before_admin_bar_render', array( $this, 'add_to_menubar' ) );
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Runs when Jetpack is deactivated from the network admin plugins menu.
[164] Fix | Delete
* Each individual site will need to have Jetpack::disconnect called on it.
[165] Fix | Delete
* Site that had Jetpack individually enabled will not be disconnected as
[166] Fix | Delete
* on Multisite individually activated plugins are still activated when
[167] Fix | Delete
* a plugin is deactivated network wide.
[168] Fix | Delete
*
[169] Fix | Delete
* @since 2.9
[170] Fix | Delete
**/
[171] Fix | Delete
public function deactivate() {
[172] Fix | Delete
// Only fire if in network admin.
[173] Fix | Delete
if ( ! is_network_admin() ) {
[174] Fix | Delete
return;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
$sites = get_sites();
[178] Fix | Delete
[179] Fix | Delete
foreach ( $sites as $s ) {
[180] Fix | Delete
switch_to_blog( (int) $s->blog_id );
[181] Fix | Delete
$active_plugins = get_option( 'active_plugins' );
[182] Fix | Delete
[183] Fix | Delete
/*
[184] Fix | Delete
* If this plugin was activated in the subsite individually
[185] Fix | Delete
* we do not want to call disconnect. Plugins activated
[186] Fix | Delete
* individually (before network activation) stay activated
[187] Fix | Delete
* when the network deactivation occurs
[188] Fix | Delete
*/
[189] Fix | Delete
if ( ! in_array( 'jetpack/jetpack.php', $active_plugins, true ) ) {
[190] Fix | Delete
Jetpack::disconnect();
[191] Fix | Delete
Jetpack_Options::delete_option( 'version' );
[192] Fix | Delete
}
[193] Fix | Delete
restore_current_blog();
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Adds a link to the Jetpack Network Admin page in the network admin menu bar.
[199] Fix | Delete
*
[200] Fix | Delete
* @since 2.9
[201] Fix | Delete
**/
[202] Fix | Delete
public function add_to_menubar() {
[203] Fix | Delete
global $wp_admin_bar;
[204] Fix | Delete
// Don't show for logged out users or single site mode.
[205] Fix | Delete
if ( ! is_user_logged_in() || ! is_multisite() ) {
[206] Fix | Delete
return;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
$wp_admin_bar->add_node(
[210] Fix | Delete
array(
[211] Fix | Delete
'parent' => 'network-admin',
[212] Fix | Delete
'id' => 'network-admin-jetpack',
[213] Fix | Delete
'title' => 'Jetpack',
[214] Fix | Delete
'href' => $this->get_url( 'network_admin_page' ),
[215] Fix | Delete
)
[216] Fix | Delete
);
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Returns various URL strings. Factory like
[221] Fix | Delete
*
[222] Fix | Delete
* $args can be a string or an array.
[223] Fix | Delete
* If $args is an array there must be an element called name for the switch statement
[224] Fix | Delete
*
[225] Fix | Delete
* Currently supports:
[226] Fix | Delete
* - subsiteregister: Pass array( 'name' => 'subsiteregister', 'site_id' => SITE_ID )
[227] Fix | Delete
* - network_admin_page: Provides link to /wp-admin/network/JETPACK
[228] Fix | Delete
* - subsitedisconnect: Pass array( 'name' => 'subsitedisconnect', 'site_id' => SITE_ID )
[229] Fix | Delete
*
[230] Fix | Delete
* @since 2.9
[231] Fix | Delete
*
[232] Fix | Delete
* @param Mixed $args URL parameters.
[233] Fix | Delete
*
[234] Fix | Delete
* @return String
[235] Fix | Delete
**/
[236] Fix | Delete
public function get_url( $args ) {
[237] Fix | Delete
$url = null; // Default url value.
[238] Fix | Delete
[239] Fix | Delete
if ( is_string( $args ) ) {
[240] Fix | Delete
$name = $args;
[241] Fix | Delete
} elseif ( is_array( $args ) ) {
[242] Fix | Delete
$name = $args['name'];
[243] Fix | Delete
} else {
[244] Fix | Delete
return $url;
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
switch ( $name ) {
[248] Fix | Delete
case 'subsiteregister':
[249] Fix | Delete
if ( ! isset( $args['site_id'] ) ) {
[250] Fix | Delete
break; // If there is not a site id present we cannot go further.
[251] Fix | Delete
}
[252] Fix | Delete
$url = network_admin_url(
[253] Fix | Delete
'admin.php?page=jetpack&action=subsiteregister&site_id='
[254] Fix | Delete
. $args['site_id']
[255] Fix | Delete
);
[256] Fix | Delete
break;
[257] Fix | Delete
[258] Fix | Delete
case 'network_admin_page':
[259] Fix | Delete
$url = network_admin_url( 'admin.php?page=jetpack' );
[260] Fix | Delete
break;
[261] Fix | Delete
[262] Fix | Delete
case 'subsitedisconnect':
[263] Fix | Delete
if ( ! isset( $args['site_id'] ) ) {
[264] Fix | Delete
break; // If there is not a site id present we cannot go further.
[265] Fix | Delete
}
[266] Fix | Delete
$url = network_admin_url(
[267] Fix | Delete
'admin.php?page=jetpack&action=subsitedisconnect&site_id='
[268] Fix | Delete
. $args['site_id']
[269] Fix | Delete
);
[270] Fix | Delete
break;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
return $url;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Adds the Jetpack menu item to the Network Admin area
[278] Fix | Delete
*
[279] Fix | Delete
* @since 2.9
[280] Fix | Delete
*/
[281] Fix | Delete
public function add_network_admin_menu() {
[282] Fix | Delete
$icon = ( new Logo() )->get_base64_logo();
[283] Fix | Delete
add_menu_page( 'Jetpack', 'Jetpack', 'jetpack_network_admin_page', 'jetpack', array( $this, 'wrap_network_admin_page' ), $icon, 3 );
[284] Fix | Delete
$jetpack_sites_page_hook = add_submenu_page( 'jetpack', __( 'Jetpack Sites', 'jetpack' ), __( 'Sites', 'jetpack' ), 'jetpack_network_sites_page', 'jetpack', array( $this, 'wrap_network_admin_page' ) );
[285] Fix | Delete
$jetpack_settings_page_hook = add_submenu_page( 'jetpack', __( 'Settings', 'jetpack' ), __( 'Settings', 'jetpack' ), 'jetpack_network_settings_page', 'jetpack-settings', array( $this, 'wrap_render_network_admin_settings_page' ) );
[286] Fix | Delete
add_action( "admin_print_styles-$jetpack_sites_page_hook", array( 'Jetpack_Admin_Page', 'load_wrapper_styles' ) );
[287] Fix | Delete
add_action( "admin_print_styles-$jetpack_settings_page_hook", array( 'Jetpack_Admin_Page', 'load_wrapper_styles' ) );
[288] Fix | Delete
/**
[289] Fix | Delete
* As jetpack_register_genericons is by default fired off a hook,
[290] Fix | Delete
* the hook may have already fired by this point.
[291] Fix | Delete
* So, let's just trigger it manually.
[292] Fix | Delete
*/
[293] Fix | Delete
require_once JETPACK__PLUGIN_DIR . '_inc/genericons.php';
[294] Fix | Delete
jetpack_register_genericons();
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* Provides functionality for the Jetpack > Sites page.
[299] Fix | Delete
* Does not do the display!
[300] Fix | Delete
*
[301] Fix | Delete
* @since 2.9
[302] Fix | Delete
*/
[303] Fix | Delete
public function jetpack_sites_list() {
[304] Fix | Delete
Jetpack::init();
[305] Fix | Delete
[306] Fix | Delete
if ( isset( $_GET['action'] ) ) {
[307] Fix | Delete
switch ( $_GET['action'] ) {
[308] Fix | Delete
case 'subsiteregister':
[309] Fix | Delete
check_admin_referer( 'jetpack-subsite-register' );
[310] Fix | Delete
Jetpack::log( 'subsiteregister' );
[311] Fix | Delete
[312] Fix | Delete
// If no site_id, stop registration and error.
[313] Fix | Delete
if ( ! isset( $_GET['site_id'] ) || empty( $_GET['site_id'] ) ) {
[314] Fix | Delete
/**
[315] Fix | Delete
* Log error to state cookie for display later.
[316] Fix | Delete
*
[317] Fix | Delete
* @todo Make state messages show on Jetpack NA pages
[318] Fix | Delete
*/
[319] Fix | Delete
Jetpack::state( 'missing_site_id', esc_html__( 'Site ID must be provided to register a sub-site.', 'jetpack' ) );
[320] Fix | Delete
break;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
// Send data to register endpoint and retrieve shadow blog details.
[324] Fix | Delete
$result = $this->do_subsiteregister();
[325] Fix | Delete
$url = $this->get_url( 'network_admin_page' );
[326] Fix | Delete
[327] Fix | Delete
if ( is_wp_error( $result ) ) {
[328] Fix | Delete
$url = add_query_arg( 'action', 'connection_failed', $url );
[329] Fix | Delete
} else {
[330] Fix | Delete
$url = add_query_arg( 'action', 'connected', $url );
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
wp_safe_redirect( $url );
[334] Fix | Delete
exit( 0 );
[335] Fix | Delete
[336] Fix | Delete
case 'subsitedisconnect':
[337] Fix | Delete
check_admin_referer( 'jetpack-subsite-disconnect' );
[338] Fix | Delete
Jetpack::log( 'subsitedisconnect' );
[339] Fix | Delete
[340] Fix | Delete
if ( ! isset( $_GET['site_id'] ) || empty( $_GET['site_id'] ) ) {
[341] Fix | Delete
Jetpack::state( 'missing_site_id', esc_html__( 'Site ID must be provided to disconnect a sub-site.', 'jetpack' ) );
[342] Fix | Delete
break;
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
$this->do_subsitedisconnect();
[346] Fix | Delete
break;
[347] Fix | Delete
[348] Fix | Delete
case 'connected':
[349] Fix | Delete
case 'connection_failed':
[350] Fix | Delete
add_action( 'jetpack_notices', array( $this, 'show_jetpack_notice' ) );
[351] Fix | Delete
break;
[352] Fix | Delete
}
[353] Fix | Delete
}
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
/**
[357] Fix | Delete
* Set the disconnect capability for multisite.
[358] Fix | Delete
*
[359] Fix | Delete
* @param array $caps The capabilities array.
[360] Fix | Delete
*/
[361] Fix | Delete
public function set_multisite_disconnect_cap( $caps ) {
[362] Fix | Delete
// Can individual site admins manage their own connection?
[363] Fix | Delete
if ( ! is_super_admin() && ! $this->get_option( 'sub-site-connection-override' ) ) {
[364] Fix | Delete
/*
[365] Fix | Delete
* We need to update the option name -- it's terribly unclear which
[366] Fix | Delete
* direction the override goes.
[367] Fix | Delete
*
[368] Fix | Delete
* @todo: Update the option name to `sub-sites-can-manage-own-connections`
[369] Fix | Delete
*/
[370] Fix | Delete
return array( 'do_not_allow' );
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
return $caps;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Shows the Jetpack plugin notices.
[378] Fix | Delete
*/
[379] Fix | Delete
public function show_jetpack_notice() {
[380] Fix | Delete
if ( isset( $_GET['action'] ) && 'connected' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
[381] Fix | Delete
$notice = __( 'Site successfully connected.', 'jetpack' );
[382] Fix | Delete
$classname = 'updated';
[383] Fix | Delete
} elseif ( isset( $_GET['action'] ) && 'connection_failed' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
[384] Fix | Delete
$notice = __( 'Site connection failed!', 'jetpack' );
[385] Fix | Delete
$classname = 'error';
[386] Fix | Delete
}
[387] Fix | Delete
?>
[388] Fix | Delete
<div id="message" class="<?php echo esc_attr( $classname ); ?> jetpack-message jp-connect" style="display:block !important;">
[389] Fix | Delete
<p><?php echo esc_html( $notice ); ?></p>
[390] Fix | Delete
</div>
[391] Fix | Delete
<?php
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
/**
[395] Fix | Delete
* Disconnect functionality for an individual site
[396] Fix | Delete
*
[397] Fix | Delete
* @since 2.9
[398] Fix | Delete
* @see Jetpack_Network::jetpack_sites_list()
[399] Fix | Delete
*
[400] Fix | Delete
* @param int $site_id the site identifier.
[401] Fix | Delete
*/
[402] Fix | Delete
public function do_subsitedisconnect( $site_id = null ) {
[403] Fix | Delete
if ( ! current_user_can( 'jetpack_disconnect' ) ) {
[404] Fix | Delete
return;
[405] Fix | Delete
}
[406] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Caller (i.e. `$this->jetpack_sites_list()`) should check.
[407] Fix | Delete
$site_id = ( $site_id === null ) ? ( isset( $_GET['site_id'] ) ? (int) $_GET['site_id'] : null ) : $site_id;
[408] Fix | Delete
switch_to_blog( $site_id );
[409] Fix | Delete
Jetpack::disconnect();
[410] Fix | Delete
restore_current_blog();
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
/**
[414] Fix | Delete
* Registers a subsite with the Jetpack servers
[415] Fix | Delete
*
[416] Fix | Delete
* @since 2.9
[417] Fix | Delete
* @todo Break apart into easier to manage chunks that can be unit tested
[418] Fix | Delete
* @see Jetpack_Network::jetpack_sites_list();
[419] Fix | Delete
*
[420] Fix | Delete
* @param int $site_id the site identifier.
[421] Fix | Delete
*/
[422] Fix | Delete
public function do_subsiteregister( $site_id = null ) {
[423] Fix | Delete
if ( ! current_user_can( 'jetpack_disconnect' ) ) {
[424] Fix | Delete
return;
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
if ( ( new Status() )->is_offline_mode() ) {
[428] Fix | Delete
return;
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
// Figure out what site we are working on.
[432] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Caller (i.e. `$this->jetpack_sites_list()`) should check.
[433] Fix | Delete
$site_id = ( $site_id === null ) ? ( isset( $_GET['site_id'] ) ? (int) $_GET['site_id'] : null ) : $site_id;
[434] Fix | Delete
[435] Fix | Delete
/*
[436] Fix | Delete
* Here we need to switch to the subsite
[437] Fix | Delete
* For the registration process we really only hijack how it
[438] Fix | Delete
* works for an individual site and pass in some extra data here
[439] Fix | Delete
*/
[440] Fix | Delete
switch_to_blog( $site_id );
[441] Fix | Delete
[442] Fix | Delete
add_filter( 'jetpack_register_request_body', array( $this, 'filter_register_request_body' ) );
[443] Fix | Delete
add_action( 'jetpack_site_registered_user_token', array( $this, 'filter_register_user_token' ) );
[444] Fix | Delete
[445] Fix | Delete
// Save the secrets in the subsite so when the wpcom server does a pingback it
[446] Fix | Delete
// will be able to validate the connection.
[447] Fix | Delete
$result = $this->connection->register( 'subsiteregister' );
[448] Fix | Delete
[449] Fix | Delete
if ( is_wp_error( $result ) || ! $result ) {
[450] Fix | Delete
restore_current_blog();
[451] Fix | Delete
return $result;
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
Jetpack::activate_default_modules( false, false, array(), false );
[455] Fix | Delete
[456] Fix | Delete
restore_current_blog();
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
/**
[460] Fix | Delete
* Receives the registration response token.
[461] Fix | Delete
*
[462] Fix | Delete
* @param Object $token the received token.
[463] Fix | Delete
*/
[464] Fix | Delete
public function filter_register_user_token( $token ) {
[465] Fix | Delete
$is_connection_owner = ! $this->connection->has_connected_owner();
[466] Fix | Delete
( new Tokens() )->update_user_token(
[467] Fix | Delete
get_current_user_id(),
[468] Fix | Delete
sprintf( '%s.%d', $token->secret, get_current_user_id() ),
[469] Fix | Delete
$is_connection_owner
[470] Fix | Delete
);
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Filters the registration request body to include additional properties.
[475] Fix | Delete
*
[476] Fix | Delete
* @param array $properties standard register request body properties.
[477] Fix | Delete
* @return array amended properties.
[478] Fix | Delete
*/
[479] Fix | Delete
public function filter_register_request_body( $properties ) {
[480] Fix | Delete
$blog_details = get_blog_details();
[481] Fix | Delete
[482] Fix | Delete
$network = get_network();
[483] Fix | Delete
[484] Fix | Delete
switch_to_blog( $network->blog_id );
[485] Fix | Delete
// The blog id on WordPress.com of the primary network site.
[486] Fix | Delete
$network_wpcom_blog_id = Jetpack_Options::get_option( 'id' );
[487] Fix | Delete
restore_current_blog();
[488] Fix | Delete
[489] Fix | Delete
/**
[490] Fix | Delete
* Both `state` and `user_id` need to be sent in the request, even though they are the same value.
[491] Fix | Delete
* Connecting via the network admin combines `register()` and `authorize()` methods into one step,
[492] Fix | Delete
* because we assume the main site is already authorized. `state` is used to verify the `register()`
[493] Fix | Delete
* request, while `user_id()` is used to create the token in the `authorize()` request.
[494] Fix | Delete
*/
[495] Fix | Delete
return array_merge(
[496] Fix | Delete
$properties,
[497] Fix | Delete
array(
[498] Fix | Delete
'network_url' => $this->get_url( 'network_admin_page' ),
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function