blog-verification-tools.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | use Automattic\Jetpack\Redirect; |
| 4 | |
| 5 | // Edit here to add new services |
| 6 | function jetpack_verification_services() { |
| 7 | return array( |
| 8 | 'google' => array( |
| 9 | 'name' => 'Google Search Console', |
| 10 | 'key' => 'google-site-verification', |
| 11 | 'format' => 'dBw5CvburAxi537Rp9qi5uG2174Vb6JwHwIRwPSLIK8', |
| 12 | 'url' => 'https://www.google.com/webmasters/tools/', |
| 13 | ), |
| 14 | 'bing' => array( |
| 15 | 'name' => 'Bing Webmaster Center', |
| 16 | 'key' => 'msvalidate.01', |
| 17 | 'format' => '12C1203B5086AECE94EB3A3D9830B2E', |
| 18 | 'url' => 'https://www.bing.com/toolbox/webmaster/', |
| 19 | ), |
| 20 | 'pinterest' => array( |
| 21 | 'name' => 'Pinterest Site Verification', |
| 22 | 'key' => 'p:domain_verify', |
| 23 | 'format' => 'f100679e6048d45e4a0b0b92dce1efce', |
| 24 | 'url' => 'https://pinterest.com/website/verify/', |
| 25 | ), |
| 26 | 'yandex' => array( |
| 27 | 'name' => 'Yandex.Webmaster', |
| 28 | 'key' => 'yandex-verification', |
| 29 | 'format' => '44d68e1216009f40', |
| 30 | 'url' => 'https://webmaster.yandex.com/sites/', |
| 31 | ), |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | function jetpack_verification_options_init() { |
| 36 | register_setting( |
| 37 | 'verification_services_codes_fields', |
| 38 | 'verification_services_codes', |
| 39 | array( 'sanitize_callback' => 'jetpack_verification_validate' ) |
| 40 | ); |
| 41 | } |
| 42 | add_action( 'admin_init', 'jetpack_verification_options_init' ); |
| 43 | add_action( 'rest_api_init', 'jetpack_verification_options_init' ); |
| 44 | |
| 45 | function jetpack_verification_print_meta() { |
| 46 | $verification_services_codes = Jetpack_Options::get_option_and_ensure_autoload( 'verification_services_codes', '0' ); |
| 47 | if ( is_array( $verification_services_codes ) ) { |
| 48 | $ver_output = "<!-- Jetpack Site Verification Tags -->\n"; |
| 49 | foreach ( jetpack_verification_services() as $name => $service ) { |
| 50 | if ( is_array( $service ) && ! empty( $verification_services_codes[ "$name" ] ) ) { |
| 51 | if ( preg_match( '#^<meta name="([a-z0-9_\-.:]+)?" content="([a-z0-9_-]+)?" />$#i', $verification_services_codes[ "$name" ], $matches ) ) { |
| 52 | $verification_code = $matches[2]; |
| 53 | } else { |
| 54 | $verification_code = $verification_services_codes[ "$name" ]; |
| 55 | } |
| 56 | $ver_tag = sprintf( '<meta name="%s" content="%s" />', esc_attr( $service['key'] ), esc_attr( $verification_code ) ); |
| 57 | /** |
| 58 | * Filter the meta tag template used for all verification tools. |
| 59 | * |
| 60 | * @module verification-tools |
| 61 | * |
| 62 | * @since 3.0.0 |
| 63 | * |
| 64 | * @param string $ver_tag Verification Tool meta tag. |
| 65 | */ |
| 66 | $ver_output .= apply_filters( 'jetpack_site_verification_output', $ver_tag ); |
| 67 | $ver_output .= "\n"; |
| 68 | } |
| 69 | } |
| 70 | echo $ver_output; |
| 71 | } |
| 72 | } |
| 73 | add_action( 'wp_head', 'jetpack_verification_print_meta', 1 ); |
| 74 | |
| 75 | function jetpack_verification_tool_box() { |
| 76 | ?> |
| 77 | <div class="jp-verification-tools card"> |
| 78 | <h3 class="title"><?php esc_html_e( 'Website Verification Services', 'jetpack' ); ?> <a href="<?php echo esc_url( Redirect::get_url( 'jetpack-support-site-verification-tools' ) ); ?>" rel="noopener noreferrer" target="_blank">(?)</a></h3> |
| 79 | <p> |
| 80 | <?php printf( __( 'You can verify your site using the <a href="%s">"Site verification" tool in Jetpack Settings</a>.', 'jetpack' ), esc_url( admin_url( 'admin.php?page=jetpack#/traffic' ) ) ); ?> |
| 81 | </p> |
| 82 | </div> |
| 83 | <?php |
| 84 | } |
| 85 | |
| 86 | add_action( 'tool_box', 'jetpack_verification_tool_box', 25 ); |
| 87 |