PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 14.9
Jetpack – WP Security, Backup, Speed, & Growth v14.9
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
← All changes | class.jetpack-cli.php +46 -56 13.3.314.9 View file →
@@ -9,8 +9,10 @@
9 9 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
10 10 use Automattic\Jetpack\Connection\Tokens;
11 11 use Automattic\Jetpack\Identity_Crisis;
12 12 use Automattic\Jetpack\IP\Utils as IP_Utils;
13 +use Automattic\Jetpack\Publicize\Connections;
14 +use Automattic\Jetpack\Publicize\Publicize;
13 15 use Automattic\Jetpack\Status;
14 16 use Automattic\Jetpack\Sync\Actions;
15 17 use Automattic\Jetpack\Sync\Listener;
16 18 use Automattic\Jetpack\Sync\Modules;
@@ -21,8 +23,9 @@
21 23 if ( ! class_exists( 'WP_CLI_Command' ) ) {
22 24 return;
23 25 }
24 26
27 +// @phan-suppress-next-line PhanUndeclaredFunctionInCallable -- https://github.com/phan/phan/issues/4763
25 28 WP_CLI::add_command( 'jetpack', 'Jetpack_CLI' );
26 29
27 30 /**
28 31 * Control your local Jetpack installation.
@@ -983,10 +986,10 @@
983 986 if ( $status->is_offline_mode() ) {
984 987 WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. The site is in offline mode.', 'jetpack' ) );
985 988 return;
986 989 }
987 - if ( $status->is_staging_site() ) {
988 - WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. The site is in staging mode.', 'jetpack' ) );
990 + if ( $status->in_safe_mode() ) {
991 + WP_CLI::error( __( 'Jetpack sync is not currently allowed for this site. The site is in safe mode.', 'jetpack' ) );
989 992 return;
990 993 }
991 994 }
992 995 // Get the original settings so that we can restore them later.
@@ -1033,9 +1036,9 @@
1033 1036 $modules = null;
1034 1037 }
1035 1038
1036 1039 // Kick off a full sync.
1037 - if ( Actions::do_full_sync( $modules ) ) {
1040 + if ( Actions::do_full_sync( $modules, 'jetpack_cli' ) ) {
1038 1041 if ( $modules ) {
1039 1042 /* translators: %s is a comma separated list of Jetpack modules */
1040 1043 WP_CLI::log( sprintf( __( 'Initialized a new full sync with modules: %s', 'jetpack' ), implode( ', ', array_keys( $modules ) ) ) );
1041 1044 } else {
@@ -1071,9 +1074,9 @@
1071 1074 WP_CLI::log( __( 'Sent more data to WordPress.com', 'jetpack' ) );
1072 1075 }
1073 1076
1074 1077 // Immediate Full Sync does not wait for WP.com to process data so we need to enforce a wait.
1075 - if ( str_contains( get_class( Modules::get_module( 'full-sync' ) ), 'Full_Sync_Immediately' ) ) {
1078 + if ( Modules::get_module( 'full-sync' ) instanceof \Automattic\Jetpack\Sync\Modules\Full_Sync_Immediately ) {
1076 1079 sleep( 15 );
1077 1080 }
1078 1081 }
1079 1082 ++$i;
@@ -1217,10 +1220,8 @@
1217 1220 }
1218 1221
1219 1222 $result = Client::_wp_remote_request( $url, $request );
1220 1223
1221 - Jetpack_Options::delete_option( 'onboarding' );
1222 -
1223 1224 if ( is_wp_error( $result ) ) {
1224 1225 $this->partner_provision_error( $result );
1225 1226 }
1226 1227
@@ -1241,10 +1242,8 @@
1241 1242 * [--wpcom_user_id=<user_id>]
1242 1243 * : WordPress.com ID of user to connect as (must be whitelisted against partner key)
1243 1244 * [--wpcom_user_email=<wpcom_user_email>]
1244 1245 * : Override the email we send to WordPress.com for registration
1245 - * [--onboarding=<onboarding>]
1246 - * : Guide the user through an onboarding wizard
1247 1246 * [--force_register=<register>]
1248 1247 * : Whether to force a site to register
1249 1248 * [--force_connect=<force_connect>]
1250 1249 * : Force JPS to not reuse existing credentials
@@ -1259,9 +1258,9 @@
1259 1258 *
1260 1259 * $ wp jetpack partner_provision '{ some: "json" }' premium 1
1261 1260 * { success: true }
1262 1261 *
1263 - * @synopsis <token_json> [--wpcom_user_id=<user_id>] [--plan=<plan_name>] [--onboarding=<onboarding>] [--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>]
1262 + * @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>]
1264 1263 *
1265 1264 * @param array $args Positional args.
1266 1265 * @param array $named_args Named args.
1267 1266 */
@@ -1323,11 +1322,8 @@
1323 1322 * @param array $args Positional args.
1324 1323 * @param array $assoc_args Named args.
1325 1324 */
1326 1325 public function sitemap( $args, $assoc_args ) {
1327 - if ( ! Jetpack::is_connection_ready() ) {
1328 - WP_CLI::error( __( 'Jetpack is not currently connected to WordPress.com', 'jetpack' ) );
1329 - }
1330 1326 if ( ! Jetpack::is_module_active( 'sitemaps' ) ) {
1331 1327 WP_CLI::error( __( 'Jetpack Sitemaps module is not currently active. Activate it first if you want to work with sitemaps.', 'jetpack' ) );
1332 1328 }
1333 1329 if ( ! class_exists( 'Jetpack_Sitemap_Builder' ) ) {
@@ -1336,8 +1332,13 @@
1336 1332
1337 1333 if ( isset( $assoc_args['purge'] ) && $assoc_args['purge'] ) {
1338 1334 $librarian = new Jetpack_Sitemap_Librarian();
1339 1335 $librarian->delete_all_stored_sitemap_data();
1336 +
1337 + // Clear sitemap-related transients
1338 + delete_transient( 'jetpack_news_sitemap_xml' );
1339 + delete_transient( 'jetpack-sitemap-state-lock' );
1340 + WP_CLI::success( 'Purged all sitemap data and cleared sitemap transients.' );
1340 1341 }
1341 1342
1342 1343 $sitemap_builder = new Jetpack_Sitemap_Builder();
1343 1344 $sitemap_builder->update_sitemap();
@@ -1670,8 +1671,11 @@
1670 1671 *
1671 1672 * [<identifier>]
1672 1673 * : The connection ID or service to perform an action on.
1673 1674 *
1675 + * [--ignore-cache]
1676 + * : Whether to ignore connections cache.
1677 + *
1674 1678 * [--format=<format>]
1675 1679 * : Allows overriding the output of the command when listing connections.
1676 1680 * ---
1677 1681 * default: table
@@ -1688,8 +1692,11 @@
1688 1692 *
1689 1693 * # List all publicize connections.
1690 1694 * $ wp jetpack publicize list
1691 1695 *
1696 + * # List all publicize connections, ignoring the cache.
1697 + * $ wp jetpack publicize list --ignore-cache
1698 + *
1692 1699 * # List publicize connections for a given service.
1693 1700 * $ wp jetpack publicize list linkedin
1694 1701 *
1695 1702 * # List all publicize connections for a given user.
@@ -1734,9 +1741,9 @@
1734 1741
1735 1742 WP_CLI::error( __( 'Jetpack is currently in offline mode, so the Jetpack Social module will not load.', 'jetpack' ) );
1736 1743 }
1737 1744
1738 - if ( ! class_exists( 'Publicize' ) ) {
1745 + if ( ! class_exists( Publicize::class ) ) {
1739 1746 WP_CLI::error( __( 'The Jetpack Social module is not loaded.', 'jetpack' ) );
1740 1747 }
1741 1748
1742 1749 $action = $args[0];
@@ -1746,30 +1753,23 @@
1746 1753 $id_is_service = in_array( $identifier, $services, true );
1747 1754
1748 1755 switch ( $action ) {
1749 1756 case 'list':
1750 - $connections_to_return = array();
1751 -
1757 + $_args = array(
1758 + 'ignore_cache' => $named_args['ignore-cache'] ?? false,
1759 + );
1752 1760 // For the CLI command, let's return all connections when a user isn't specified. This
1753 1761 // differs from the logic in the Publicize class.
1754 - $option_connections = is_user_logged_in()
1755 - ? (array) $publicize->get_all_connections_for_user()
1756 - : (array) $publicize->get_all_connections();
1762 + $connections_to_return = is_user_logged_in()
1763 + ? Connections::get_all_for_user( $_args )
1764 + : Connections::get_all( $_args );
1757 1765
1758 - foreach ( $option_connections as $service_name => $connections ) {
1759 - foreach ( (array) $connections as $id => $connection ) {
1760 - $connection['id'] = $id;
1761 - $connection['service'] = $service_name;
1762 - $connections_to_return[] = $connection;
1763 - }
1764 - }
1765 -
1766 1766 if ( $id_is_service && ! empty( $identifier ) && ! empty( $connections_to_return ) ) {
1767 1767 $temp_connections = $connections_to_return;
1768 1768 $connections_to_return = array();
1769 1769
1770 1770 foreach ( $temp_connections as $connection ) {
1771 - if ( $identifier === $connection['service'] ) {
1771 + if ( $identifier === $connection['service_name'] ) {
1772 1772 $connections_to_return[] = $connection;
1773 1773 }
1774 1774 }
1775 1775 }
@@ -1774,23 +1774,18 @@
1774 1774 }
1775 1775 }
1776 1776
1777 1777 if ( $identifier && ! $id_is_service && ! empty( $connections_to_return ) ) {
1778 - $connections_to_return = wp_list_filter( $connections_to_return, array( 'id' => $identifier ) );
1778 + $connections_to_return = wp_list_filter( $connections_to_return, array( 'connection_id' => $identifier ) );
1779 1779 }
1780 1780
1781 1781 $expected_keys = array(
1782 - 'id',
1783 - 'service',
1784 - 'user_id',
1785 - 'provider',
1786 - 'issued',
1787 - 'expires',
1782 + 'connection_id',
1783 + 'service_name',
1784 + 'display_name',
1788 1785 'external_id',
1789 - 'external_name',
1790 - 'external_display',
1791 - 'type',
1792 - 'connection_data',
1786 + 'wpcom_user_id',
1787 + 'shared',
1793 1788 );
1794 1789
1795 1790 // Somehow, a test site ended up in a state where $connections_to_return looked like:
1796 1791 // array( array( array( 'id' => 0, 'service' => 0 ) ) ) // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
@@ -1828,23 +1823,15 @@
1828 1823 }
1829 1824
1830 1825 jetpack_cli_are_you_sure();
1831 1826
1832 - $connections = array();
1833 1827 $service = $identifier;
1828 + $connections = is_user_logged_in()
1829 + ? Connections::get_all_for_user()
1830 + : Connections::get_all();
1834 1831
1835 - $option_connections = is_user_logged_in()
1836 - ? (array) $publicize->get_all_connections_for_user()
1837 - : (array) $publicize->get_all_connections();
1838 -
1839 - if ( 'all' === $service ) {
1840 - foreach ( (array) $option_connections as $service_name => $service_connections ) {
1841 - foreach ( $service_connections as $id => $connection ) {
1842 - $connections[ $id ] = $connection;
1843 - }
1844 - }
1845 - } elseif ( ! empty( $option_connections[ $service ] ) ) {
1846 - $connections = $option_connections[ $service ];
1832 + if ( 'all' !== $service ) {
1833 + $connections = wp_list_filter( $connections, array( 'service_name' => $service ) );
1847 1834 }
1848 1835
1849 1836 if ( ! empty( $connections ) ) {
1850 1837 $count = is_countable( $connections ) ? count( $connections ) : 0;
@@ -1853,9 +1840,10 @@
1853 1840 sprintf( __( 'Disconnecting all connections to %s.', 'jetpack' ), $service ),
1854 1841 $count
1855 1842 );
1856 1843
1857 - foreach ( $connections as $id => $connection ) {
1844 + foreach ( $connections as $connection ) {
1845 + $id = $connection['connection_id'];
1858 1846 if ( false === $publicize->disconnect( false, $id ) ) {
1859 1847 WP_CLI::error(
1860 1848 sprintf(
1861 1849 /* translators: %1$d is a numeric ID and %2$s is a lowercase string for a social network. */
@@ -1864,11 +1852,13 @@
1864 1852 )
1865 1853 );
1866 1854 }
1867 1855
1856 + // @phan-suppress-next-line PhanUndeclaredClassMethod - Class is missing from php-stubs/wp-cli-stubs 🤷
1868 1857 $progress->tick();
1869 1858 }
1870 1859
1860 + // @phan-suppress-next-line PhanUndeclaredClassMethod - Class is missing from php-stubs/wp-cli-stubs 🤷
1871 1861 $progress->finish();
1872 1862
1873 1863 if ( 'all' === $service ) {
1874 1864 WP_CLI::success( __( 'All Jetpack Social connections were successfully disconnected.', 'jetpack' ) );
@@ -1873,9 +1863,9 @@
1873 1863 if ( 'all' === $service ) {
1874 1864 WP_CLI::success( __( 'All Jetpack Social connections were successfully disconnected.', 'jetpack' ) );
1875 1865 } else {
1876 1866 /* translators: %s is a lowercase string for a social network. */
1877 - WP_CLI::success( __( 'All Jetpack Social connections to %s were successfully disconnected.', 'jetpack' ), $service );
1867 + WP_CLI::success( sprintf( __( 'All Jetpack Social connections to %s were successfully disconnected.', 'jetpack' ), $service ) );
1878 1868 }
1879 1869 }
1880 1870 } elseif ( false !== $publicize->disconnect( false, $identifier ) ) {
1881 1871 /* translators: %d is a numeric ID. Example: 1234. */
@@ -1965,14 +1955,14 @@
1965 1955 * @param array $args Positional parameters. Only one is used, that corresponds to the block title.
1966 1956 * @param array $assoc_args Associative parameters defined in the scaffold() method.
1967 1957 */
1968 1958 public function block( $args, $assoc_args ) {
1969 - if ( isset( $args[1] ) ) {
1970 - $title = ucwords( $args[1] );
1971 - } else {
1959 + if ( ! isset( $args[1] ) ) {
1972 1960 WP_CLI::error( esc_html__( 'The title parameter is required.', 'jetpack' ) . ' 👻' );
1973 1961 exit( 1 );
1974 1962 }
1963 +
1964 + $title = ucwords( $args[1] );
1975 1965
1976 1966 $slug = isset( $assoc_args['slug'] )
1977 1967 ? $assoc_args['slug']
1978 1968 : sanitize_title( $title );