Нет описания

blog-verification-tools.php 3.4KB

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