| 1 |
<?php |
| 2 |
/** |
| 3 |
* Helper functions that are called from API even when module is inactive should be added here. |
| 4 |
* This file will be included in module-extras.php. |
| 5 |
* |
| 6 |
* @package jetpack |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! function_exists( 'jetpack_verification_validate' ) ) { |
| 10 |
/** |
| 11 |
* Validate jetpack verification codes. |
| 12 |
* |
| 13 |
* @param array $verification_services_codes - array of verification codes. |
| 14 |
*/ |
| 15 |
function jetpack_verification_validate( $verification_services_codes ) { |
| 16 |
foreach ( $verification_services_codes as $key => $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 |
} |
| 21 |
|
| 22 |
$code = esc_attr( trim( $code ) ); |
| 23 |
|
| 24 |
// limit length to 100 chars. |
| 25 |
$code = substr( $code, 0, 100 ); |
| 26 |
|
| 27 |
/** |
| 28 |
* Fire after each Verification code was validated. |
| 29 |
* |
| 30 |
* @module verification-tools |
| 31 |
* |
| 32 |
* @since 3.0.0 |
| 33 |
* |
| 34 |
* @param string $key Verification service name. |
| 35 |
* @param string $code Verification service code provided in field in the Tools menu. |
| 36 |
*/ |
| 37 |
do_action( 'jetpack_site_verification_validate', $key, $code ); |
| 38 |
|
| 39 |
$verification_services_codes[ $key ] = $code; |
| 40 |
} |
| 41 |
return $verification_services_codes; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
if ( ! function_exists( 'jetpack_verification_get_code' ) ) { |
| 46 |
/** |
| 47 |
* Return the code we're trying to verify after decoding. |
| 48 |
* |
| 49 |
* @param string $code - the code we need to parse. |
| 50 |
*/ |
| 51 |
function jetpack_verification_get_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 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|