| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* Helper functions that are called from API even when module is inactive should be added here. |
| 5 |
* This file will be included in module-extras.php. |
| 6 |
*/ |
| 7 |
|
| 8 |
function jetpack_verification_validate( $verification_services_codes ) { |
| 9 |
foreach ( $verification_services_codes as $key => $code ) { |
| 10 |
// Parse html meta tag if it does not look like a valid code |
| 11 |
if ( ! preg_match( '/^[a-z0-9_-]+$/i', $code ) ) { |
| 12 |
$code = jetpack_verification_get_code( $code ); |
| 13 |
} |
| 14 |
|
| 15 |
$code = esc_attr( trim( $code ) ); |
| 16 |
|
| 17 |
// limit length to 100 chars. |
| 18 |
$code = substr( $code, 0, 100 ); |
| 19 |
|
| 20 |
/** |
| 21 |
* Fire after each Verification code was validated. |
| 22 |
* |
| 23 |
* @module verification-tools |
| 24 |
* |
| 25 |
* @since 3.0.0 |
| 26 |
* |
| 27 |
* @param string $key Verification service name. |
| 28 |
* @param string $code Verification service code provided in field in the Tools menu. |
| 29 |
*/ |
| 30 |
do_action( 'jetpack_site_verification_validate', $key, $code ); |
| 31 |
|
| 32 |
$verification_services_codes[ $key ] = $code; |
| 33 |
} |
| 34 |
return $verification_services_codes; |
| 35 |
} |
| 36 |
|
| 37 |
function jetpack_verification_get_code( $code ) { |
| 38 |
$pattern = '/content=["\']?([^"\' ]*)["\' ]/is'; |
| 39 |
preg_match( $pattern, $code, $match ); |
| 40 |
if ( $match ) { |
| 41 |
return urldecode( $match[1] ); |
| 42 |
} else { |
| 43 |
return false; |
| 44 |
} |
| 45 |
} |
| 46 |
|