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