/modules/verification-tools/blog-verification-tools.php

  1. <?php 
  2.  
  3. // Edit here to add new services 
  4. function jetpack_verification_services() { 
  5. return array( 
  6. 'google' => array( 
  7. 'name' =>'Google Webmaster Tools',  
  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' => 'http://www.bing.com/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. ); 
  25.  
  26.  
  27. function jetpack_verification_options_init() { 
  28. register_setting( 'verification_services_codes_fields', 'verification_services_codes', 'jetpack_verification_validate' ); 
  29. add_action( 'admin_init', 'jetpack_verification_options_init' ); 
  30.  
  31. function jetpack_verification_print_meta() { 
  32. $verification_services_codes = get_option( 'verification_services_codes' ); 
  33. if ( is_array( $verification_services_codes ) ) { 
  34. $ver_output = "<!-- Jetpack Site Verification Tags -->\n"; 
  35. foreach ( jetpack_verification_services() as $name => $service ) { 
  36. if ( is_array( $service ) && !empty( $verification_services_codes["$name"] ) ) { 
  37. $ver_tag = sprintf( '<meta name="%s" content="%s" />', esc_attr( $service["key"] ), esc_attr( $verification_services_codes["$name"] ) ); 
  38. /** 
  39. * Filter the meta tag template used for all verification tools. 
  40. * 
  41. * @since 3.0.0 
  42. * 
  43. * @param string $ver_tag Verification Tool meta tag. 
  44. */ 
  45. $ver_output .= apply_filters( 'jetpack_site_verification_output', $ver_tag ); 
  46. $ver_output .= "\n"; 
  47. echo $ver_output; 
  48. add_action( 'wp_head', 'jetpack_verification_print_meta', 1 ); 
  49.  
  50. function jetpack_verification_get_code( $code ) { 
  51. $pattern = '/content=["\']?([^"\' ]*)["\' ]/is'; 
  52. preg_match( $pattern, $code, $match ); 
  53. if ( $match ) { 
  54. return urldecode( $match[1] ); 
  55. } else { 
  56. return false; 
  57.  
  58. function jetpack_verification_validate( $verification_services_codes ) { 
  59. foreach ( $verification_services_codes as $key => &$code ) { 
  60. // Parse html meta tags if present 
  61. if ( stripos( $code, 'meta' ) ) 
  62. $code = jetpack_verification_get_code( $code ); 
  63.  
  64. $code = esc_attr( trim( $code ) ); 
  65.  
  66. // limit length to 100 chars. 
  67. $code = substr( $code, 0, 100 ); 
  68.  
  69. /** 
  70. * Fire after each Verification code was validated. 
  71. * 
  72. * @since 3.0.0 
  73. * 
  74. * @param string $key Verification service name. 
  75. * @param string $code Verification service code provided in field in the Tools menu. 
  76. */ 
  77. do_action( 'jetpack_site_verification_validate', $key, $code ); 
  78. return $verification_services_codes; 
  79.  
  80. function jetpack_verification_options_form() { 
  81. $verification_services_codes = get_option( 'verification_services_codes' ); 
  82. ?> 
  83. <form method="post" action="options.php"> 
  84. <?php settings_fields( 'verification_services_codes_fields' ); ?> 
  85. <div class="tools-container"> 
  86. <?php 
  87. foreach ( jetpack_verification_services() as $key => $service ) { 
  88. echo "<div class='jp-verification-service'> 
  89. <h4>" . esc_html( $service['name'] ) . "</h4> 
  90. <input value='" . esc_attr( $verification_services_codes["$key"] ) . "' name='verification_services_codes[" . esc_attr( $key ) . "]' type='text' /> 
  91. <small> 
  92. <label for='verification_services_codes[" . esc_attr( $key ) . "]'>" . esc_html( __( 'Example:' , 'jetpack' ) ) . " <span><meta name='" . esc_attr( $service['key'] ) . "' content='<strong>" . esc_attr( $service['format'] ) . "</strong>'></span></label> 
  93. </small> 
  94. </div>"; 
  95. ?> 
  96. </div> 
  97. <p class="submit"> 
  98. <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' , 'jetpack' ); ?>" /> 
  99. </p> 
  100. </form> 
  101.  
  102. <style> 
  103. /* Jetpack styles aren't loaded in the tools section of the admin, let's save on some http requests and just do an inline block */ 
  104.  
  105. .jp-verification-tools h3 a { 
  106. text-decoration: none; 
  107.  
  108. .jp-verification-service { 
  109. border-bottom: 1px #f1f1f1 solid; 
  110. padding-bottom: 20px; 
  111.  
  112. .jp-verification-service input[type="text"] { 
  113. width: 100%; 
  114. margin-bottom: 10px; 
  115.  
  116. .jp-verification-service label { 
  117. font-size: 13px; 
  118.  
  119. /* mimic 'code' tag style, but this allows for better visuals + line breaks on mobile devices */ 
  120. .jp-verification-service span { 
  121. display: block; 
  122. margin-top: 5px; 
  123. font-size: 14px; 
  124. padding: 10px; 
  125. background: #f1f1f1; 
  126. font-family: monospace; 
  127. word-wrap: break-word; 
  128.  
  129. .jp-verification-service strong { 
  130. font-weight: bold; 
  131. </style> 
  132.  
  133. <?php 
  134.  
  135. function jetpack_verification_tool_box() { 
  136. global $current_user; 
  137.  
  138. /** 
  139. * Decide whether Site Verification tools be added to the Tools menu. 
  140. * 
  141. * @since 3.0.0 
  142. * 
  143. * @param bool true Should the Site Verification tools be added to the Tools menu. 
  144. */ 
  145. if ( ! apply_filters( 'jetpack_enable_site_verification', true ) ) 
  146. return; 
  147.  
  148. $list = array(); 
  149. foreach ( jetpack_verification_services() as $key => $service ) { 
  150. $list[] = '<a href="' . esc_url( $service['url'] ) . '">' . esc_html( $service['name'] ) . '</a>'; 
  151. $last = array_pop( $list ); 
  152.  
  153. if ( current_user_can( 'manage_options' ) ) { 
  154. echo '<div class="jp-verification-tools card"><h3 class="title">' . __( 'Website Verification Services' , 'jetpack' ) . ' <a href="http://support.wordpress.com/webmaster-tools/" target="_blank">(?)</a></h3>'; 
  155. echo '<p>' . sprintf( esc_html( __( 'Enter your meta key "content" value to verify your blog with %s' , 'jetpack' ) ), implode( ', ', $list ) ) . ' ' . __( 'and' , 'jetpack' ) . ' ' . $last . '.</p>'; 
  156. jetpack_verification_options_form(); 
  157. echo '</div>'; 
  158. add_action( 'tool_box', 'jetpack_verification_tool_box', 25 ); 
.