Completed
Push — fix/block-vr ( dd4d13...b6c320 )
by Bernhard
196:37 queued 183:38
created

blog-verification-tools.php ➔ jetpack_verification_tool_box()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
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
		'yandex'    => array(
25
			'name'   => 'Yandex.Webmaster',
26
			'key'    => 'yandex-verification',
27
			'format' => '44d68e1216009f40',
28
			'url'    => 'https://webmaster.yandex.com/sites/',
29
		),
30
	);
31
}
32
33
function jetpack_verification_options_init() {
34
	register_setting(
35
		'verification_services_codes_fields',
36
		'verification_services_codes',
37
		array( 'sanitize_callback' => 'jetpack_verification_validate' )
38
	);
39
}
40
add_action( 'admin_init', 'jetpack_verification_options_init' );
41
add_action( 'rest_api_init', 'jetpack_verification_options_init' );
42
43
function jetpack_verification_print_meta() {
44
	$verification_services_codes = Jetpack_Options::get_option_and_ensure_autoload( 'verification_services_codes', '0' );
45
	if ( is_array( $verification_services_codes ) ) {
46
		$ver_output = "<!-- Jetpack Site Verification Tags -->\n";
47
		foreach ( jetpack_verification_services() as $name => $service ) {
48
			if ( is_array( $service ) && ! empty( $verification_services_codes[ "$name" ] ) ) {
49
				if ( preg_match( '#^<meta name="([a-z0-9_\-.:]+)?" content="([a-z0-9_-]+)?" />$#i', $verification_services_codes[ "$name" ], $matches ) ) {
50
					$verification_code = $matches[2];
51
				} else {
52
					$verification_code = $verification_services_codes[ "$name" ];
53
				}
54
				$ver_tag = sprintf( '<meta name="%s" content="%s" />', esc_attr( $service['key'] ), esc_attr( $verification_code ) );
55
				/**
56
				 * Filter the meta tag template used for all verification tools.
57
				 *
58
				 * @module verification-tools
59
				 *
60
				 * @since 3.0.0
61
				 *
62
				 * @param string $ver_tag Verification Tool meta tag.
63
				 */
64
				$ver_output .= apply_filters( 'jetpack_site_verification_output', $ver_tag );
65
				$ver_output .= "\n";
66
			}
67
		}
68
		echo $ver_output;
69
	}
70
}
71
add_action( 'wp_head', 'jetpack_verification_print_meta', 1 );
72
73
function jetpack_verification_tool_box() {
74
	?>
75
		<div class="jp-verification-tools card">
76
			<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>
77
			<p>
78
				<?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' ) ) ); ?>
79
			</p>
80
		</div>
81
	<?php
82
}
83
84
add_action( 'tool_box', 'jetpack_verification_tool_box', 25 );
85