diff --git a/projects/plugins/jetpack/.phan/baseline.php b/projects/plugins/jetpack/.phan/baseline.php index bd0a0bf496b72..f951297a6a338 100644 --- a/projects/plugins/jetpack/.phan/baseline.php +++ b/projects/plugins/jetpack/.phan/baseline.php @@ -15,7 +15,7 @@ // PhanTypeMismatchArgumentProbablyReal : 200+ occurrences // PhanTypeMismatchReturn : 150+ occurrences // PhanTypeMismatchReturnProbablyReal : 130+ occurrences - // PhanDeprecatedFunction : 120+ occurrences + // PhanDeprecatedFunction : 110+ occurrences // PhanTypePossiblyInvalidDimOffset : 95+ occurrences // PhanRedundantCondition : 70+ occurrences // PhanPossiblyUndeclaredVariable : 60+ occurrences @@ -51,10 +51,10 @@ // PhanUndeclaredFunction : 10+ occurrences // PhanTypeComparisonToArray : 9 occurrences // PhanPluginRedundantAssignment : 8 occurrences - // PhanDeprecatedClass : 7 occurrences // PhanTypeInvalidLeftOperandOfNumericOp : 7 occurrences // PhanTypeMismatchArgumentInternalReal : 7 occurrences // PhanCommentAbstractOnInheritedMethod : 6 occurrences + // PhanDeprecatedClass : 5 occurrences // PhanImpossibleCondition : 5 occurrences // PhanNonClassMethodCall : 5 occurrences // PhanRedefinedClassReference : 5 occurrences @@ -74,7 +74,6 @@ // PhanTypeConversionFromArray : 3 occurrences // PhanTypeMismatchArgumentReal : 3 occurrences // PhanTypeObjectUnsetDeclaredProperty : 3 occurrences - // PhanUndeclaredConstant : 3 occurrences // PhanUndeclaredMethodInCallable : 3 occurrences // PhanCompatibleNegativeStringOffset : 2 occurrences // PhanImpossibleConditionInLoop : 2 occurrences @@ -96,6 +95,7 @@ // PhanTypeComparisonFromArray : 1 occurrence // PhanTypeInvalidRightOperandOfNumericOp : 1 occurrence // PhanTypeVoidArgument : 1 occurrence + // PhanUndeclaredConstant : 1 occurrence // PhanUndeclaredExtendedClass : 1 occurrence // PhanUndeclaredTypeReturnType : 1 occurrence @@ -364,7 +364,6 @@ 'modules/seo-tools.php' => ['PhanNoopNew'], 'modules/seo-tools/class-jetpack-seo.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], 'modules/sharedaddy/recaptcha.php' => ['PhanPluginDuplicateExpressionAssignmentOperation'], - 'modules/sharedaddy/sharedaddy.php' => ['PhanDeprecatedClass', 'PhanDeprecatedFunction', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredConstant'], 'modules/sharedaddy/sharing-service.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspicious', 'PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanTypeMismatchPropertyDefault', 'PhanTypeMismatchPropertyProbablyReal', 'PhanTypePossiblyInvalidDimOffset', 'PhanUndeclaredFunction'], 'modules/sharedaddy/sharing-sources.php' => ['PhanParamSignatureMismatch', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchProperty', 'PhanTypeSuspiciousNonTraversableForeach'], 'modules/sharedaddy/sharing.php' => ['PhanRedundantCondition', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypePossiblyInvalidDimOffset'], diff --git a/projects/plugins/jetpack/changelog/remove-deprecated-sharedaddy-functions b/projects/plugins/jetpack/changelog/remove-deprecated-sharedaddy-functions new file mode 100644 index 0000000000000..6035c051ce360 --- /dev/null +++ b/projects/plugins/jetpack/changelog/remove-deprecated-sharedaddy-functions @@ -0,0 +1,4 @@ +Significance: major +Type: other + +Sharing: remove functions that were deprecated in Jetpack 11.0. diff --git a/projects/plugins/jetpack/modules/sharedaddy/sharedaddy.php b/projects/plugins/jetpack/modules/sharedaddy/sharedaddy.php index 36b8727b2c07c..8e0e1a63b05d1 100644 --- a/projects/plugins/jetpack/modules/sharedaddy/sharedaddy.php +++ b/projects/plugins/jetpack/modules/sharedaddy/sharedaddy.php @@ -9,155 +9,6 @@ // Set up Sharing in wp-admin. require_once plugin_dir_path( __FILE__ ) . 'sharing.php'; -/** - * Send an email via the Email sharing button. - * - * @param array $data Array of information about the shared message. - * - * @return void - * - * @deprecated 11.0 - */ -function sharing_email_send_post( $data ) { - - $content = sharing_email_send_post_content( $data ); - // Borrowed from wp_mail(); - - if ( empty( $_SERVER['SERVER_NAME'] ) ) { - return; - } - - $sitename = strtolower( sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) ); - if ( str_starts_with( $sitename, 'www.' ) ) { - $sitename = substr( $sitename, 4 ); - } - - /** This filter is documented in core/src/wp-includes/pluggable.php */ - $from_email = apply_filters( 'wp_mail_from', 'wordpress@' . $sitename ); - - if ( ! empty( $data['name'] ) ) { - $s_name = (string) $data['name']; - $name_needs_encoding_regex = - '/[' . - // SpamAssasin's list of characters which "need MIME" encoding - '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff' . - // Our list of "unsafe" characters - '<\r\n' . - ']/'; - - $needs_encoding = - // If it contains any blocked chars. - preg_match( $name_needs_encoding_regex, $s_name ) || - // Or if we can't use `mb_convert_encoding` - ! function_exists( 'mb_convert_encoding' ) || - // Or if it's not already ASCII - mb_convert_encoding( $data['name'], 'ASCII' ) !== $s_name; - - if ( $needs_encoding ) { - $data['name'] = sprintf( '=?UTF-8?B?%s?=', base64_encode( $data['name'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode - } - } - - $headers = array(); - $headers[] = sprintf( 'From: %1$s <%2$s>', $data['name'], $from_email ); - $headers[] = sprintf( 'Reply-To: %1$s <%2$s>', $data['name'], $data['source'] ); - - // Make sure to pass the title through the normal sharing filters. - $title = $data['sharing_source']->get_share_title( $data['post']->ID ); - - /** - * Filter the Sharing Email Send Post Subject. - * - * @module sharedaddy - * - * @since 5.8.0 - * - * @param string $var Sharing Email Send Post Subject. Default is "Shared Post". - */ - $subject = apply_filters( 'wp_sharing_email_send_post_subject', '[' . __( 'Shared Post', 'jetpack' ) . '] ' . $title ); - - wp_mail( $data['target'], $subject, $content, $headers ); -} - -/** - * Checks for spam using Akismet if available. - * Return $data as it if email about to be send out is not spam. - * - * @param array $data Array of information about the shared message. - * - * @return array $data - * - * @deprecated 11.0 - */ -function sharing_email_check_for_spam_via_akismet( $data ) { - - if ( ! Jetpack::is_akismet_active() ) { - return $data; - } - - // Prepare the body_request for akismet - $body_request = array( - 'blog' => get_option( 'home' ), - 'permalink' => $data['sharing_source']->get_share_url( $data['post']->ID ), - 'comment_type' => 'share', - 'comment_author' => $data['name'], - 'comment_author_email' => $data['source'], - 'comment_content' => sharing_email_send_post_content( $data ), - 'user_agent' => ( isset( $_SERVER['HTTP_USER_AGENT'] ) - ? filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) - : null - ), - ); - - if ( method_exists( 'Akismet', 'http_post' ) ) { - $body_request['user_ip'] = Akismet::get_ip_address(); - $response = Akismet::http_post( build_query( $body_request ), 'comment-check' ); - } else { - global $akismet_api_host, $akismet_api_port; - $body_request['user_ip'] = ( isset( $_SERVER['REMOTE_ADDR'] ) - ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) - : null - ); - $response = akismet_http_post( build_query( $body_request ), $akismet_api_host, '/1.1/comment-check', $akismet_api_port ); - } - - /* - * The Response is spam lets not send the email. - * 'true' is spam - */ - if ( - ! empty( $response ) - && isset( $response[1] ) - && 'true' == trim( $response[1] ) // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- response comes from the Akismet API. - ) { - return false; // don't send the email - } - return $data; -} - -/** - * Content of the emails sent to the target email address. - * - * @param array $data Array of information about the shared message. - * - * @return string $content - * - * @deprecated 11.0 - */ -function sharing_email_send_post_content( $data ) { - $content = sprintf( - /* translators: included in email when post is shared via email. First item is sender's name. Second is sender's email address. */ - __( '%1$s (%2$s) thinks you may be interested in the following post:', 'jetpack' ), - $data['name'], - $data['source'] - ); - $content .= "\n\n"; - // Make sure to pass the title and URL through the normal sharing filters. - $content .= $data['sharing_source']->get_share_title( $data['post']->ID ) . "\n"; - $content .= $data['sharing_source']->get_share_url( $data['post']->ID ) . "\n"; - return $content; -} - /** * Add a meta box to the post editing screen for sharing. * @@ -368,90 +219,6 @@ function sharing_global_resources_save() { update_option( 'sharedaddy_disable_resources', isset( $_POST['disable_resources'] ) ? 1 : 0 ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce handling is handled for all elements at once. } -/** - * Returns the Recaptcha site/public key. - * - * Supports legacy RECAPTCHA_PUBLIC_KEY or RECAPTCHA_SITE_KEY. - * - * @return string - * - * @deprecated 11.0 - */ -function sharing_recaptcha_site_key() { - if ( ! defined( 'RECAPTCHA_PUBLIC_KEY' ) && ! defined( 'RECAPTCHA_SITE_KEY' ) ) { - return ''; - } - - if ( defined( 'RECAPTCHA_PUBLIC_KEY' ) && ! defined( 'RECAPTCHA_SITE_KEY' ) ) { - define( 'RECAPTCHA_SITE_KEY', RECAPTCHA_PUBLIC_KEY ); - } - - return RECAPTCHA_SITE_KEY; -} - -/** - * Returns the Recaptcha private/secret key. - * - * Supports legacy RECAPTCHA_PRIVATE_KEY or RECAPTCHA_SECRET_KEY. - * - * @return string - * - * @deprecated 11.0 - */ -function sharing_recaptcha_secret_key() { - if ( ! defined( 'RECAPTCHA_PRIVATE_KEY' ) && ! defined( 'RECAPTCHA_SECRET_KEY' ) ) { - return ''; - } - - if ( defined( 'RECAPTCHA_PRIVATE_KEY' ) && ! defined( 'RECAPTCHA_SECRET_KEY' ) ) { - define( 'RECAPTCHA_SECRET_KEY', RECAPTCHA_PRIVATE_KEY ); - } - - return RECAPTCHA_SECRET_KEY; -} - -/** - * Contents of a reCAPTCHA box. - * - * @return void - * - * @deprecated 11.0 - */ -function sharing_email_dialog() { - require_once plugin_dir_path( __FILE__ ) . 'recaptcha.php'; - - $recaptcha = new Jetpack_ReCaptcha( - sharing_recaptcha_site_key(), - sharing_recaptcha_secret_key(), - array( 'script_lazy' => true ) - ); - echo $recaptcha->get_recaptcha_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in method. -} - -/** - * Short-circuit the email sharing button based on the results of reCAPTCHA. - * - * @param bool $true Should we check if the message isn't spam. - * @param object $post Post information. - * @param array $data Information about the shared message. - * - * @deprecated 11.0 - */ -function sharing_email_check( $true, $post, $data ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable - require_once plugin_dir_path( __FILE__ ) . 'recaptcha.php'; - - $recaptcha = new Jetpack_ReCaptcha( sharing_recaptcha_site_key(), sharing_recaptcha_secret_key(), array( 'script_lazy' => true ) ); - $response = ! empty( $_POST['g-recaptcha-response'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing -- we do not change anything on the site based on that. - ? filter_var( wp_unslash( $_POST['g-recaptcha-response'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Missing -- we do not change anything on the site based on that. - : ''; - $remote_addr = ! empty( $_SERVER['REMOTE_ADDR'] ) - ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) - : ''; - $result = $recaptcha->verify( $response, $remote_addr ); - - return ( true === $result ); -} - add_action( 'init', 'sharing_init' ); add_action( 'add_meta_boxes', 'sharing_add_meta_box' ); add_action( 'save_post', 'sharing_meta_box_save' );