Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack
File: class.jetpack-cli.php
array(
[1000] Fix | Delete
'sync_wait_time' => 0,
[1001] Fix | Delete
'enqueue_wait_time' => 0,
[1002] Fix | Delete
'queue_max_writes_sec' => 10000,
[1003] Fix | Delete
'max_queue_size_full_sync' => 100000,
[1004] Fix | Delete
'full_sync_send_duration' => HOUR_IN_SECONDS,
[1005] Fix | Delete
)
[1006] Fix | Delete
);
[1007] Fix | Delete
Settings::update_settings( $sync_settings );
[1008] Fix | Delete
[1009] Fix | Delete
// Convert comma-delimited string of modules to an array.
[1010] Fix | Delete
if ( ! empty( $assoc_args['modules'] ) ) {
[1011] Fix | Delete
$modules = array_map( 'trim', explode( ',', $assoc_args['modules'] ) );
[1012] Fix | Delete
[1013] Fix | Delete
// Convert the array so that the keys are the module name and the value is true to indicate
[1014] Fix | Delete
// that we want to sync the module.
[1015] Fix | Delete
$modules = array_map( '__return_true', array_flip( $modules ) );
[1016] Fix | Delete
}
[1017] Fix | Delete
[1018] Fix | Delete
foreach ( array( 'posts', 'comments', 'users' ) as $module_name ) {
[1019] Fix | Delete
if (
[1020] Fix | Delete
'users' === $module_name &&
[1021] Fix | Delete
isset( $assoc_args[ $module_name ] ) &&
[1022] Fix | Delete
'initial' === $assoc_args[ $module_name ]
[1023] Fix | Delete
) {
[1024] Fix | Delete
$modules['users'] = 'initial';
[1025] Fix | Delete
} elseif ( isset( $assoc_args[ $module_name ] ) ) {
[1026] Fix | Delete
$ids = explode( ',', $assoc_args[ $module_name ] );
[1027] Fix | Delete
if ( $ids !== array() ) {
[1028] Fix | Delete
$modules[ $module_name ] = $ids;
[1029] Fix | Delete
}
[1030] Fix | Delete
}
[1031] Fix | Delete
}
[1032] Fix | Delete
[1033] Fix | Delete
if ( empty( $modules ) ) {
[1034] Fix | Delete
$modules = null;
[1035] Fix | Delete
}
[1036] Fix | Delete
[1037] Fix | Delete
// Kick off a full sync.
[1038] Fix | Delete
if ( Actions::do_full_sync( $modules, 'jetpack_cli' ) ) {
[1039] Fix | Delete
if ( $modules ) {
[1040] Fix | Delete
/* translators: %s is a comma separated list of Jetpack modules */
[1041] Fix | Delete
WP_CLI::log( sprintf( __( 'Initialized a new full sync with modules: %s', 'jetpack' ), implode( ', ', array_keys( $modules ) ) ) );
[1042] Fix | Delete
} else {
[1043] Fix | Delete
WP_CLI::log( __( 'Initialized a new full sync', 'jetpack' ) );
[1044] Fix | Delete
}
[1045] Fix | Delete
} else {
[1046] Fix | Delete
[1047] Fix | Delete
// Reset sync settings to original.
[1048] Fix | Delete
Settings::update_settings( $original_settings );
[1049] Fix | Delete
[1050] Fix | Delete
if ( $modules ) {
[1051] Fix | Delete
/* translators: %s is a comma separated list of Jetpack modules */
[1052] Fix | Delete
WP_CLI::error( sprintf( __( 'Could not start a new full sync with modules: %s', 'jetpack' ), implode( ', ', $modules ) ) );
[1053] Fix | Delete
} else {
[1054] Fix | Delete
WP_CLI::error( __( 'Could not start a new full sync', 'jetpack' ) );
[1055] Fix | Delete
}
[1056] Fix | Delete
}
[1057] Fix | Delete
[1058] Fix | Delete
// Keep sending to WPCOM until there's nothing to send.
[1059] Fix | Delete
$i = 1;
[1060] Fix | Delete
do {
[1061] Fix | Delete
$result = Actions::$sender->do_full_sync();
[1062] Fix | Delete
if ( is_wp_error( $result ) ) {
[1063] Fix | Delete
$queue_empty_error = ( 'empty_queue_full_sync' === $result->get_error_code() );
[1064] Fix | Delete
if ( ! $queue_empty_error || ( $queue_empty_error && ( 1 === $i ) ) ) {
[1065] Fix | Delete
/* translators: %s is an error code */
[1066] Fix | Delete
WP_CLI::error( sprintf( __( 'Sync errored with code: %s', 'jetpack' ), $result->get_error_code() ) );
[1067] Fix | Delete
}
[1068] Fix | Delete
} else {
[1069] Fix | Delete
if ( 1 === $i ) {
[1070] Fix | Delete
WP_CLI::log( __( 'Sent data to WordPress.com', 'jetpack' ) );
[1071] Fix | Delete
} else {
[1072] Fix | Delete
WP_CLI::log( __( 'Sent more data to WordPress.com', 'jetpack' ) );
[1073] Fix | Delete
}
[1074] Fix | Delete
[1075] Fix | Delete
// Immediate Full Sync does not wait for WP.com to process data so we need to enforce a wait.
[1076] Fix | Delete
if ( Modules::get_module( 'full-sync' ) instanceof \Automattic\Jetpack\Sync\Modules\Full_Sync_Immediately ) {
[1077] Fix | Delete
sleep( 15 );
[1078] Fix | Delete
}
[1079] Fix | Delete
}
[1080] Fix | Delete
++$i;
[1081] Fix | Delete
} while ( $result && ! is_wp_error( $result ) );
[1082] Fix | Delete
[1083] Fix | Delete
// Reset sync settings to original.
[1084] Fix | Delete
Settings::update_settings( $original_settings );
[1085] Fix | Delete
[1086] Fix | Delete
WP_CLI::success( __( 'Finished syncing to WordPress.com', 'jetpack' ) );
[1087] Fix | Delete
break;
[1088] Fix | Delete
}
[1089] Fix | Delete
}
[1090] Fix | Delete
[1091] Fix | Delete
/**
[1092] Fix | Delete
* List the contents of a specific Jetpack sync queue.
[1093] Fix | Delete
*
[1094] Fix | Delete
* ## OPTIONS
[1095] Fix | Delete
*
[1096] Fix | Delete
* peek : List the 100 front-most items on the queue.
[1097] Fix | Delete
*
[1098] Fix | Delete
* ## EXAMPLES
[1099] Fix | Delete
*
[1100] Fix | Delete
* wp jetpack sync_queue full_sync peek
[1101] Fix | Delete
*
[1102] Fix | Delete
* @synopsis <incremental|full_sync> <peek>
[1103] Fix | Delete
*
[1104] Fix | Delete
* @param array $args Positional args.
[1105] Fix | Delete
*/
[1106] Fix | Delete
public function sync_queue( $args ) {
[1107] Fix | Delete
if ( ! Actions::sync_allowed() ) {
[1108] Fix | Delete
WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site.', 'jetpack' ) );
[1109] Fix | Delete
}
[1110] Fix | Delete
[1111] Fix | Delete
$queue_name = isset( $args[0] ) ? $args[0] : 'sync';
[1112] Fix | Delete
$action = isset( $args[1] ) ? $args[1] : 'peek';
[1113] Fix | Delete
[1114] Fix | Delete
// We map the queue name that way we can support more friendly queue names in the commands, but still use
[1115] Fix | Delete
// the queue name that the code expects.
[1116] Fix | Delete
$allowed_queues = array(
[1117] Fix | Delete
'incremental' => 'sync',
[1118] Fix | Delete
'full' => 'full_sync',
[1119] Fix | Delete
);
[1120] Fix | Delete
$queue_name_map = $allowed_queues;
[1121] Fix | Delete
$mapped_queue_name = isset( $queue_name_map[ $queue_name ] ) ? $queue_name_map[ $queue_name ] : $queue_name;
[1122] Fix | Delete
[1123] Fix | Delete
switch ( $action ) {
[1124] Fix | Delete
case 'peek':
[1125] Fix | Delete
$queue = new Queue( $mapped_queue_name );
[1126] Fix | Delete
$items = $queue->peek( 100 );
[1127] Fix | Delete
[1128] Fix | Delete
if ( empty( $items ) ) {
[1129] Fix | Delete
/* translators: %s is the name of the queue, either 'incremental' or 'full' */
[1130] Fix | Delete
WP_CLI::log( sprintf( __( 'Nothing is in the queue: %s', 'jetpack' ), $queue_name ) );
[1131] Fix | Delete
} else {
[1132] Fix | Delete
$collection = array();
[1133] Fix | Delete
foreach ( $items as $item ) {
[1134] Fix | Delete
$collection[] = array(
[1135] Fix | Delete
'action' => $item[0],
[1136] Fix | Delete
'args' => wp_json_encode( $item[1] ),
[1137] Fix | Delete
'current_user_id' => $item[2],
[1138] Fix | Delete
'microtime' => $item[3],
[1139] Fix | Delete
'importing' => (string) $item[4],
[1140] Fix | Delete
);
[1141] Fix | Delete
}
[1142] Fix | Delete
WP_CLI\Utils\format_items(
[1143] Fix | Delete
'table',
[1144] Fix | Delete
$collection,
[1145] Fix | Delete
array(
[1146] Fix | Delete
'action',
[1147] Fix | Delete
'args',
[1148] Fix | Delete
'current_user_id',
[1149] Fix | Delete
'microtime',
[1150] Fix | Delete
'importing',
[1151] Fix | Delete
)
[1152] Fix | Delete
);
[1153] Fix | Delete
}
[1154] Fix | Delete
break;
[1155] Fix | Delete
}
[1156] Fix | Delete
}
[1157] Fix | Delete
[1158] Fix | Delete
/**
[1159] Fix | Delete
* Cancel's the current Jetpack plan granted by this partner, if applicable
[1160] Fix | Delete
*
[1161] Fix | Delete
* Returns success or error JSON
[1162] Fix | Delete
*
[1163] Fix | Delete
* <token_json>
[1164] Fix | Delete
* : JSON blob of WPCOM API token
[1165] Fix | Delete
* [--partner_tracking_id=<partner_tracking_id>]
[1166] Fix | Delete
* : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com
[1167] Fix | Delete
*
[1168] Fix | Delete
* @synopsis <token_json> [--partner_tracking_id=<partner_tracking_id>]
[1169] Fix | Delete
*
[1170] Fix | Delete
* @param array $args Positional args.
[1171] Fix | Delete
* @param array $named_args Named args.
[1172] Fix | Delete
*/
[1173] Fix | Delete
public function partner_cancel( $args, $named_args ) {
[1174] Fix | Delete
list( $token_json ) = $args;
[1175] Fix | Delete
[1176] Fix | Delete
$token = $token_json ? json_decode( $token_json ) : null;
[1177] Fix | Delete
if ( ! $token ) {
[1178] Fix | Delete
/* translators: %s is the invalid JSON string */
[1179] Fix | Delete
$this->partner_provision_error( new WP_Error( 'missing_access_token', sprintf( __( 'Invalid token JSON: %s', 'jetpack' ), $token_json ) ) );
[1180] Fix | Delete
}
[1181] Fix | Delete
[1182] Fix | Delete
if ( isset( $token->error ) ) {
[1183] Fix | Delete
$this->partner_provision_error( new WP_Error( $token->error, $token->message ) );
[1184] Fix | Delete
}
[1185] Fix | Delete
[1186] Fix | Delete
if ( ! isset( $token->access_token ) ) {
[1187] Fix | Delete
$this->partner_provision_error( new WP_Error( 'missing_access_token', __( 'Missing or invalid access token', 'jetpack' ) ) );
[1188] Fix | Delete
}
[1189] Fix | Delete
[1190] Fix | Delete
if ( Identity_Crisis::validate_sync_error_idc_option() ) {
[1191] Fix | Delete
$this->partner_provision_error(
[1192] Fix | Delete
new WP_Error(
[1193] Fix | Delete
'site_in_safe_mode',
[1194] Fix | Delete
esc_html__( 'Can not cancel a plan while in safe mode. See: https://jetpack.com/support/safe-mode/', 'jetpack' )
[1195] Fix | Delete
)
[1196] Fix | Delete
);
[1197] Fix | Delete
}
[1198] Fix | Delete
[1199] Fix | Delete
$site_identifier = Jetpack_Options::get_option( 'id' );
[1200] Fix | Delete
[1201] Fix | Delete
if ( ! $site_identifier ) {
[1202] Fix | Delete
$status = new Status();
[1203] Fix | Delete
$site_identifier = $status->get_site_suffix();
[1204] Fix | Delete
}
[1205] Fix | Delete
[1206] Fix | Delete
$request = array(
[1207] Fix | Delete
'headers' => array(
[1208] Fix | Delete
'Authorization' => 'Bearer ' . $token->access_token,
[1209] Fix | Delete
'Host' => 'public-api.wordpress.com',
[1210] Fix | Delete
),
[1211] Fix | Delete
'timeout' => 60,
[1212] Fix | Delete
'method' => 'POST',
[1213] Fix | Delete
);
[1214] Fix | Delete
[1215] Fix | Delete
$url = sprintf( '%s/rest/v1.3/jpphp/%s/partner-cancel', $this->get_api_host(), $site_identifier );
[1216] Fix | Delete
if ( ! empty( $named_args ) && ! empty( $named_args['partner_tracking_id'] ) ) {
[1217] Fix | Delete
$url = esc_url_raw( add_query_arg( 'partner_tracking_id', $named_args['partner_tracking_id'], $url ) );
[1218] Fix | Delete
}
[1219] Fix | Delete
[1220] Fix | Delete
$result = Client::_wp_remote_request( $url, $request );
[1221] Fix | Delete
[1222] Fix | Delete
if ( is_wp_error( $result ) ) {
[1223] Fix | Delete
$this->partner_provision_error( $result );
[1224] Fix | Delete
}
[1225] Fix | Delete
[1226] Fix | Delete
WP_CLI::log( wp_remote_retrieve_body( $result ) );
[1227] Fix | Delete
}
[1228] Fix | Delete
[1229] Fix | Delete
/**
[1230] Fix | Delete
* Provision a site using a Jetpack Partner license
[1231] Fix | Delete
*
[1232] Fix | Delete
* Returns JSON blob
[1233] Fix | Delete
*
[1234] Fix | Delete
* ## OPTIONS
[1235] Fix | Delete
*
[1236] Fix | Delete
* <token_json>
[1237] Fix | Delete
* : JSON blob of WPCOM API token
[1238] Fix | Delete
* [--plan=<plan_name>]
[1239] Fix | Delete
* : Slug of the requested plan, e.g. premium
[1240] Fix | Delete
* [--wpcom_user_id=<user_id>]
[1241] Fix | Delete
* : WordPress.com ID of user to connect as (must be whitelisted against partner key)
[1242] Fix | Delete
* [--wpcom_user_email=<wpcom_user_email>]
[1243] Fix | Delete
* : Override the email we send to WordPress.com for registration
[1244] Fix | Delete
* [--force_register=<register>]
[1245] Fix | Delete
* : Whether to force a site to register
[1246] Fix | Delete
* [--force_connect=<force_connect>]
[1247] Fix | Delete
* : Force JPS to not reuse existing credentials
[1248] Fix | Delete
* [--home_url=<home_url>]
[1249] Fix | Delete
* : Overrides the home option via the home_url filter, or the WP_HOME constant
[1250] Fix | Delete
* [--site_url=<site_url>]
[1251] Fix | Delete
* : Overrides the siteurl option via the site_url filter, or the WP_SITEURL constant
[1252] Fix | Delete
* [--partner_tracking_id=<partner_tracking_id>]
[1253] Fix | Delete
* : This is an optional ID that a host can pass to help identify a site in logs on WordPress.com
[1254] Fix | Delete
*
[1255] Fix | Delete
* ## EXAMPLES
[1256] Fix | Delete
*
[1257] Fix | Delete
* $ wp jetpack partner_provision '{ some: "json" }' premium 1
[1258] Fix | Delete
* { success: true }
[1259] Fix | Delete
*
[1260] Fix | Delete
* @synopsis <token_json> [--wpcom_user_id=<user_id>] [--plan=<plan_name>] [--force_register=<register>] [--force_connect=<force_connect>] [--home_url=<home_url>] [--site_url=<site_url>] [--wpcom_user_email=<wpcom_user_email>] [--partner_tracking_id=<partner_tracking_id>]
[1261] Fix | Delete
*
[1262] Fix | Delete
* @param array $args Positional args.
[1263] Fix | Delete
* @param array $named_args Named args.
[1264] Fix | Delete
*/
[1265] Fix | Delete
public function partner_provision( $args, $named_args ) {
[1266] Fix | Delete
list( $token_json ) = $args;
[1267] Fix | Delete
[1268] Fix | Delete
$token = $token_json ? json_decode( $token_json ) : null;
[1269] Fix | Delete
if ( ! $token ) {
[1270] Fix | Delete
/* translators: %s is the invalid JSON string */
[1271] Fix | Delete
$this->partner_provision_error( new WP_Error( 'missing_access_token', sprintf( __( 'Invalid token JSON: %s', 'jetpack' ), $token_json ) ) );
[1272] Fix | Delete
}
[1273] Fix | Delete
[1274] Fix | Delete
if ( isset( $token->error ) ) {
[1275] Fix | Delete
$message = isset( $token->message )
[1276] Fix | Delete
? $token->message
[1277] Fix | Delete
: '';
[1278] Fix | Delete
$this->partner_provision_error( new WP_Error( $token->error, $message ) );
[1279] Fix | Delete
}
[1280] Fix | Delete
[1281] Fix | Delete
if ( ! isset( $token->access_token ) ) {
[1282] Fix | Delete
$this->partner_provision_error( new WP_Error( 'missing_access_token', __( 'Missing or invalid access token', 'jetpack' ) ) );
[1283] Fix | Delete
}
[1284] Fix | Delete
[1285] Fix | Delete
require_once JETPACK__PLUGIN_DIR . '_inc/class.jetpack-provision.php';
[1286] Fix | Delete
[1287] Fix | Delete
$body_json = Jetpack_Provision::partner_provision( $token->access_token, $named_args );
[1288] Fix | Delete
[1289] Fix | Delete
if ( is_wp_error( $body_json ) ) {
[1290] Fix | Delete
WP_CLI::error(
[1291] Fix | Delete
wp_json_encode(
[1292] Fix | Delete
array(
[1293] Fix | Delete
'success' => false,
[1294] Fix | Delete
'error_code' => $body_json->get_error_code(),
[1295] Fix | Delete
'error_message' => $body_json->get_error_message(),
[1296] Fix | Delete
)
[1297] Fix | Delete
)
[1298] Fix | Delete
);
[1299] Fix | Delete
exit( 1 );
[1300] Fix | Delete
}
[1301] Fix | Delete
[1302] Fix | Delete
WP_CLI::log( wp_json_encode( $body_json ) );
[1303] Fix | Delete
}
[1304] Fix | Delete
[1305] Fix | Delete
/**
[1306] Fix | Delete
* Manages your Jetpack sitemap
[1307] Fix | Delete
*
[1308] Fix | Delete
* ## OPTIONS
[1309] Fix | Delete
*
[1310] Fix | Delete
* rebuild : Rebuild all sitemaps
[1311] Fix | Delete
* --purge : if set, will remove all existing sitemap data before rebuilding
[1312] Fix | Delete
* --monitor : if set, will output elapsed time, peak memory usage, CPU time (user/system), and average CPU utilization
[1313] Fix | Delete
* --suspend-cache-addition : if set, will suspend cache additions during sitemap generation
[1314] Fix | Delete
*
[1315] Fix | Delete
* ## EXAMPLES
[1316] Fix | Delete
*
[1317] Fix | Delete
* wp jetpack sitemap rebuild
[1318] Fix | Delete
* wp jetpack sitemap rebuild --monitor
[1319] Fix | Delete
*
[1320] Fix | Delete
* @subcommand sitemap
[1321] Fix | Delete
* @synopsis <rebuild> [--purge] [--monitor] [--suspend-cache-addition]
[1322] Fix | Delete
*
[1323] Fix | Delete
* @param array $args Positional args.
[1324] Fix | Delete
* @param array $assoc_args Named args.
[1325] Fix | Delete
*/
[1326] Fix | Delete
public function sitemap( $args, $assoc_args ) {
[1327] Fix | Delete
if ( ! Jetpack::is_module_active( 'sitemaps' ) ) {
[1328] Fix | Delete
WP_CLI::error( __( 'Jetpack Sitemaps module is not currently active. Activate it first if you want to work with sitemaps.', 'jetpack' ) );
[1329] Fix | Delete
}
[1330] Fix | Delete
if ( ! class_exists( 'Jetpack_Sitemap_Builder' ) ) {
[1331] Fix | Delete
WP_CLI::error( __( 'Jetpack Sitemaps module is active, but unavailable. This can happen if your site is set to discourage search engine indexing. Please enable search engine indexing to allow sitemap generation.', 'jetpack' ) );
[1332] Fix | Delete
}
[1333] Fix | Delete
[1334] Fix | Delete
if ( isset( $assoc_args['suspend-cache-addition'] ) && $assoc_args['suspend-cache-addition'] ) {
[1335] Fix | Delete
add_filter( 'jetpack_sitemap_suspend_cache_addition', '__return_true' );
[1336] Fix | Delete
WP_CLI::success( 'Suspending cache addition.' );
[1337] Fix | Delete
}
[1338] Fix | Delete
[1339] Fix | Delete
$monitor = isset( $assoc_args['monitor'] ) && $assoc_args['monitor'];
[1340] Fix | Delete
[1341] Fix | Delete
if ( $monitor ) {
[1342] Fix | Delete
$start_time = microtime( true );
[1343] Fix | Delete
$rusage_start = function_exists( 'getrusage' ) ? getrusage() : null;
[1344] Fix | Delete
}
[1345] Fix | Delete
[1346] Fix | Delete
if ( isset( $assoc_args['purge'] ) && $assoc_args['purge'] ) {
[1347] Fix | Delete
$librarian = new Jetpack_Sitemap_Librarian();
[1348] Fix | Delete
$librarian->delete_all_stored_sitemap_data();
[1349] Fix | Delete
[1350] Fix | Delete
// Clear sitemap-related transients
[1351] Fix | Delete
delete_transient( 'jetpack_news_sitemap_xml' );
[1352] Fix | Delete
delete_transient( 'jetpack-sitemap-state-lock' );
[1353] Fix | Delete
WP_CLI::success( __( 'Purged all sitemap data and cleared sitemap transients.', 'jetpack' ) );
[1354] Fix | Delete
}
[1355] Fix | Delete
[1356] Fix | Delete
$sitemap_builder = new Jetpack_Sitemap_Builder();
[1357] Fix | Delete
$sitemap_builder->update_sitemap();
[1358] Fix | Delete
[1359] Fix | Delete
WP_CLI::success( __( 'Sitemap rebuilt successfully.', 'jetpack' ) );
[1360] Fix | Delete
[1361] Fix | Delete
if ( $monitor && isset( $start_time ) ) {
[1362] Fix | Delete
$end_time = microtime( true );
[1363] Fix | Delete
$peak_memory = memory_get_peak_usage();
[1364] Fix | Delete
$elapsed_time = $end_time - $start_time;
[1365] Fix | Delete
$rusage_end = function_exists( 'getrusage' ) ? getrusage() : null;
[1366] Fix | Delete
[1367] Fix | Delete
WP_CLI::log( '----------------------------------' );
[1368] Fix | Delete
WP_CLI::log( __( 'Performance Metrics:', 'jetpack' ) );
[1369] Fix | Delete
/* translators: %s is a float representing seconds */
[1370] Fix | Delete
WP_CLI::log( sprintf( __( 'Elapsed Time: %.4f seconds', 'jetpack' ), $elapsed_time ) );
[1371] Fix | Delete
/* translators: %s is a human-readable memory size (e.g., 128MB) */
[1372] Fix | Delete
WP_CLI::log( sprintf( __( 'Peak Memory Usage: %s', 'jetpack' ), size_format( $peak_memory ) ) );
[1373] Fix | Delete
[1374] Fix | Delete
if ( ! empty( $rusage_start ) && ! empty( $rusage_end ) ) {
[1375] Fix | Delete
$user_cpu_time = ( $rusage_end['ru_utime.tv_sec'] * 1e6 + $rusage_end['ru_utime.tv_usec'] ) - ( $rusage_start['ru_utime.tv_sec'] * 1e6 + $rusage_start['ru_utime.tv_usec'] );
[1376] Fix | Delete
$system_cpu_time = ( $rusage_end['ru_stime.tv_sec'] * 1e6 + $rusage_end['ru_stime.tv_usec'] ) - ( $rusage_start['ru_stime.tv_sec'] * 1e6 + $rusage_start['ru_stime.tv_usec'] );
[1377] Fix | Delete
[1378] Fix | Delete
/* translators: %d is an integer representing microseconds */
[1379] Fix | Delete
WP_CLI::log( sprintf( __( 'CPU time (user): %d microseconds', 'jetpack' ), $user_cpu_time ) );
[1380] Fix | Delete
/* translators: %d is an integer representing microseconds */
[1381] Fix | Delete
WP_CLI::log( sprintf( __( 'CPU time (system): %d microseconds', 'jetpack' ), $system_cpu_time ) );
[1382] Fix | Delete
[1383] Fix | Delete
// Average CPU utilization over the elapsed wall time.
[1384] Fix | Delete
$total_cpu_sec = ( $user_cpu_time + $system_cpu_time ) / 1e6;
[1385] Fix | Delete
$avg_cpu_pct = $elapsed_time > 0 ? ( $total_cpu_sec / $elapsed_time ) * 100 : 0.0;
[1386] Fix | Delete
/* translators: %s is a percentage like 83.4 */
[1387] Fix | Delete
WP_CLI::log( sprintf( __( 'Average CPU Utilization: %.1f%%', 'jetpack' ), $avg_cpu_pct ) );
[1388] Fix | Delete
}
[1389] Fix | Delete
WP_CLI::log( '----------------------------------' );
[1390] Fix | Delete
}
[1391] Fix | Delete
}
[1392] Fix | Delete
[1393] Fix | Delete
/**
[1394] Fix | Delete
* Allows authorizing a user via the command line and will activate
[1395] Fix | Delete
*
[1396] Fix | Delete
* ## EXAMPLES
[1397] Fix | Delete
*
[1398] Fix | Delete
* wp jetpack authorize_user --token=123456789abcdef
[1399] Fix | Delete
*
[1400] Fix | Delete
* @synopsis --token=<value>
[1401] Fix | Delete
*
[1402] Fix | Delete
* @param array $args Positional args.
[1403] Fix | Delete
* @param array $named_args Named args.
[1404] Fix | Delete
*/
[1405] Fix | Delete
public function authorize_user( $args, $named_args ) {
[1406] Fix | Delete
if ( ! is_user_logged_in() ) {
[1407] Fix | Delete
WP_CLI::error( __( 'Please select a user to authorize via the --user global argument.', 'jetpack' ) );
[1408] Fix | Delete
}
[1409] Fix | Delete
[1410] Fix | Delete
if ( empty( $named_args['token'] ) ) {
[1411] Fix | Delete
WP_CLI::error( __( 'A non-empty token argument must be passed.', 'jetpack' ) );
[1412] Fix | Delete
}
[1413] Fix | Delete
[1414] Fix | Delete
$is_connection_owner = ! Jetpack::connection()->has_connected_owner();
[1415] Fix | Delete
$current_user_id = get_current_user_id();
[1416] Fix | Delete
[1417] Fix | Delete
( new Tokens() )->update_user_token( $current_user_id, sprintf( '%s.%d', $named_args['token'], $current_user_id ), $is_connection_owner );
[1418] Fix | Delete
[1419] Fix | Delete
WP_CLI::log( wp_json_encode( $named_args ) );
[1420] Fix | Delete
[1421] Fix | Delete
if ( $is_connection_owner ) {
[1422] Fix | Delete
/**
[1423] Fix | Delete
* Auto-enable SSO module for new Jetpack Start connections
[1424] Fix | Delete
*
[1425] Fix | Delete
* @since 5.0.0
[1426] Fix | Delete
*
[1427] Fix | Delete
* @param bool $enable_sso Whether to enable the SSO module. Default to true.
[1428] Fix | Delete
*/
[1429] Fix | Delete
$enable_sso = apply_filters( 'jetpack_start_enable_sso', true );
[1430] Fix | Delete
Jetpack::handle_post_authorization_actions( $enable_sso, false );
[1431] Fix | Delete
[1432] Fix | Delete
/* translators: %d is a user ID */
[1433] Fix | Delete
WP_CLI::success( sprintf( __( 'Authorized %d and activated default modules.', 'jetpack' ), $current_user_id ) );
[1434] Fix | Delete
} else {
[1435] Fix | Delete
/* translators: %d is a user ID */
[1436] Fix | Delete
WP_CLI::success( sprintf( __( 'Authorized %d.', 'jetpack' ), $current_user_id ) );
[1437] Fix | Delete
}
[1438] Fix | Delete
}
[1439] Fix | Delete
[1440] Fix | Delete
/**
[1441] Fix | Delete
* Allows calling a WordPress.com API endpoint using the current blog's token.
[1442] Fix | Delete
*
[1443] Fix | Delete
* ## OPTIONS
[1444] Fix | Delete
* --resource=<resource>
[1445] Fix | Delete
* : The resource to call with the current blog's token, where `%d` represents the current blog's ID.
[1446] Fix | Delete
*
[1447] Fix | Delete
* [--api_version=<api_version>]
[1448] Fix | Delete
* : The API version to query against.
[1449] Fix | Delete
*
[1450] Fix | Delete
* [--base_api_path=<base_api_path>]
[1451] Fix | Delete
* : The base API path to query.
[1452] Fix | Delete
* ---
[1453] Fix | Delete
* default: rest
[1454] Fix | Delete
* ---
[1455] Fix | Delete
*
[1456] Fix | Delete
* [--body=<body>]
[1457] Fix | Delete
* : A JSON encoded string representing arguments to send in the body.
[1458] Fix | Delete
*
[1459] Fix | Delete
* [--field=<value>]
[1460] Fix | Delete
* : Any number of arguments that should be passed to the resource.
[1461] Fix | Delete
*
[1462] Fix | Delete
* [--pretty]
[1463] Fix | Delete
* : Will pretty print the results of a successful API call.
[1464] Fix | Delete
*
[1465] Fix | Delete
* [--strip-success]
[1466] Fix | Delete
* : Will remove the green success label from successful API calls.
[1467] Fix | Delete
*
[1468] Fix | Delete
* ## EXAMPLES
[1469] Fix | Delete
*
[1470] Fix | Delete
* wp jetpack call_api --resource='/sites/%d'
[1471] Fix | Delete
*
[1472] Fix | Delete
* @param array $args Positional args.
[1473] Fix | Delete
* @param array $named_args Named args.
[1474] Fix | Delete
*/
[1475] Fix | Delete
public function call_api( $args, $named_args ) {
[1476] Fix | Delete
if ( ! Jetpack::is_connection_ready() ) {
[1477] Fix | Delete
WP_CLI::error( __( 'Jetpack is not currently connected to WordPress.com', 'jetpack' ) );
[1478] Fix | Delete
}
[1479] Fix | Delete
[1480] Fix | Delete
$consumed_args = array(
[1481] Fix | Delete
'resource',
[1482] Fix | Delete
'api_version',
[1483] Fix | Delete
'base_api_path',
[1484] Fix | Delete
'body',
[1485] Fix | Delete
'pretty',
[1486] Fix | Delete
);
[1487] Fix | Delete
[1488] Fix | Delete
// Get args that should be passed to resource.
[1489] Fix | Delete
$other_args = array_diff_key( $named_args, array_flip( $consumed_args ) );
[1490] Fix | Delete
[1491] Fix | Delete
$decoded_body = ! empty( $named_args['body'] )
[1492] Fix | Delete
? json_decode( $named_args['body'], true )
[1493] Fix | Delete
: false;
[1494] Fix | Delete
[1495] Fix | Delete
$resource_url = ( ! str_contains( $named_args['resource'], '%d' ) )
[1496] Fix | Delete
? $named_args['resource']
[1497] Fix | Delete
: sprintf( $named_args['resource'], Jetpack_Options::get_option( 'id' ) );
[1498] Fix | Delete
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function