PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 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 All 504 releases
← All changes | _inc/lib/core-api/class.jetpack-core-api-module-endpoints.php +226 -279 12.2.3 → 16.3-a.1 View file →
@@ -5,9 +5,9 @@
5 5 * @package automattic/jetpack
6 6 */
7 7
8 8 use Automattic\Jetpack\Connection\REST_Connector;
9 -use Automattic\Jetpack\Plugins_Installer;
9 +use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
10 10 use Automattic\Jetpack\Stats\WPCOM_Stats;
11 11 use Automattic\Jetpack\Stats_Admin\Main as Stats_Admin_Main;
12 12 use Automattic\Jetpack\Status;
13 13 use Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection;
@@ -12,13 +12,16 @@
12 12 use Automattic\Jetpack\Status;
13 13 use Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection;
14 14 use Automattic\Jetpack\Waf\Brute_Force_Protection\Brute_Force_Protection_Shared_Functions;
15 15
16 +if ( ! defined( 'ABSPATH' ) ) {
17 + exit( 0 );
18 +}
19 +
16 20 /**
17 21 * This is the base class for every Core API endpoint Jetpack uses.
18 22 */
19 -class Jetpack_Core_API_Module_Toggle_Endpoint
20 - extends Jetpack_Core_API_XMLRPC_Consumer_Endpoint {
23 +class Jetpack_Core_API_Module_Toggle_Endpoint extends Jetpack_Core_API_XMLRPC_Consumer_Endpoint {
21 24
22 25 /**
23 26 * Check if the module requires the site to be publicly accessible from WPCOM.
24 27 * If the site meets this requirement, the module is activated. Otherwise an error is returned.
@@ -195,11 +198,11 @@
195 198 * @return bool|Array|WP_Error a resulting value or object, or an error.
196 199 */
197 200 public function process( $request ) {
198 201 if ( 'GET' === $request->get_method() ) {
199 - return $this->get_modules( $request );
202 + return $this->get_modules();
200 203 } else {
201 - return $this->activate_modules( $request );
204 + return static::activate_modules( $request );
202 205 }
203 206 }
204 207
205 208 /**
@@ -402,15 +405,17 @@
402 405 $module['activated'] = false;
403 406 }
404 407
405 408 $i18n = jetpack_get_module_i18n( $request['slug'] );
406 - if ( isset( $module['name'] ) ) {
407 - $module['name'] = $i18n['name'];
409 + if ( $i18n ) {
410 + if ( isset( $module['name'] ) ) {
411 + $module['name'] = $i18n['name'];
412 + }
413 + if ( isset( $module['description'] ) ) {
414 + $module['description'] = $i18n['description'];
415 + $module['short_description'] = $i18n['description'];
416 + }
408 417 }
409 - if ( isset( $module['description'] ) ) {
410 - $module['description'] = $i18n['description'];
411 - $module['short_description'] = $i18n['description'];
412 - }
413 418 if ( isset( $module['module_tags'] ) ) {
414 419 $module['module_tags'] = array_map( 'jetpack_get_module_i18n_tag', $module['module_tags'] );
415 420 }
416 421
@@ -447,14 +452,18 @@
447 452 $response[ $module ] = Jetpack::is_module_active( $module );
448 453 }
449 454 }
450 455
451 - $settings = Jetpack_Core_Json_Api_Endpoints::get_updateable_data_list( 'settings' );
456 + $settings = Jetpack_Core_Json_Api_Endpoints::filter_options_for_response(
457 + Jetpack_Core_Json_Api_Endpoints::get_updateable_data_list( 'settings' )
458 + );
452 459
453 460 if ( ! function_exists( 'is_plugin_active' ) ) {
454 461 require_once ABSPATH . 'wp-admin/includes/plugin.php';
455 462 }
456 463
464 + $response['categories'] = get_categories( array( 'get' => 'all' ) );
465 +
457 466 foreach ( $settings as $setting => $properties ) {
458 467 switch ( $setting ) {
459 468 case 'lang_id':
460 469 if ( ! current_user_can( 'install_languages' ) ) {
@@ -483,24 +492,8 @@
483 492 $response[ $setting ] = class_exists( 'Akismet' ) ? Akismet::get_api_key() : '';
484 493 }
485 494 break;
486 495
487 - case 'onboarding':
488 - $business_address = get_option( 'jpo_business_address' );
489 - $business_address = is_array( $business_address ) ? array_map( array( $this, 'decode_special_characters' ), $business_address ) : $business_address;
490 -
491 - $response[ $setting ] = array(
492 - 'siteTitle' => $this->decode_special_characters( get_option( 'blogname' ) ),
493 - 'siteDescription' => $this->decode_special_characters( get_option( 'blogdescription' ) ),
494 - 'siteType' => get_option( 'jpo_site_type' ),
495 - 'homepageFormat' => get_option( 'jpo_homepage_format' ),
496 - 'addContactForm' => (int) get_option( 'jpo_contact_page' ),
497 - 'businessAddress' => $business_address,
498 - 'installWooCommerce' => is_plugin_active( 'woocommerce/woocommerce.php' ),
499 - 'stats' => Jetpack::is_connection_ready() && Jetpack::is_module_active( 'stats' ),
500 - );
501 - break;
502 -
503 496 case 'search_auto_config':
504 497 // Only writable.
505 498 $response[ $setting ] = 1;
506 499 break;
@@ -505,9 +498,9 @@
505 498 $response[ $setting ] = 1;
506 499 break;
507 500
508 501 default:
509 - $default = isset( $settings[ $setting ]['default'] ) ? $settings[ $setting ]['default'] : false;
502 + $default = $settings[ $setting ]['default'] ?? false;
510 503 $response[ $setting ] = Jetpack_Core_Json_Api_Endpoints::cast_value( get_option( $setting, $default ), $settings[ $setting ] );
511 504 break;
512 505 }
513 506 }
@@ -513,25 +506,23 @@
513 506 }
514 507
515 508 $response['akismet'] = is_plugin_active( 'akismet/akismet.php' );
516 509
510 + require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php';
511 + if ( class_exists( 'Jetpack_Memberships' ) ) {
512 + $response['newsletter_has_active_plan'] = count( Jetpack_Memberships::get_all_newsletter_plan_ids( false ) ) > 0;
513 + }
514 +
515 + // Make sure we are returning a consistent type
516 + if ( ! class_exists( 'Jetpack_Newsletter_Category_Helper' ) ) {
517 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-newsletter-category-helper.php';
518 + }
519 + $response['wpcom_newsletter_categories'] = Jetpack_Newsletter_Category_Helper::get_category_ids();
520 +
517 521 return rest_ensure_response( $response );
518 522 }
519 523
520 524 /**
521 - * Decode the special HTML characters in a certain value.
522 - *
523 - * @since 5.8
524 - *
525 - * @param string $value Value to decode.
526 - *
527 - * @return string Value with decoded HTML characters.
528 - */
529 - private function decode_special_characters( $value ) {
530 - return (string) htmlspecialchars_decode( $value, ENT_QUOTES );
531 - }
532 -
533 - /**
534 525 * If it's a valid Jetpack module and configuration parameters have been sent, update it.
535 526 *
536 527 * @since 4.3.0
537 528 *
@@ -540,9 +531,9 @@
540 531 *
541 532 * @type string $slug Module slug.
542 533 * }
543 534 *
544 - * @return bool|WP_Error True if module was updated. Otherwise, a WP_Error instance with the corresponding error.
535 + * @return bool|WP_REST_Response|WP_Error True or a WP_REST_Response if module was updated. Otherwise, a WP_Error instance with the corresponding error.
545 536 */
546 537 public function update_data( $request ) {
547 538
548 539 // If it's null, we're trying to update many module options from different modules.
@@ -562,9 +553,9 @@
562 553 }
563 554
564 555 /*
565 556 * Get parameters to update the module.
566 - * We can not simply use $request->get_params() because when we registered this route,
557 + * We cannot simply use $request->get_params() because when we registered this route,
567 558 * we are adding the entire output of Jetpack_Core_Json_Api_Endpoints::get_updateable_data_list()
568 559 * to the current request object's params. We are interested in body of the actual request.
569 560 * This may be JSON:
570 561 */
@@ -649,13 +640,22 @@
649 640 if ( ! $updated ) {
650 641 $not_updated[ $option ] = $error;
651 642 }
652 643
644 + if ( $updated ) {
645 + // Return the module state.
646 + $response[ $option ] = $value;
647 + }
648 +
653 649 // Remove module from list so we don't go through it again.
654 650 unset( $params[ $option ] );
655 651 }
656 652 }
657 653
654 + if ( ! class_exists( 'Jetpack_Newsletter_Category_Helper' ) ) {
655 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-newsletter-category-helper.php';
656 + }
657 +
658 658 foreach ( $params as $option => $value ) {
659 659
660 660 // Used if there was an error. Can be overwritten with specific error messages.
661 661 $error = '';
@@ -665,8 +665,14 @@
665 665
666 666 // Get option attributes, including the group it belongs to.
667 667 $option_attrs = $options[ $option ];
668 668
669 + // Everything outside the Post by Email group requires the admin capability.
670 + if ( 'post-by-email' !== $option_attrs['jp_group'] && ! current_user_can( 'jetpack_configure_modules' ) ) {
671 + $not_updated[ $option ] = REST_Connector::get_user_permissions_error_msg();
672 + continue;
673 + }
674 +
669 675 // If this is a module option and the related module isn't active for any reason, continue with the next one.
670 676 if ( 'settings' !== $option_attrs['jp_group'] ) {
671 677 if ( ! Jetpack::is_module( $option_attrs['jp_group'] ) ) {
672 678 $not_updated[ $option ] = esc_html__( 'The requested Jetpack module was not found.', 'jetpack' );
@@ -717,8 +723,13 @@
717 723 $updated = get_option( 'WPLANG' ) === $language ? true : update_option( 'WPLANG', $language );
718 724 break;
719 725
720 726 case 'monitor_receive_notifications':
727 + if ( ! class_exists( 'Jetpack_Monitor' ) ) {
728 + $updated = false;
729 + break;
730 + }
731 +
721 732 $monitor = new Jetpack_Monitor();
722 733
723 734 // If we got true as response, consider it done.
724 735 $updated = true === $monitor->update_option_receive_jetpack_monitor_notification( $value );
@@ -724,8 +735,13 @@
724 735 $updated = true === $monitor->update_option_receive_jetpack_monitor_notification( $value );
725 736 break;
726 737
727 738 case 'post_by_email_address':
739 + if ( ! class_exists( 'Jetpack_Post_By_Email' ) ) {
740 + $updated = false;
741 + break;
742 + }
743 +
728 744 $result = Jetpack_Post_By_Email::init()->process_api_request( $value );
729 745
730 746 // If we got an email address (create or regenerate) or 1 (delete), consider it done.
731 747 if ( is_string( $result ) && preg_match( '/[a-z0-9][email protected]/', $result ) ) {
@@ -746,9 +762,9 @@
746 762 $result = false;
747 763 }
748 764
749 765 // If we got one of Protect keys, consider it done.
750 - if ( preg_match( '/[a-z0-9]{40,}/i', $result ) ) {
766 + if ( is_string( $result ) && preg_match( '/[a-z0-9]{40,}/i', $result ) ) {
751 767 $response[ $option ] = $result;
752 768 $updated = true;
753 769 }
754 770 break;
@@ -812,8 +828,17 @@
812 828 ? update_option( 'verification_services_codes', $grouped_options )
813 829 : true;
814 830 break;
815 831
832 + case Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION:
833 + Jetpack_SEO_Utils::update_front_page_meta_description( $value );
834 + $response[ $option ] = Jetpack_SEO_Utils::get_front_page_meta_description();
835 + // The helper returns an empty string for a successful clear or
836 + // same-value write, so use its authoritative getter for the response
837 + // and treat every valid request reaching this switch as handled.
838 + $updated = true;
839 + break;
840 +
816 841 case 'sharing_services':
817 842 if ( ! class_exists( 'Sharing_Service' ) && ! include_once JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php' ) {
818 843 break;
819 844 }
@@ -961,26 +986,37 @@
961 986 ? update_option( $option, (bool) $value )
962 987 : true;
963 988 break;
964 989
965 - case 'onboarding':
966 - require_once JETPACK__PLUGIN_DIR . '_inc/lib/widgets.php';
967 - // Break apart and set Jetpack onboarding options.
968 - $result = $this->process_onboarding( (array) $value );
969 - if ( empty( $result ) ) {
970 - $updated = true;
971 - } else {
972 - $error = sprintf(
973 - /* Translators: placeholder is a list of error codes. */
974 - esc_html__( 'Onboarding failed to process: %s', 'jetpack' ),
975 - $result
976 - );
977 - $updated = false;
978 - }
990 + case 'jetpack_subscriptions_reply_to':
991 + // If option value was the same, consider it done.
992 + require_once JETPACK__PLUGIN_DIR . 'modules/subscriptions/class-settings.php';
993 + $sub_value = Automattic\Jetpack\Modules\Subscriptions\Settings::is_valid_reply_to( $value )
994 + ? $value
995 + : Automattic\Jetpack\Modules\Subscriptions\Settings::$default_reply_to;
996 +
997 + $updated = (string) get_option( $option ) !== (string) $sub_value ? update_option( $option, $sub_value ) : true;
979 998 break;
999 + case 'jetpack_subscriptions_from_name':
1000 + // If option value was the same, consider it done.
1001 + $sub_value = sanitize_text_field( $value );
1002 + $updated = (string) get_option( $option ) !== (string) $sub_value ? update_option( $option, $sub_value ) : true;
1003 + break;
980 1004
981 1005 case 'stb_enabled':
982 1006 case 'stc_enabled':
1007 + case 'sm_enabled':
1008 + case 'jetpack_subscribe_overlay_enabled':
1009 + case 'jetpack_subscribe_floating_button_enabled':
1010 + case 'wpcom_newsletter_categories_enabled':
1011 + case 'wpcom_featured_image_in_email':
1012 + case 'jetpack_gravatar_in_email':
1013 + case 'jetpack_author_in_email':
1014 + case 'jetpack_post_date_in_email':
1015 + case 'wpcom_subscription_emails_use_excerpt':
1016 + case 'jetpack_subscriptions_subscribe_post_end_enabled':
1017 + case 'jetpack_subscriptions_login_navigation_enabled':
1018 + case 'jetpack_subscriptions_subscribe_navigation_enabled':
983 1019 // Convert the false value to 0. This allows the option to be updated if it doesn't exist yet.
984 1020 $sub_value = $value ? $value : 0;
985 1021 $updated = (string) get_option( $option ) !== (string) $sub_value ? update_option( $option, $sub_value ) : true;
986 1022 break;
@@ -988,8 +1024,119 @@
988 1024 case 'jetpack_blocks_disabled':
989 1025 $updated = (bool) get_option( $option ) !== (bool) $value ? update_option( $option, (bool) $value ) : true;
990 1026 break;
991 1027
1028 + case 'subscription_options':
1029 + if ( ! is_array( $value ) ) {
1030 + break;
1031 + }
1032 +
1033 + $allowed_keys = array( 'invitation', 'comment_follow', 'welcome', 'subscribe_modal_heading', 'free_tier_description', 'hide_free_tier' );
1034 + $filtered_value = array_filter(
1035 + $value,
1036 + function ( $key ) use ( $allowed_keys ) {
1037 + return in_array( $key, $allowed_keys, true );
1038 + },
1039 + ARRAY_FILTER_USE_KEY
1040 + );
1041 +
1042 + if ( empty( $filtered_value ) ) {
1043 + break;
1044 + }
1045 +
1046 + // `hide_free_tier` is a boolean flag, so pull it out before the HTML
1047 + // sanitization below (which expects strings). Sanitize it with
1048 + // rest_sanitize_boolean() so stringy booleans (e.g. "false", "0")
1049 + // are interpreted correctly rather than being treated as truthy by a
1050 + // plain `! empty()`.
1051 + $has_hide_free_tier = array_key_exists( 'hide_free_tier', $filtered_value );
1052 + $hide_free_tier = $has_hide_free_tier && rest_sanitize_boolean( $filtered_value['hide_free_tier'] );
1053 + unset( $filtered_value['hide_free_tier'] );
1054 +
1055 + array_walk_recursive(
1056 + $filtered_value,
1057 + function ( &$value ) {
1058 + $value = wp_kses(
1059 + $value,
1060 + array(
1061 + 'ul' => array(),
1062 + 'li' => array(),
1063 + 'p' => array(),
1064 + 'strong' => array(),
1065 + 'ol' => array(),
1066 + 'em' => array(),
1067 + 'a' => array(
1068 + 'href' => array(),
1069 + ),
1070 + )
1071 + );
1072 + }
1073 + );
1074 +
1075 + // Normalize whitespace-only `subscribe_modal_heading` input to empty so
1076 + // the modal template's `empty()` fallback fires. PHP's `empty()` treats
1077 + // `" "` as non-empty, which would otherwise render a blank heading.
1078 + if ( isset( $filtered_value['subscribe_modal_heading'] ) ) {
1079 + $filtered_value['subscribe_modal_heading'] = trim( $filtered_value['subscribe_modal_heading'] );
1080 + }
1081 +
1082 + // The free tier description is stored as plain markdown source, so strip
1083 + // all HTML and cap its length to match the paid-tier description field.
1084 + // WordPress core guarantees mb_substr() (polyfilled in wp-includes/compat.php
1085 + // when the mbstring extension is unavailable), so it's safe to use directly.
1086 + // A JSON payload could supply a non-scalar (array/object) for this field,
1087 + // which would fatal in wp_kses()/mb_substr() on PHP 8+, so drop invalid values.
1088 + if ( isset( $filtered_value['free_tier_description'] ) ) {
1089 + if ( is_scalar( $filtered_value['free_tier_description'] ) ) {
1090 + $filtered_value['free_tier_description'] = mb_substr( wp_kses( (string) $filtered_value['free_tier_description'], array() ), 0, 500 );
1091 + } else {
1092 + unset( $filtered_value['free_tier_description'] );
1093 + }
1094 + }
1095 +
1096 + if ( $has_hide_free_tier ) {
1097 + $filtered_value['hide_free_tier'] = $hide_free_tier;
1098 + }
1099 +
1100 + $old_subscription_options = get_option( 'subscription_options' );
1101 + if ( ! is_array( $old_subscription_options ) ) {
1102 + $old_subscription_options = array();
1103 + }
1104 + $new_subscription_options = array_merge( $old_subscription_options, $filtered_value );
1105 + $updated = true;
1106 +
1107 + if ( serialize( $old_subscription_options ) === serialize( $new_subscription_options ) ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
1108 + break; // This prevents the option update to fail when the values are the same.
1109 + }
1110 +
1111 + if ( ! update_option( $option, $new_subscription_options ) ) {
1112 + $updated = false;
1113 + $error = esc_html__( 'Subscription Options failed to process.', 'jetpack' );
1114 + }
1115 + break;
1116 +
1117 + case Jetpack_Newsletter_Category_Helper::NEWSLETTER_CATEGORIES_OPTION:
1118 + if ( ! is_array( $value ) || empty( $value ) ) {
1119 + $updated = true;
1120 + break;
1121 + }
1122 +
1123 + // If we are already current, do nothing
1124 + $current_value = Jetpack_Newsletter_Category_Helper::get_category_ids();
1125 + if ( $value === $current_value ) {
1126 + $updated = true;
1127 + break;
1128 + }
1129 +
1130 + if ( Jetpack_Newsletter_Category_Helper::save_category_ids( $value ) ) {
1131 + $updated = true;
1132 + } else {
1133 + $updated = false;
1134 + $error = esc_html__( 'Newsletter category did not update.', 'jetpack' );
1135 + }
1136 +
1137 + break;
1138 +
992 1139 default:
993 1140 // Boolean values are stored as 1 or 0.
994 1141 if ( isset( $options[ $option ]['type'] ) && 'boolean' === $options[ $option ]['type'] ) {
995 1142 $value = (int) $value;
@@ -995,9 +1142,9 @@
995 1142 $value = (int) $value;
996 1143 }
997 1144
998 1145 // If option value was the same as it's current value, or it's default, consider it done.
999 - $default = isset( $options[ $option ]['default'] ) ? $options[ $option ]['default'] : false;
1146 + $default = $options[ $option ]['default'] ?? false;
1000 1147 $updated = get_option( $option, $default ) != $value // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual -- ensure we support scalars or strings saved by update_option.
1001 1148 ? update_option( $option, $value )
1002 1149 : true;
1003 1150 break;
@@ -1051,218 +1198,30 @@
1051 1198 * Perform tasks in the site based on onboarding choices.
1052 1199 *
1053 1200 * @since 5.4.0
1054 1201 *
1202 + * @deprecated since 13.9
1203 + *
1055 1204 * @param array $data Onboarding choices made by user.
1056 1205 *
1057 1206 * @return string Result of onboarding processing and, if there is one, an error message.
1058 1207 */
1059 - private function process_onboarding( $data ) {
1060 - if ( isset( $data['end'] ) && $data['end'] ) {
1061 - return Jetpack::invalidate_onboarding_token()
1062 - ? ''
1063 - : esc_html__( "The onboarding token couldn't be deleted.", 'jetpack' );
1064 - }
1065 -
1066 - $error = array();
1067 -
1068 - if ( ! empty( $data['siteTitle'] ) ) {
1069 - // If option value was the same, consider it done.
1070 - if ( ! (
1071 - update_option( 'blogname', $data['siteTitle'] )
1072 - || get_option( 'blogname' ) === $data['siteTitle']
1073 - ) ) {
1074 - $error[] = 'siteTitle';
1075 - }
1076 - }
1077 -
1078 - if ( isset( $data['siteDescription'] ) ) {
1079 - // If option value was the same, consider it done.
1080 - if ( ! (
1081 - update_option( 'blogdescription', $data['siteDescription'] )
1082 - || get_option( 'blogdescription' ) === $data['siteDescription']
1083 - ) ) {
1084 - $error[] = 'siteDescription';
1085 - }
1086 - }
1087 -
1088 - $site_title = get_option( 'blogname' );
1089 - $author = get_current_user_id() || 1;
1090 -
1091 - if ( ! empty( $data['siteType'] ) ) {
1092 - if ( ! (
1093 - update_option( 'jpo_site_type', $data['siteType'] )
1094 - || get_option( 'jpo_site_type' ) === $data['siteType']
1095 - ) ) {
1096 - $error[] = 'siteType';
1097 - }
1098 - }
1099 -
1100 - if ( isset( $data['homepageFormat'] ) ) {
1101 - /*
1102 - * If $data['homepageFormat'] is 'posts',
1103 - * we have nothing to do since it's WordPress' default
1104 - * if it exists, just update
1105 - */
1106 - $homepage_format = get_option( 'jpo_homepage_format' );
1107 - if ( ! $homepage_format || $homepage_format !== $data['homepageFormat'] ) {
1108 - if ( 'page' === $data['homepageFormat'] ) {
1109 - if ( ! (
1110 - update_option( 'show_on_front', 'page' )
1111 - || get_option( 'show_on_front' ) === 'page'
1112 - ) ) {
1113 - $error[] = 'homepageFormat';
1114 - }
1115 -
1116 - $home = wp_insert_post(
1117 - array(
1118 - 'post_type' => 'page',
1119 - /* translators: this references the home page of a site, also called front page. */
1120 - 'post_title' => esc_html_x( 'Home Page', 'The home page of a website.', 'jetpack' ),
1121 - 'post_content' => sprintf(
1122 - /* Translators: placeholder is the site title. */
1123 - esc_html__( 'Welcome to %s.', 'jetpack' ),
1124 - $site_title
1125 - ),
1126 - 'post_status' => 'publish',
1127 - 'post_author' => $author,
1128 - )
1129 - );
1130 - if ( 0 === $home ) {
1131 - $error[] = 'home insert: 0';
1132 - } elseif ( is_wp_error( $home ) ) {
1133 - $error[] = 'home creation: ' . $home->get_error_message();
1134 - }
1135 - if ( ! (
1136 - update_option( 'page_on_front', $home )
1137 - || get_option( 'page_on_front' ) === $home
1138 - ) ) {
1139 -
1140 - $error[] = 'home set';
1141 - }
1142 -
1143 - $blog = wp_insert_post(
1144 - array(
1145 - 'post_type' => 'page',
1146 - /* translators: this references the page where blog posts are listed. */
1147 - 'post_title' => esc_html_x( 'Blog', 'The blog of a website.', 'jetpack' ),
1148 - 'post_content' => sprintf(
1149 - /* Translators: placeholder is the site title. */
1150 - esc_html__( 'These are the latest posts in %s.', 'jetpack' ),
1151 - $site_title
1152 - ),
1153 - 'post_status' => 'publish',
1154 - 'post_author' => $author,
1155 - )
1156 - );
1157 - if ( 0 === $blog ) {
1158 - $error[] = 'blog insert: 0';
1159 - } elseif ( is_wp_error( $blog ) ) {
1160 - $error[] = 'blog creation: ' . $blog->get_error_message();
1161 - }
1162 - if ( ! (
1163 - update_option( 'page_for_posts', $blog )
1164 - || get_option( 'page_for_posts' ) === $blog
1165 - ) ) {
1166 - $error[] = 'blog set';
1167 - }
1168 - } else {
1169 - $front_page = get_option( 'page_on_front' );
1170 - $posts_page = get_option( 'page_for_posts' );
1171 - if ( $posts_page && get_post( $posts_page ) ) {
1172 - wp_delete_post( $posts_page );
1173 - }
1174 - if ( $front_page && get_post( $front_page ) ) {
1175 - wp_delete_post( $front_page );
1176 - }
1177 - update_option( 'show_on_front', 'posts' );
1178 - }
1179 - }
1180 - update_option( 'jpo_homepage_format', $data['homepageFormat'] );
1181 - }
1182 -
1183 - // Setup contact page and add a form and/or business info.
1184 - $contact_page = '';
1185 - if ( ! empty( $data['addContactForm'] ) && ! get_option( 'jpo_contact_page' ) ) {
1186 - $contact_form_module_active = Jetpack::is_module_active( 'contact-form' );
1187 - if ( ! $contact_form_module_active ) {
1188 - $contact_form_module_active = Jetpack::activate_module( 'contact-form', false, false );
1189 - }
1190 -
1191 - if ( $contact_form_module_active ) {
1192 - $contact_page = '[contact-form][contact-field label="' . esc_html__( 'Name', 'jetpack' ) . '" type="name" required="true" /][contact-field label="' . esc_html__( 'Email', 'jetpack' ) . '" type="email" required="true" /][contact-field label="' . esc_html__( 'Website', 'jetpack' ) . '" type="url" /][contact-field label="' . esc_html__( 'Message', 'jetpack' ) . '" type="textarea" /][/contact-form]';
1193 - } else {
1194 - $error[] = 'contact-form activate';
1195 - }
1196 - }
1197 -
1198 - if ( isset( $data['businessPersonal'] ) && 'business' === $data['businessPersonal'] ) {
1199 - $contact_page .= "\n" . implode( "\n", $data['businessInfo'] );
1200 - }
1201 -
1202 - if ( ! empty( $contact_page ) ) {
1203 - $form = wp_insert_post(
1204 - array(
1205 - 'post_type' => 'page',
1206 - /* translators: this references a page with contact details and possibly a form. */
1207 - 'post_title' => esc_html_x( 'Contact us', 'Contact page for your website.', 'jetpack' ),
1208 - 'post_content' => esc_html__( 'Send us a message!', 'jetpack' ) . "\n" . $contact_page,
1209 - 'post_status' => 'publish',
1210 - 'post_author' => $author,
1211 - )
1212 - );
1213 - if ( 0 === $form ) {
1214 - $error[] = 'form insert: 0';
1215 - } elseif ( is_wp_error( $form ) ) {
1216 - $error[] = 'form creation: ' . $form->get_error_message();
1217 - } else {
1218 - update_option( 'jpo_contact_page', $form );
1219 - }
1220 - }
1221 -
1222 - if ( isset( $data['businessAddress'] ) ) {
1223 - $handled_business_address = self::handle_business_address( $data['businessAddress'] );
1224 - if ( is_wp_error( $handled_business_address ) ) {
1225 - $error[] = 'BusinessAddress';
1226 - }
1227 - }
1228 -
1229 - if ( ! empty( $data['installWooCommerce'] ) ) {
1230 - $wc_install_result = Plugins_Installer::install_and_activate_plugin( 'woocommerce' );
1231 - delete_transient( '_wc_activation_redirect' ); // Redirecting to WC setup would kill our users' flow.
1232 - if ( is_wp_error( $wc_install_result ) ) {
1233 - $error[] = 'woocommerce installation';
1234 - }
1235 - }
1236 -
1237 - if ( ! empty( $data['stats'] ) ) {
1238 - if ( Jetpack::is_connection_ready() ) {
1239 - $stats_module_active = Jetpack::is_module_active( 'stats' );
1240 - if ( ! $stats_module_active ) {
1241 - $stats_module_active = Jetpack::activate_module( 'stats', false, false );
1242 - }
1243 -
1244 - if ( ! $stats_module_active ) {
1245 - $error[] = 'stats activate';
1246 - }
1247 - } else {
1248 - $error[] = 'stats not connected';
1249 - }
1250 - }
1251 -
1252 - return empty( $error )
1253 - ? ''
1254 - : implode( ', ', $error );
1208 + private function process_onboarding( $data ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
1209 + _deprecated_function( __METHOD__, '13.9' );
1210 + return '';
1255 1211 }
1256 1212
1257 1213 /**
1258 1214 * Add or update Business Address widget.
1259 1215 *
1216 + * @deprecated since 13.9
1217 + *
1260 1218 * @param array $address Array of business address fields.
1261 1219 *
1262 1220 * @return WP_Error|true True if the data was saved correctly.
1263 1221 */
1264 1222 private static function handle_business_address( $address ) {
1223 + _deprecated_function( __METHOD__, '13.9' );
1265 1224 $first_sidebar = Jetpack_Widgets::get_first_sidebar();
1266 1225
1267 1226 $widgets_module_active = Jetpack::is_module_active( 'widgets' );
1268 1227 if ( ! $widgets_module_active ) {
@@ -1329,9 +1288,9 @@
1329 1288 if ( ! isset( $sidebars_widgets[ $sidebar ] ) ) {
1330 1289 return false;
1331 1290 }
1332 1291 foreach ( $sidebars_widgets[ $sidebar ] as $widget ) {
1333 - if ( strpos( $widget, 'widget_contact_info' ) !== false ) {
1292 + if ( str_contains( $widget, 'widget_contact_info' ) ) {
1334 1293 return true;
1335 1294 }
1336 1295 }
1337 1296 return false;
@@ -1346,13 +1305,8 @@
1346 1305 *
1347 1306 * @return bool
1348 1307 */
1349 1308 public function can_request( $request ) {
1350 - $req_params = $request->get_params();
1351 - if ( ! empty( $req_params['onboarding']['token'] ) && isset( $req_params['rest_route'] ) ) {
1352 - return Jetpack::validate_onboarding_token_action( $req_params['onboarding']['token'], $req_params['rest_route'] );
1353 - }
1354 -
1355 1309 if ( 'GET' === $request->get_method() ) {
1356 1310 return current_user_can( 'jetpack_admin_page' );
1357 1311 } else {
1358 1312 $module = Jetpack_Core_Json_Api_Endpoints::get_module_requested();
@@ -1361,13 +1315,13 @@
1361 1315 if ( ! is_array( $params ) ) {
1362 1316 $params = $request->get_body_params();
1363 1317 }
1364 1318 $options = Jetpack_Core_Json_Api_Endpoints::get_updateable_data_list( $params );
1365 - foreach ( $options as $option => $definition ) {
1366 - if ( in_array( $options[ $option ]['jp_group'], array( 'post-by-email' ), true ) ) {
1367 - $module = $options[ $option ]['jp_group'];
1368 - break;
1369 - }
1319 +
1320 + // The Post by Email gate applies only when the request contains nothing else.
1321 + $groups = array_values( array_unique( array_column( $options, 'jp_group' ) ) );
1322 + if ( array( 'post-by-email' ) === $groups ) {
1323 + $module = 'post-by-email';
1370 1324 }
1371 1325 }
1372 1326 // User is trying to create, regenerate or delete its PbE.
1373 1327 if ( 'post-by-email' === $module ) {
@@ -1383,9 +1337,8 @@
1383 1337 *
1384 1338 * phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
1385 1339 */
1386 1340 class Jetpack_Core_API_Module_Data_Endpoint {
1387 - // phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
1388 1341
1389 1342 /**
1390 1343 * Process request and return different data based on the module we are interested in.
1391 1344 *
@@ -1574,32 +1527,26 @@
1574 1527 ) {
1575 1528 $range = 'day';
1576 1529 }
1577 1530
1578 - if ( ! function_exists( 'convert_stats_array_to_object' ) ) {
1579 - require_once JETPACK__PLUGIN_DIR . 'modules/stats.php';
1580 - }
1581 -
1582 1531 $wpcom_stats = new WPCOM_Stats();
1583 1532 switch ( $range ) {
1584 1533
1585 1534 // This is always called first on page load.
1586 1535 case 'day':
1587 - $initial_stats = convert_stats_array_to_object( $wpcom_stats->get_stats() );
1536 + $initial_stats = $wpcom_stats->convert_stats_array_to_object( $wpcom_stats->get_stats() );
1588 1537 return rest_ensure_response(
1589 1538 array(
1590 1539 'general' => $initial_stats,
1591 1540
1592 1541 // Build data for 'day' as if it was $wpcom_stats ->get_visits( array( 'unit' => 'day, 'quantity' => 30).
1593 - 'day' => isset( $initial_stats->visits )
1594 - ? $initial_stats->visits
1595 - : array(),
1542 + 'day' => $initial_stats->visits ?? array(),
1596 1543 )
1597 1544 );
1598 1545 case 'week':
1599 1546 return rest_ensure_response(
1600 1547 array(
1601 - 'week' => convert_stats_array_to_object(
1548 + 'week' => $wpcom_stats->convert_stats_array_to_object(
1602 1549 $wpcom_stats->get_visits(
1603 1550 array(
1604 1551 'unit' => 'week',
1605 1552 'quantity' => 14,
@@ -1610,9 +1557,9 @@
1610 1557 );
1611 1558 case 'month':
1612 1559 return rest_ensure_response(
1613 1560 array(
1614 - 'month' => convert_stats_array_to_object(
1561 + 'month' => $wpcom_stats->convert_stats_array_to_object(
1615 1562 $wpcom_stats->get_visits(
1616 1563 array(
1617 1564 'unit' => 'month',
1618 1565 'quantity' => 12,
@@ -1734,9 +1681,9 @@
1734 1681 $last_service = $copy_services[ $last ];
1735 1682 unset( $copy_services[ $last ] );
1736 1683 $message = esc_html(
1737 1684 sprintf(
1738 - /* translators: %1$s is a comma separated list of services, and %2$s is a single service name like Google, Bing, Pinterest, etc. */
1685 + /* translators: %1$s is a comma-separated list of services, and %2$s is a single service name like Google, Bing, Pinterest, etc. */
1739 1686 __( 'Your site is verified with %1$s and %2$s.', 'jetpack' ),
1740 1687 implode( ', ', $copy_services ),
1741 1688 $last_service
1742 1689 )