blog-verification-tools.php 3.0 KB

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