From d1a9ad57b1ac6609ef3a864315a0c009bd774446 Mon Sep 17 00:00:00 2001 From: Karen Attfield Date: Fri, 9 Aug 2024 08:01:16 +0100 Subject: [PATCH] Contact Form: Removing deprecated Google Drive Helper file, and jetpack_form_register_pattern function (#38786) --- projects/plugins/jetpack/.phan/baseline.php | 4 +- .../lib/class-jetpack-google-drive-helper.php | 133 ------------------ .../changelog/remove-google-drive-helper | 4 + .../plugins/jetpack/modules/contact-form.php | 103 -------------- 4 files changed, 5 insertions(+), 239 deletions(-) delete mode 100644 projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php create mode 100644 projects/plugins/jetpack/changelog/remove-google-drive-helper diff --git a/projects/plugins/jetpack/.phan/baseline.php b/projects/plugins/jetpack/.phan/baseline.php index 1610ab760497e..cd06acc4b737c 100644 --- a/projects/plugins/jetpack/.phan/baseline.php +++ b/projects/plugins/jetpack/.phan/baseline.php @@ -14,7 +14,7 @@ // PhanNoopNew : 200+ occurrences // PhanTypeMismatchArgumentProbablyReal : 200+ occurrences // PhanTypeMismatchReturn : 150+ occurrences - // PhanTypeMismatchReturnProbablyReal : 140+ occurrences + // PhanTypeMismatchReturnProbablyReal : 130+ occurrences // PhanDeprecatedFunction : 120+ occurrences // PhanTypePossiblyInvalidDimOffset : 95+ occurrences // PhanRedundantCondition : 70+ occurrences @@ -116,7 +116,6 @@ '_inc/lib/admin-pages/class-jetpack-redux-state-helper.php' => ['PhanParamTooMany', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanRedundantCondition', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDimAssignment'], '_inc/lib/admin-pages/class.jetpack-admin-page.php' => ['PhanDeprecatedProperty', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredProperty'], '_inc/lib/class-jetpack-ai-helper.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchPropertyDefault'], - '_inc/lib/class-jetpack-google-drive-helper.php' => ['PhanTypeMismatchReturnProbablyReal'], '_inc/lib/class-jetpack-instagram-gallery-helper.php' => ['PhanTypeMismatchArgument'], '_inc/lib/class-jetpack-mapbox-helper.php' => ['PhanTypeMismatchArgumentNullable'], '_inc/lib/class-jetpack-podcast-feed-locator.php' => ['PhanDeprecatedFunctionInternal'], @@ -329,7 +328,6 @@ 'modules/comments/base.php' => ['PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredProperty'], 'modules/comments/comments.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanRedundantCondition', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchArgument', 'PhanUndeclaredFunction'], 'modules/comments/subscription-modal-on-comment/class-jetpack-subscription-modal-on-comment.php' => ['PhanTypeMismatchReturnNullable'], - 'modules/contact-form.php' => ['PhanSuspiciousMagicConstant'], 'modules/copy-post.php' => ['PhanNoopNew'], 'modules/custom-css/csstidy/class.csstidy-ctype.php' => ['PhanRedefineFunctionInternal'], 'modules/custom-css/csstidy/class.csstidy-optimise.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPluginSimplifyExpressionBool', 'PhanTypeComparisonFromArray', 'PhanTypeConversionFromArray', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeInvalidRightOperandOfNumericOp', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchReturnProbablyReal'], diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php deleted file mode 100644 index bbc61f4e10290..0000000000000 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-google-drive-helper.php +++ /dev/null @@ -1,133 +0,0 @@ -has_valid_connection - * @param int $user_id The user ID. - * @return array Array with single 'valid' (bool) entry. - */ - public static function has_valid_connection( $user_id ) { - _deprecated_function( __METHOD__, 'jetpack-13.4', 'Automattic\Jetpack\Forms\Service\Google_Drive_Helper->has_valid_connection' ); - $site_id = Manager::get_site_id(); - if ( is_wp_error( $site_id ) ) { - return false; - } - - if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - // check for gdrive helper class, call synchronously on .com - require_lib( 'google-sheets-helper' ); - $user_id = (int) get_current_user_id(); - $token = WPCOM_Google_Sheets_helper::get_google_drive_token_for_user_id( $user_id ); - - return ! is_wp_error( $token ) && ! $token->is_expired(); - } - - $request_path = sprintf( '/sites/%d/google-drive/connection', $site_id ); - $wpcom_request = Client::wpcom_json_api_request_as_user( - $request_path, - '2', - array( - 'method' => 'GET', - 'headers' => array( - 'content-type' => 'application/json', - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ), - ), - ) - ); - - $response_code = wp_remote_retrieve_response_code( $wpcom_request ); - if ( 200 !== $response_code ) { - return new WP_Error( - 'failed_to_fetch_data', - esc_html__( 'Unable to fetch the requested data.', 'jetpack' ), - array( 'status' => $response_code ) - ); - } - $result = json_decode( wp_remote_retrieve_body( $wpcom_request ), true ); - - return ! empty( $result ) && ! empty( $result['valid'] ); - } - - /** - * Creates a Google Spreadsheet and returns some of its meta - * - * @deprecated 13.4 Use Automattic\Jetpack\Forms\Service\Google_Drive_Helper->create_sheet - * @param int $user_id The user ID. - * @param string $title The spreadsheet title. - * @param array $rows Array of arrays with values. - * @return array|WP_Error - */ - public static function create_sheet( $user_id, $title, $rows = array() ) { - _deprecated_function( __METHOD__, 'jetpack-13.4', 'Automattic\Jetpack\Forms\Service\Google_Drive_Helper->create_sheet' ); - $site_id = Manager::get_site_id(); - if ( is_wp_error( $site_id ) ) { - return false; - } - - if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - // check for gdrive helper class, call synchronously on .com - require_lib( 'google-sheets-helper' ); - $helper = WPCOM_Google_Sheets_helper::create_for_user( $user_id ); - - if ( is_wp_error( $helper ) ) { - return $helper; - } - - $spreadsheet = $helper->create_spreadsheet( $title, $rows ); - - if ( is_wp_error( $spreadsheet ) ) { - return $spreadsheet; - } - - return array( - // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- as is on google client - 'sheet_link' => $spreadsheet->spreadsheetUrl, - // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- as is on google client - 'sheet_id' => $spreadsheet->spreadsheetId, - ); - } - - $request_path = sprintf( '/sites/%d/google-drive/sheets', $site_id ); - $wpcom_request = Client::wpcom_json_api_request_as_user( - $request_path, - '2', - array( - 'method' => 'POST', - 'headers' => array( - 'content-type' => 'application/json', - 'X-Forwarded-For' => ( new Visitor() )->get_ip( true ), - ), - ), - array( - 'title' => $title, - 'rows' => $rows, - ) - ); - $response_code = wp_remote_retrieve_response_code( $wpcom_request ); - if ( 200 !== $response_code ) { - return new WP_Error( - 'failed_to_fetch_data', - esc_html__( 'Unable to fetch the requested data.', 'jetpack' ), - array( 'status' => $response_code ) - ); - } - return json_decode( wp_remote_retrieve_body( $wpcom_request ), true ); - } -} diff --git a/projects/plugins/jetpack/changelog/remove-google-drive-helper b/projects/plugins/jetpack/changelog/remove-google-drive-helper new file mode 100644 index 0000000000000..44e0e8410807b --- /dev/null +++ b/projects/plugins/jetpack/changelog/remove-google-drive-helper @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Contact Form: Removing deprecated functionality diff --git a/projects/plugins/jetpack/modules/contact-form.php b/projects/plugins/jetpack/modules/contact-form.php index e943fa6b37a10..a01f48e8a82c0 100644 --- a/projects/plugins/jetpack/modules/contact-form.php +++ b/projects/plugins/jetpack/modules/contact-form.php @@ -24,106 +24,3 @@ * Load the newer Jetpack Forms package. */ Jetpack_Forms::load_contact_form(); - -/** - * Register Jetpack Form patterns - * - * @deprecated 13.4 Use Automattic\Jetpack\Forms\ContactForm\Util::register_pattern - */ -function jetpack_form_register_pattern() { - _deprecated_function( __METHOD__, 'jetpack-13.4', 'Automattic\Jetpack\Forms\ContactForm\Util::register_pattern' ); - $category_slug = 'forms'; - register_block_pattern_category( $category_slug, array( 'label' => __( 'Forms', 'jetpack' ) ) ); - - $patterns = array( - 'contact-form' => array( - 'title' => 'Contact Form', - 'blockTypes' => array( 'jetpack/contact-form' ), - 'categories' => array( $category_slug ), - 'content' => ' -
- - - - -
- ', - ), - 'newsletter-form' => array( - 'title' => 'Newsletter Subscription Form', - 'blockTypes' => array( 'jetpack/contact-form' ), - 'categories' => array( $category_slug ), - 'content' => ' -
- - - - -
- ', - ), - 'rsvp-form' => array( - 'title' => 'RSVP Form', - 'blockTypes' => array( 'jetpack/contact-form' ), - 'categories' => array( $category_slug ), - 'content' => ' -
- - - - - -
- ', - ), - 'registration-form' => array( - 'title' => 'Registration Form', - 'blockTypes' => array( 'jetpack/contact-form' ), - 'categories' => array( $category_slug ), - 'content' => ' -
- - - - - - -
- ', - ), - 'appointment-form' => array( - 'title' => 'Appointment Form', - 'blockTypes' => array( 'jetpack/contact-form' ), - 'categories' => array( $category_slug ), - 'content' => ' -
- - - - - - - -
- ', - ), - 'feedback-form' => array( - 'title' => 'Feedback Form', - 'blockTypes' => array( 'jetpack/contact-form' ), - 'categories' => array( $category_slug ), - 'content' => ' -
- - - - - -
- ', - ), - ); - - foreach ( $patterns as $name => $pattern ) { - register_block_pattern( $name, $pattern ); - } -}