Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack
File: class.jetpack-cli.php
);
[500] Fix | Delete
}
[501] Fix | Delete
[502] Fix | Delete
/**
[503] Fix | Delete
* Manage Jetpack Modules
[504] Fix | Delete
*
[505] Fix | Delete
* ## OPTIONS
[506] Fix | Delete
*
[507] Fix | Delete
* <list|activate|deactivate|toggle>
[508] Fix | Delete
* : The action to take.
[509] Fix | Delete
* ---
[510] Fix | Delete
* default: list
[511] Fix | Delete
* options:
[512] Fix | Delete
* - list
[513] Fix | Delete
* - activate
[514] Fix | Delete
* - deactivate
[515] Fix | Delete
* - toggle
[516] Fix | Delete
* ---
[517] Fix | Delete
*
[518] Fix | Delete
* [<module_slug>]
[519] Fix | Delete
* : The slug of the module to perform an action on.
[520] Fix | Delete
*
[521] Fix | Delete
* [--format=<format>]
[522] Fix | Delete
* : Allows overriding the output of the command when listing modules.
[523] Fix | Delete
* ---
[524] Fix | Delete
* default: table
[525] Fix | Delete
* options:
[526] Fix | Delete
* - table
[527] Fix | Delete
* - json
[528] Fix | Delete
* - csv
[529] Fix | Delete
* - yaml
[530] Fix | Delete
* - ids
[531] Fix | Delete
* - count
[532] Fix | Delete
* ---
[533] Fix | Delete
*
[534] Fix | Delete
* ## EXAMPLES
[535] Fix | Delete
*
[536] Fix | Delete
* wp jetpack module list
[537] Fix | Delete
* wp jetpack module list --format=json
[538] Fix | Delete
* wp jetpack module activate stats
[539] Fix | Delete
* wp jetpack module deactivate stats
[540] Fix | Delete
* wp jetpack module toggle stats
[541] Fix | Delete
* wp jetpack module activate all
[542] Fix | Delete
* wp jetpack module deactivate all
[543] Fix | Delete
*
[544] Fix | Delete
* @param array $args Positional args.
[545] Fix | Delete
* @param array $assoc_args Named args.
[546] Fix | Delete
*/
[547] Fix | Delete
public function module( $args, $assoc_args ) {
[548] Fix | Delete
$module_slug = null;
[549] Fix | Delete
$action = isset( $args[0] ) ? $args[0] : 'list';
[550] Fix | Delete
[551] Fix | Delete
if ( isset( $args[1] ) ) {
[552] Fix | Delete
$module_slug = $args[1];
[553] Fix | Delete
if ( 'all' !== $module_slug && ! Jetpack::is_module( $module_slug ) ) {
[554] Fix | Delete
/* translators: %s is a module slug like "stats" */
[555] Fix | Delete
WP_CLI::error( sprintf( __( '%s is not a valid module.', 'jetpack' ), $module_slug ) );
[556] Fix | Delete
}
[557] Fix | Delete
if ( 'toggle' === $action ) {
[558] Fix | Delete
$action = Jetpack::is_module_active( $module_slug )
[559] Fix | Delete
? 'deactivate'
[560] Fix | Delete
: 'activate';
[561] Fix | Delete
}
[562] Fix | Delete
if ( 'all' === $args[1] ) {
[563] Fix | Delete
$action = ( 'deactivate' === $action )
[564] Fix | Delete
? 'deactivate_all'
[565] Fix | Delete
: 'activate_all';
[566] Fix | Delete
}
[567] Fix | Delete
} elseif ( 'list' !== $action ) {
[568] Fix | Delete
WP_CLI::line( __( 'Please specify a valid module.', 'jetpack' ) );
[569] Fix | Delete
$action = 'list';
[570] Fix | Delete
}
[571] Fix | Delete
[572] Fix | Delete
switch ( $action ) {
[573] Fix | Delete
case 'list':
[574] Fix | Delete
$modules_list = array();
[575] Fix | Delete
$modules = Jetpack::get_available_modules();
[576] Fix | Delete
sort( $modules );
[577] Fix | Delete
foreach ( (array) $modules as $module_slug ) {
[578] Fix | Delete
if ( 'vaultpress' === $module_slug ) {
[579] Fix | Delete
continue;
[580] Fix | Delete
}
[581] Fix | Delete
$modules_list[] = array(
[582] Fix | Delete
'slug' => $module_slug,
[583] Fix | Delete
'status' => Jetpack::is_module_active( $module_slug )
[584] Fix | Delete
? __( 'Active', 'jetpack' )
[585] Fix | Delete
: __( 'Inactive', 'jetpack' ),
[586] Fix | Delete
);
[587] Fix | Delete
}
[588] Fix | Delete
WP_CLI\Utils\format_items( $assoc_args['format'], $modules_list, array( 'slug', 'status' ) );
[589] Fix | Delete
break;
[590] Fix | Delete
case 'activate':
[591] Fix | Delete
$module = Jetpack::get_module( $module_slug );
[592] Fix | Delete
Jetpack::log( 'activate', $module_slug );
[593] Fix | Delete
if ( Jetpack::activate_module( $module_slug, false, false ) ) {
[594] Fix | Delete
/* translators: %s is the name of a Jetpack module */
[595] Fix | Delete
WP_CLI::success( sprintf( __( '%s has been activated.', 'jetpack' ), $module['name'] ) );
[596] Fix | Delete
} else {
[597] Fix | Delete
/* translators: %s is the name of a Jetpack module */
[598] Fix | Delete
WP_CLI::error( sprintf( __( '%s could not be activated.', 'jetpack' ), $module['name'] ) );
[599] Fix | Delete
}
[600] Fix | Delete
break;
[601] Fix | Delete
case 'activate_all':
[602] Fix | Delete
$modules = Jetpack::get_available_modules();
[603] Fix | Delete
Jetpack::update_active_modules( $modules );
[604] Fix | Delete
WP_CLI::success( __( 'All modules activated!', 'jetpack' ) );
[605] Fix | Delete
break;
[606] Fix | Delete
case 'deactivate':
[607] Fix | Delete
$module = Jetpack::get_module( $module_slug );
[608] Fix | Delete
Jetpack::log( 'deactivate', $module_slug );
[609] Fix | Delete
Jetpack::deactivate_module( $module_slug );
[610] Fix | Delete
/* translators: %s is the name of a Jetpack module */
[611] Fix | Delete
WP_CLI::success( sprintf( __( '%s has been deactivated.', 'jetpack' ), $module['name'] ) );
[612] Fix | Delete
break;
[613] Fix | Delete
case 'deactivate_all':
[614] Fix | Delete
Jetpack::delete_active_modules();
[615] Fix | Delete
WP_CLI::success( __( 'All modules deactivated!', 'jetpack' ) );
[616] Fix | Delete
break;
[617] Fix | Delete
case 'toggle':
[618] Fix | Delete
// Will never happen, should have been handled above and changed to activate or deactivate.
[619] Fix | Delete
break;
[620] Fix | Delete
}
[621] Fix | Delete
}
[622] Fix | Delete
[623] Fix | Delete
/**
[624] Fix | Delete
* Manage Protect Settings
[625] Fix | Delete
*
[626] Fix | Delete
* ## OPTIONS
[627] Fix | Delete
*
[628] Fix | Delete
* allow: Add an IP address to an always allow list. You can also read or clear the allow list.
[629] Fix | Delete
*
[630] Fix | Delete
*
[631] Fix | Delete
* ## EXAMPLES
[632] Fix | Delete
*
[633] Fix | Delete
* wp jetpack protect allow <ip address>
[634] Fix | Delete
* wp jetpack protect allow list
[635] Fix | Delete
* wp jetpack protect allow clear
[636] Fix | Delete
*
[637] Fix | Delete
* @synopsis <allow> [<ip|ip_low-ip_high|list|clear>]
[638] Fix | Delete
*
[639] Fix | Delete
* @param array $args Positional args.
[640] Fix | Delete
*/
[641] Fix | Delete
public function protect( $args ) {
[642] Fix | Delete
$action = isset( $args[0] ) ? $args[0] : 'prompt';
[643] Fix | Delete
if ( ! in_array( $action, array( 'whitelist', 'allow' ), true ) ) { // Still allow "whitelist" for legacy support.
[644] Fix | Delete
/* translators: %s is a command like "prompt" */
[645] Fix | Delete
WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) );
[646] Fix | Delete
}
[647] Fix | Delete
// Check if module is active.
[648] Fix | Delete
if ( ! Jetpack::is_module_active( __FUNCTION__ ) ) {
[649] Fix | Delete
/* translators: %s is a module name */
[650] Fix | Delete
WP_CLI::error( sprintf( _x( '%1$s is not active. You can activate it with "wp jetpack module activate %2$s"', '"wp jetpack module activate" is a command - do not translate', 'jetpack' ), __FUNCTION__, __FUNCTION__ ) );
[651] Fix | Delete
}
[652] Fix | Delete
if ( in_array( $action, array( 'allow', 'whitelist' ), true ) ) {
[653] Fix | Delete
if ( isset( $args[1] ) ) {
[654] Fix | Delete
$action = 'allow';
[655] Fix | Delete
} else {
[656] Fix | Delete
$action = 'prompt';
[657] Fix | Delete
}
[658] Fix | Delete
}
[659] Fix | Delete
switch ( $action ) {
[660] Fix | Delete
case 'allow':
[661] Fix | Delete
$allow = array();
[662] Fix | Delete
$new_ip = $args[1];
[663] Fix | Delete
$current_allow = get_site_option( 'jetpack_protect_whitelist', array() ); // @todo Update the option name.
[664] Fix | Delete
[665] Fix | Delete
// Build array of IPs that are already on the allowed list.
[666] Fix | Delete
// Re-build manually instead of using jetpack_protect_format_allow_list() so we can easily get
[667] Fix | Delete
// low & high range params for IP_Utils::ip_address_is_in_range().
[668] Fix | Delete
foreach ( $current_allow as $allowed ) {
[669] Fix | Delete
[670] Fix | Delete
// IP ranges.
[671] Fix | Delete
if ( $allowed->range ) {
[672] Fix | Delete
[673] Fix | Delete
// Is it already on the allowed list?
[674] Fix | Delete
if ( IP_Utils::ip_address_is_in_range( $new_ip, $allowed->range_low, $allowed->range_high ) ) {
[675] Fix | Delete
/* translators: %s is an IP address */
[676] Fix | Delete
WP_CLI::error( sprintf( __( '%s is already on the always allow list.', 'jetpack' ), $new_ip ) );
[677] Fix | Delete
break;
[678] Fix | Delete
}
[679] Fix | Delete
$allow[] = $allowed->range_low . ' - ' . $allowed->range_high;
[680] Fix | Delete
[681] Fix | Delete
} else { // Individual IPs.
[682] Fix | Delete
[683] Fix | Delete
// Check if the IP is already on the allow list (single IP only).
[684] Fix | Delete
if ( $new_ip === $allowed->ip_address ) {
[685] Fix | Delete
/* translators: %s is an IP address */
[686] Fix | Delete
WP_CLI::error( sprintf( __( '%s is already on the always allow list.', 'jetpack' ), $new_ip ) );
[687] Fix | Delete
break;
[688] Fix | Delete
}
[689] Fix | Delete
$allow[] = $allowed->ip_address;
[690] Fix | Delete
[691] Fix | Delete
}
[692] Fix | Delete
}
[693] Fix | Delete
[694] Fix | Delete
/*
[695] Fix | Delete
* List the allowed IPs.
[696] Fix | Delete
* Done here because it's easier to read the $allow array after it's been rebuilt.
[697] Fix | Delete
*/
[698] Fix | Delete
if ( isset( $args[1] ) && 'list' === $args[1] ) {
[699] Fix | Delete
if ( ! empty( $allow ) ) {
[700] Fix | Delete
WP_CLI::success( __( 'Here are your always allowed IPs:', 'jetpack' ) );
[701] Fix | Delete
foreach ( $allow as $ip ) {
[702] Fix | Delete
WP_CLI::line( "\t" . str_pad( $ip, 24 ) );
[703] Fix | Delete
}
[704] Fix | Delete
} else {
[705] Fix | Delete
WP_CLI::line( __( 'Always allow list is empty.', 'jetpack' ) );
[706] Fix | Delete
}
[707] Fix | Delete
break;
[708] Fix | Delete
}
[709] Fix | Delete
[710] Fix | Delete
/*
[711] Fix | Delete
* Clear the always allow list.
[712] Fix | Delete
*/
[713] Fix | Delete
if ( isset( $args[1] ) && 'clear' === $args[1] ) {
[714] Fix | Delete
if ( ! empty( $allow ) ) {
[715] Fix | Delete
$allow = array();
[716] Fix | Delete
Brute_Force_Protection_Shared_Functions::save_allow_list( $allow ); // @todo Need to update function name in the Protect module.
[717] Fix | Delete
WP_CLI::success( __( 'Cleared all IPs from the always allow list.', 'jetpack' ) );
[718] Fix | Delete
} else {
[719] Fix | Delete
WP_CLI::line( __( 'Always allow list is empty.', 'jetpack' ) );
[720] Fix | Delete
}
[721] Fix | Delete
break;
[722] Fix | Delete
}
[723] Fix | Delete
[724] Fix | Delete
// Append new IP to allow array.
[725] Fix | Delete
array_push( $allow, $new_ip );
[726] Fix | Delete
[727] Fix | Delete
// Save allow list if there are no errors.
[728] Fix | Delete
$result = Brute_Force_Protection_Shared_Functions::save_allow_list( $allow ); // @todo Need to update function name in the Protect module.
[729] Fix | Delete
if ( is_wp_error( $result ) ) {
[730] Fix | Delete
WP_CLI::error( $result );
[731] Fix | Delete
}
[732] Fix | Delete
[733] Fix | Delete
/* translators: %s is an IP address */
[734] Fix | Delete
WP_CLI::success( sprintf( __( '%s has been added to the always allowed list.', 'jetpack' ), $new_ip ) );
[735] Fix | Delete
break;
[736] Fix | Delete
case 'prompt':
[737] Fix | Delete
WP_CLI::error(
[738] Fix | Delete
__( 'No command found.', 'jetpack' ) . "\n" .
[739] Fix | Delete
__( 'Please enter the IP address you want to always allow.', 'jetpack' ) . "\n" .
[740] Fix | Delete
_x( 'You can save a range of IPs {low_range}-{high_range}. No spaces allowed. (example: 1.1.1.1-2.2.2.2)', 'Instructions on how to add IP ranges - low_range/high_range should be translated.', 'jetpack' ) . "\n" .
[741] Fix | Delete
_x( "You can also 'list' or 'clear' the always allowed list.", "'list' and 'clear' are commands and should not be translated", 'jetpack' ) . "\n"
[742] Fix | Delete
);
[743] Fix | Delete
break;
[744] Fix | Delete
}
[745] Fix | Delete
}
[746] Fix | Delete
[747] Fix | Delete
/**
[748] Fix | Delete
* Manage Jetpack Options
[749] Fix | Delete
*
[750] Fix | Delete
* ## OPTIONS
[751] Fix | Delete
*
[752] Fix | Delete
* list : List all jetpack options and their values
[753] Fix | Delete
* delete : Delete an option
[754] Fix | Delete
* - can only delete options that are white listed.
[755] Fix | Delete
* update : update an option
[756] Fix | Delete
* - can only update option strings
[757] Fix | Delete
* get : get the value of an option
[758] Fix | Delete
*
[759] Fix | Delete
* ## EXAMPLES
[760] Fix | Delete
*
[761] Fix | Delete
* wp jetpack options list
[762] Fix | Delete
* wp jetpack options get <option_name>
[763] Fix | Delete
* wp jetpack options delete <option_name>
[764] Fix | Delete
* wp jetpack options update <option_name> [<option_value>]
[765] Fix | Delete
*
[766] Fix | Delete
* @synopsis <list|get|delete|update> [<option_name>] [<option_value>]
[767] Fix | Delete
*
[768] Fix | Delete
* @param array $args Positional args.
[769] Fix | Delete
*/
[770] Fix | Delete
public function options( $args ) {
[771] Fix | Delete
$action = isset( $args[0] ) ? $args[0] : 'list';
[772] Fix | Delete
$safe_to_modify = Jetpack_Options::get_options_for_reset();
[773] Fix | Delete
[774] Fix | Delete
// Is the option flagged as unsafe?
[775] Fix | Delete
$flagged = ! in_array( $args[1], $safe_to_modify, true );
[776] Fix | Delete
[777] Fix | Delete
if ( ! in_array( $action, array( 'list', 'get', 'delete', 'update' ), true ) ) {
[778] Fix | Delete
/* translators: %s is a command like "prompt" */
[779] Fix | Delete
WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack' ), $action ) );
[780] Fix | Delete
}
[781] Fix | Delete
[782] Fix | Delete
if ( isset( $args[0] ) ) {
[783] Fix | Delete
if ( 'get' === $args[0] && isset( $args[1] ) ) {
[784] Fix | Delete
$action = 'get';
[785] Fix | Delete
} elseif ( 'delete' === $args[0] && isset( $args[1] ) ) {
[786] Fix | Delete
$action = 'delete';
[787] Fix | Delete
} elseif ( 'update' === $args[0] && isset( $args[1] ) ) {
[788] Fix | Delete
$action = 'update';
[789] Fix | Delete
} else {
[790] Fix | Delete
$action = 'list';
[791] Fix | Delete
}
[792] Fix | Delete
}
[793] Fix | Delete
[794] Fix | Delete
// Bail if the option isn't found.
[795] Fix | Delete
$option = isset( $args[1] ) ? Jetpack_Options::get_option( $args[1] ) : false;
[796] Fix | Delete
if ( isset( $args[1] ) && ! $option && 'update' !== $args[0] ) {
[797] Fix | Delete
WP_CLI::error( __( 'Option not found or is empty. Use "list" to list option names', 'jetpack' ) );
[798] Fix | Delete
}
[799] Fix | Delete
[800] Fix | Delete
// Let's print_r the option if it's an array.
[801] Fix | Delete
// Used in the 'get' and 'list' actions.
[802] Fix | Delete
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
[803] Fix | Delete
$option = is_array( $option ) ? print_r( $option, true ) : $option;
[804] Fix | Delete
[805] Fix | Delete
switch ( $action ) {
[806] Fix | Delete
case 'get':
[807] Fix | Delete
WP_CLI::success( "\t" . $option );
[808] Fix | Delete
break;
[809] Fix | Delete
case 'delete':
[810] Fix | Delete
jetpack_cli_are_you_sure( $flagged );
[811] Fix | Delete
[812] Fix | Delete
Jetpack_Options::delete_option( $args[1] );
[813] Fix | Delete
/* translators: %s is the option name */
[814] Fix | Delete
WP_CLI::success( sprintf( __( 'Deleted option: %s', 'jetpack' ), $args[1] ) );
[815] Fix | Delete
break;
[816] Fix | Delete
case 'update':
[817] Fix | Delete
jetpack_cli_are_you_sure( $flagged );
[818] Fix | Delete
[819] Fix | Delete
// Updating arrays would get pretty tricky...
[820] Fix | Delete
$value = Jetpack_Options::get_option( $args[1] );
[821] Fix | Delete
if ( $value && is_array( $value ) ) {
[822] Fix | Delete
WP_CLI::error( __( 'Sorry, no updating arrays at this time', 'jetpack' ) );
[823] Fix | Delete
}
[824] Fix | Delete
[825] Fix | Delete
Jetpack_Options::update_option( $args[1], $args[2] );
[826] Fix | Delete
/* translators: %1$s is the previous value, %2$s is the new value */
[827] Fix | Delete
WP_CLI::success( sprintf( _x( 'Updated option: %1$s to "%2$s"', 'Updating an option from "this" to "that".', 'jetpack' ), $args[1], $args[2] ) );
[828] Fix | Delete
break;
[829] Fix | Delete
case 'list':
[830] Fix | Delete
$options_compact = Jetpack_Options::get_option_names();
[831] Fix | Delete
$options_non_compact = Jetpack_Options::get_option_names( 'non_compact' );
[832] Fix | Delete
$options_private = Jetpack_Options::get_option_names( 'private' );
[833] Fix | Delete
$options = array_merge( $options_compact, $options_non_compact, $options_private );
[834] Fix | Delete
[835] Fix | Delete
// Table headers.
[836] Fix | Delete
WP_CLI::line( "\t" . str_pad( __( 'Option', 'jetpack' ), 30 ) . __( 'Value', 'jetpack' ) );
[837] Fix | Delete
[838] Fix | Delete
// List out the options and their values.
[839] Fix | Delete
// Tell them if the value is empty or not.
[840] Fix | Delete
// Tell them if it's an array.
[841] Fix | Delete
foreach ( $options as $option ) {
[842] Fix | Delete
$value = Jetpack_Options::get_option( $option );
[843] Fix | Delete
if ( ! $value ) {
[844] Fix | Delete
WP_CLI::line( "\t" . str_pad( $option, 30 ) . 'Empty' );
[845] Fix | Delete
continue;
[846] Fix | Delete
}
[847] Fix | Delete
[848] Fix | Delete
if ( ! is_array( $value ) ) {
[849] Fix | Delete
WP_CLI::line( "\t" . str_pad( $option, 30 ) . $value );
[850] Fix | Delete
} elseif ( is_array( $value ) ) {
[851] Fix | Delete
WP_CLI::line( "\t" . str_pad( $option, 30 ) . 'Array - Use "get <option>" to read option array.' );
[852] Fix | Delete
}
[853] Fix | Delete
}
[854] Fix | Delete
$option_text = '{' . _x( 'option', 'a variable command that a user can write, provided in the printed instructions', 'jetpack' ) . '}';
[855] Fix | Delete
$value_text = '{' . _x( 'value', 'the value that they want to update the option to', 'jetpack' ) . '}';
[856] Fix | Delete
[857] Fix | Delete
WP_CLI::success(
[858] Fix | Delete
_x( "Above are your options. You may 'get', 'delete', and 'update' them.", "'get', 'delete', and 'update' are commands - do not translate.", 'jetpack' ) . "\n" .
[859] Fix | Delete
str_pad( 'wp jetpack options get', 26 ) . $option_text . "\n" .
[860] Fix | Delete
str_pad( 'wp jetpack options delete', 26 ) . $option_text . "\n" .
[861] Fix | Delete
str_pad( 'wp jetpack options update', 26 ) . "$option_text $value_text\n" .
[862] Fix | Delete
_x( "Type 'wp jetpack options' for more info.", "'wp jetpack options' is a command - do not translate.", 'jetpack' ) . "\n"
[863] Fix | Delete
);
[864] Fix | Delete
break;
[865] Fix | Delete
}
[866] Fix | Delete
}
[867] Fix | Delete
[868] Fix | Delete
/**
[869] Fix | Delete
* Get the status of or start a new Jetpack sync.
[870] Fix | Delete
*
[871] Fix | Delete
* ## OPTIONS
[872] Fix | Delete
*
[873] Fix | Delete
* status : Print the current sync status
[874] Fix | Delete
* settings : Prints the current sync settings
[875] Fix | Delete
* start : Start a full sync from this site to WordPress.com
[876] Fix | Delete
* enable : Enables sync on the site
[877] Fix | Delete
* disable : Disable sync on a site
[878] Fix | Delete
* reset : Disables sync and Resets the sync queues on a site
[879] Fix | Delete
*
[880] Fix | Delete
* ## EXAMPLES
[881] Fix | Delete
*
[882] Fix | Delete
* wp jetpack sync status
[883] Fix | Delete
* wp jetpack sync settings
[884] Fix | Delete
* wp jetpack sync start --modules=functions --sync_wait_time=5
[885] Fix | Delete
* wp jetpack sync enable
[886] Fix | Delete
* wp jetpack sync disable
[887] Fix | Delete
* wp jetpack sync reset
[888] Fix | Delete
* wp jetpack sync reset --queue=full or regular
[889] Fix | Delete
*
[890] Fix | Delete
* @synopsis <status|start> [--<field>=<value>]
[891] Fix | Delete
*
[892] Fix | Delete
* @param array $args Positional args.
[893] Fix | Delete
* @param array $assoc_args Named args.
[894] Fix | Delete
*/
[895] Fix | Delete
public function sync( $args, $assoc_args ) {
[896] Fix | Delete
[897] Fix | Delete
$action = isset( $args[0] ) ? $args[0] : 'status';
[898] Fix | Delete
[899] Fix | Delete
switch ( $action ) {
[900] Fix | Delete
case 'status':
[901] Fix | Delete
$status = Actions::get_sync_status();
[902] Fix | Delete
$collection = array();
[903] Fix | Delete
foreach ( $status as $key => $item ) {
[904] Fix | Delete
$collection[] = array(
[905] Fix | Delete
'option' => $key,
[906] Fix | Delete
'value' => is_scalar( $item ) ? $item : wp_json_encode( $item ),
[907] Fix | Delete
);
[908] Fix | Delete
}
[909] Fix | Delete
WP_CLI::log( __( 'Sync Status:', 'jetpack' ) );
[910] Fix | Delete
WP_CLI\Utils\format_items( 'table', $collection, array( 'option', 'value' ) );
[911] Fix | Delete
break;
[912] Fix | Delete
case 'settings':
[913] Fix | Delete
WP_CLI::log( __( 'Sync Settings:', 'jetpack' ) );
[914] Fix | Delete
$settings = array();
[915] Fix | Delete
foreach ( Settings::get_settings() as $setting => $item ) {
[916] Fix | Delete
$settings[] = array(
[917] Fix | Delete
'setting' => $setting,
[918] Fix | Delete
'value' => is_scalar( $item ) ? $item : wp_json_encode( $item ),
[919] Fix | Delete
);
[920] Fix | Delete
}
[921] Fix | Delete
WP_CLI\Utils\format_items( 'table', $settings, array( 'setting', 'value' ) );
[922] Fix | Delete
break;
[923] Fix | Delete
case 'disable':
[924] Fix | Delete
// Don't set it via the Settings since that also resets the queues.
[925] Fix | Delete
update_option( 'jetpack_sync_settings_disable', 1 );
[926] Fix | Delete
/* translators: %s is the site URL */
[927] Fix | Delete
WP_CLI::log( sprintf( __( 'Sync Disabled on %s', 'jetpack' ), get_site_url() ) );
[928] Fix | Delete
break;
[929] Fix | Delete
case 'enable':
[930] Fix | Delete
Settings::update_settings( array( 'disable' => 0 ) );
[931] Fix | Delete
/* translators: %s is the site URL */
[932] Fix | Delete
WP_CLI::log( sprintf( __( 'Sync Enabled on %s', 'jetpack' ), get_site_url() ) );
[933] Fix | Delete
break;
[934] Fix | Delete
case 'reset':
[935] Fix | Delete
// Don't set it via the Settings since that also resets the queues.
[936] Fix | Delete
update_option( 'jetpack_sync_settings_disable', 1 );
[937] Fix | Delete
[938] Fix | Delete
/* translators: %s is the site URL */
[939] Fix | Delete
WP_CLI::log( sprintf( __( 'Sync Disabled on %s. Use `wp jetpack sync enable` to enable syncing again.', 'jetpack' ), get_site_url() ) );
[940] Fix | Delete
$listener = Listener::get_instance();
[941] Fix | Delete
if ( empty( $assoc_args['queue'] ) ) {
[942] Fix | Delete
$listener->get_sync_queue()->reset();
[943] Fix | Delete
$listener->get_full_sync_queue()->reset();
[944] Fix | Delete
/* translators: %s is the site URL */
[945] Fix | Delete
WP_CLI::log( sprintf( __( 'Reset Full Sync and Regular Queues Queue on %s', 'jetpack' ), get_site_url() ) );
[946] Fix | Delete
break;
[947] Fix | Delete
}
[948] Fix | Delete
[949] Fix | Delete
if ( ! empty( $assoc_args['queue'] ) ) {
[950] Fix | Delete
switch ( $assoc_args['queue'] ) {
[951] Fix | Delete
case 'regular':
[952] Fix | Delete
$listener->get_sync_queue()->reset();
[953] Fix | Delete
/* translators: %s is the site URL */
[954] Fix | Delete
WP_CLI::log( sprintf( __( 'Reset Regular Sync Queue on %s', 'jetpack' ), get_site_url() ) );
[955] Fix | Delete
break;
[956] Fix | Delete
case 'full':
[957] Fix | Delete
$listener->get_full_sync_queue()->reset();
[958] Fix | Delete
/* translators: %s is the site URL */
[959] Fix | Delete
WP_CLI::log( sprintf( __( 'Reset Full Sync Queue on %s', 'jetpack' ), get_site_url() ) );
[960] Fix | Delete
break;
[961] Fix | Delete
default:
[962] Fix | Delete
WP_CLI::error( __( 'Please specify what type of queue do you want to reset: `full` or `regular`.', 'jetpack' ) );
[963] Fix | Delete
break;
[964] Fix | Delete
}
[965] Fix | Delete
}
[966] Fix | Delete
[967] Fix | Delete
break;
[968] Fix | Delete
case 'start':
[969] Fix | Delete
if ( ! Actions::sync_allowed() ) {
[970] Fix | Delete
if ( Settings::get_setting( 'disable' ) ) {
[971] Fix | Delete
WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. It is currently disabled. Run `wp jetpack sync enable` to enable it.', 'jetpack' ) );
[972] Fix | Delete
return;
[973] Fix | Delete
}
[974] Fix | Delete
$connection = new Connection_Manager();
[975] Fix | Delete
if ( ! $connection->is_connected() ) {
[976] Fix | Delete
if ( ! doing_action( 'jetpack_site_registered' ) ) {
[977] Fix | Delete
WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. Jetpack is not connected.', 'jetpack' ) );
[978] Fix | Delete
return;
[979] Fix | Delete
}
[980] Fix | Delete
}
[981] Fix | Delete
[982] Fix | Delete
$status = new Status();
[983] Fix | Delete
[984] Fix | Delete
if ( $status->is_offline_mode() ) {
[985] Fix | Delete
WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. The site is in offline mode.', 'jetpack' ) );
[986] Fix | Delete
return;
[987] Fix | Delete
}
[988] Fix | Delete
if ( $status->in_safe_mode() ) {
[989] Fix | Delete
WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. The site is in safe mode.', 'jetpack' ) );
[990] Fix | Delete
return;
[991] Fix | Delete
}
[992] Fix | Delete
}
[993] Fix | Delete
// Get the original settings so that we can restore them later.
[994] Fix | Delete
$original_settings = Settings::get_settings();
[995] Fix | Delete
[996] Fix | Delete
// Initialize sync settigns so we can sync as quickly as possible.
[997] Fix | Delete
$sync_settings = wp_parse_args(
[998] Fix | Delete
array_intersect_key( $assoc_args, Settings::$valid_settings ),
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function