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 | modules/verification-tools/verification-tools-utils.php +18 -74 16.3-a.316.3-a.1 View file →
@@ -5,75 +5,26 @@
5 5 *
6 6 * @package jetpack
7 7 */
8 8
9 -if ( ! function_exists( 'jetpack_verification_extract_code' ) ) {
9 +if ( ! function_exists( 'jetpack_verification_validate' ) ) {
10 10 /**
11 - * Extract a site verification code from a meta tag.
12 - *
13 - * @since 16.3
14 - *
15 - * @param string $code Verification meta tag.
16 - * @return string|false Extracted code, or false when none is found.
17 - */
18 - function jetpack_verification_extract_code( $code ) {
19 - $pattern = '/content=["\']?([^"\' ]*)["\' ]/is';
20 - preg_match( $pattern, $code, $match );
21 -
22 - return $match ? rawurldecode( $match[1] ) : false;
23 - }
24 -}
25 -
26 -if ( ! function_exists( 'jetpack_verification_validate_code' ) ) {
27 - /**
28 - * Validate and normalize a site verification code.
29 - *
30 - * @since 16.3
31 - *
32 - * @param mixed $code Verification code or meta tag.
33 - * @return string|false Normalized code, or false when invalid.
34 - */
35 - function jetpack_verification_validate_code( $code ) {
36 - if ( ! is_scalar( $code ) ) {
37 - return false;
38 - }
39 -
40 - // Allow printable ASCII except characters that can delimit HTML attributes or tags.
41 - $code_pattern = '/^(?!.*[<>"\'])[!-~]+$/';
42 - $code = trim( (string) $code );
43 -
44 - if ( '' === $code ) {
45 - return '';
46 - }
47 -
48 - // Parse html meta tag if it does not look like a valid code.
49 - if ( ! preg_match( $code_pattern, $code ) ) {
50 - $code = jetpack_verification_extract_code( $code );
51 - }
52 -
53 - $code = trim( (string) $code );
54 - if ( '' === $code || ! preg_match( $code_pattern, $code ) ) {
55 - return false;
56 - }
57 -
58 - return substr( $code, 0, 100 );
59 - }
60 -}
61 -
62 -if ( ! function_exists( 'jetpack_verification_validate_codes' ) ) {
63 - /**
64 11 * Validate jetpack verification codes.
65 12 *
66 - * @since 16.3
67 - *
68 13 * @param array $verification_services_codes - array of verification codes.
69 - * @return array Validated verification codes.
70 14 */
71 - function jetpack_verification_validate_codes( $verification_services_codes ) {
15 + function jetpack_verification_validate( $verification_services_codes ) {
72 16 foreach ( $verification_services_codes as $key => $code ) {
73 - $code = jetpack_verification_validate_code( $code );
74 - $code = false === $code ? '' : $code;
17 + // Parse html meta tag if it does not look like a valid code.
18 + if ( ! preg_match( '/^[a-z0-9_-]+$/i', $code ) ) {
19 + $code = jetpack_verification_get_code( $code );
20 + }
75 21
22 + $code = esc_attr( trim( $code ) );
23 +
24 + // limit length to 100 chars.
25 + $code = substr( $code, 0, 100 );
26 +
76 27 /**
77 28 * Fire after each Verification code was validated.
78 29 *
79 30 * @module verification-tools
@@ -90,27 +41,20 @@
90 41 return $verification_services_codes;
91 42 }
92 43 }
93 44
94 -if ( ! function_exists( 'jetpack_verification_validate' ) ) {
95 - /**
96 - * Validate jetpack verification codes.
97 - *
98 - * @param array $verification_services_codes - array of verification codes.
99 - * @return array Validated verification codes.
100 - */
101 - function jetpack_verification_validate( $verification_services_codes ) {
102 - return jetpack_verification_validate_codes( $verification_services_codes );
103 - }
104 -}
105 -
106 45 if ( ! function_exists( 'jetpack_verification_get_code' ) ) {
107 46 /**
108 47 * Return the code we're trying to verify after decoding.
109 48 *
110 49 * @param string $code - the code we need to parse.
111 - * @return string|false Extracted code, or false when none is found.
112 50 */
113 51 function jetpack_verification_get_code( $code ) {
114 - return jetpack_verification_extract_code( $code );
52 + $pattern = '/content=["\']?([^"\' ]*)["\' ]/is';
53 + preg_match( $pattern, $code, $match );
54 + if ( $match ) {
55 + return urldecode( $match[1] );
56 + } else {
57 + return false;
58 + }
115 59 }
116 60 }