| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handles site verification services. |
| 4 |
* |
| 5 |
* @package jetpack |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit( 0 ); |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Return an array of supported verification services. |
| 14 |
* Add new services to this function. |
| 15 |
* |
| 16 |
* @return array - an array of supported services. |
| 17 |
*/ |
| 18 |
function jetpack_verification_services() { |
| 19 |
return array( |
| 20 |
'google' => array( |
| 21 |
'name' => 'Google Search Console', |
| 22 |
'key' => 'google-site-verification', |
| 23 |
'format' => 'dBw5CvburAxi537Rp9qi5uG2174Vb6JwHwIRwPSLIK8', |
| 24 |
'url' => 'https://www.google.com/webmasters/tools/', |
| 25 |
), |
| 26 |
'bing' => array( |
| 27 |
'name' => 'Bing Webmaster Center', |
| 28 |
'key' => 'msvalidate.01', |
| 29 |
'format' => '12C1203B5086AECE94EB3A3D9830B2E', |
| 30 |
'url' => 'https://www.bing.com/toolbox/webmaster/', |
| 31 |
), |
| 32 |
'pinterest' => array( |
| 33 |
'name' => 'Pinterest Site Verification', |
| 34 |
'key' => 'p:domain_verify', |
| 35 |
'format' => 'f100679e6048d45e4a0b0b92dce1efce', |
| 36 |
'url' => 'https://pinterest.com/website/verify/', |
| 37 |
), |
| 38 |
'yandex' => array( |
| 39 |
'name' => 'Yandex.Webmaster', |
| 40 |
'key' => 'yandex-verification', |
| 41 |
'format' => '44d68e1216009f40', |
| 42 |
'url' => 'https://webmaster.yandex.com/sites/', |
| 43 |
), |
| 44 |
'facebook' => array( |
| 45 |
'name' => 'Facebook Domain Verification', |
| 46 |
'key' => 'facebook-domain-verification', |
| 47 |
'format' => 'rvv8b23jxlp1lq41I9rwsvpzncy1fd', |
| 48 |
'url' => 'https://business.facebook.com/settings/', |
| 49 |
), |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Register Jetpack verification settings. |
| 55 |
*/ |
| 56 |
function jetpack_verification_options_init() { |
| 57 |
register_setting( |
| 58 |
'verification_services_codes_fields', |
| 59 |
'verification_services_codes', |
| 60 |
array( 'sanitize_callback' => 'jetpack_verification_validate' ) |
| 61 |
); |
| 62 |
} |
| 63 |
add_action( 'admin_init', 'jetpack_verification_options_init' ); |
| 64 |
add_action( 'rest_api_init', 'jetpack_verification_options_init' ); |
| 65 |
|
| 66 |
/** |
| 67 |
* Print the site verification meta in the page head. |
| 68 |
*/ |
| 69 |
function jetpack_verification_print_meta() { |
| 70 |
$verification_services_codes = Jetpack_Options::get_option_and_ensure_autoload( 'verification_services_codes', '0' ); |
| 71 |
if ( is_array( $verification_services_codes ) ) { |
| 72 |
$ver_output = "<!-- Jetpack Site Verification Tags -->\n"; |
| 73 |
foreach ( jetpack_verification_services() as $name => $service ) { |
| 74 |
if ( is_array( $service ) && ! empty( $verification_services_codes[ "$name" ] ) ) { |
| 75 |
if ( preg_match( '#^<meta name="([a-z0-9_\-.:]+)?" content="([a-z0-9_-]+)?" /?>$#i', $verification_services_codes[ "$name" ], $matches ) ) { |
| 76 |
$verification_code = $matches[2]; |
| 77 |
} else { |
| 78 |
$verification_code = $verification_services_codes[ "$name" ]; |
| 79 |
} |
| 80 |
$ver_tag = sprintf( '<meta name="%s" content="%s">', esc_attr( $service['key'] ), esc_attr( $verification_code ) ); |
| 81 |
/** |
| 82 |
* Filter the meta tag template used for all verification tools. |
| 83 |
* |
| 84 |
* @module verification-tools |
| 85 |
* |
| 86 |
* @since 3.0.0 |
| 87 |
* |
| 88 |
* @param string $ver_tag Verification Tool meta tag. |
| 89 |
*/ |
| 90 |
$ver_output .= apply_filters( 'jetpack_site_verification_output', $ver_tag ); |
| 91 |
$ver_output .= "\n"; |
| 92 |
} |
| 93 |
} |
| 94 |
echo $ver_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 95 |
} |
| 96 |
} |
| 97 |
add_action( 'wp_head', 'jetpack_verification_print_meta', 1 ); |
| 98 |
|