summaryrefslogtreecommitdiff
blob: f8b4b4a53ffbcda23abc8555d99ee646f35f0e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php

// Edit here to add new services
function jetpack_verification_services() {
	return array(
			'google' => array(
			'name'   =>'Google Search Console',
			'key'    =>'google-site-verification',
			'format' =>'dBw5CvburAxi537Rp9qi5uG2174Vb6JwHwIRwPSLIK8',
			'url'    => 'https://www.google.com/webmasters/tools/',
		),
		'bing' => array(
			'name'   =>'Bing Webmaster Center',
			'key'    =>'msvalidate.01',
			'format' =>'12C1203B5086AECE94EB3A3D9830B2E',
			'url'    => 'http://www.bing.com/webmaster/',
		 ),
		'pinterest' => array(
			'name'   => 'Pinterest Site Verification',
			'key'    => 'p:domain_verify',
			'format' => 'f100679e6048d45e4a0b0b92dce1efce',
			'url'    => 'https://pinterest.com/website/verify/',
		),
		'yandex'     => array(
			'name'   => 'Yandex.Webmaster',
			'key'    => 'yandex-verification',
			'format' => '44d68e1216009f40',
			'url'    => 'https://webmaster.yandex.com/sites/',
		),
	);
}


function jetpack_verification_options_init() {
	register_setting( 'verification_services_codes_fields', 'verification_services_codes', 'jetpack_verification_validate' );
}
add_action( 'admin_init', 'jetpack_verification_options_init' );

function jetpack_verification_print_meta() {
	$verification_services_codes =  Jetpack_Options::get_option_and_ensure_autoload( 'verification_services_codes', '0' );
	if ( is_array( $verification_services_codes ) ) {
		$ver_output = "<!-- Jetpack Site Verification Tags -->\n";
		foreach ( jetpack_verification_services() as $name => $service ) {
			if ( is_array( $service ) && !empty( $verification_services_codes["$name"] ) ) {
				if ( preg_match( '#^<meta name="([a-z0-9_\-.:]+)?" content="([a-z0-9_-]+)?" />$#i', $verification_services_codes["$name"], $matches ) ) {
					$verification_code = $matches[2];
				} else {
					$verification_code = $verification_services_codes["$name"];
				}
				$ver_tag = sprintf( '<meta name="%s" content="%s" />', esc_attr( $service["key"] ), esc_attr( $verification_code ) );
				/**
				 * Filter the meta tag template used for all verification tools.
				 *
				 * @module verification-tools
				 *
				 * @since 3.0.0
				 *
				 * @param string $ver_tag Verification Tool meta tag.
				 */
				$ver_output .= apply_filters( 'jetpack_site_verification_output', $ver_tag );
				$ver_output .= "\n";
			}
		}
	echo $ver_output;
	}
}
add_action( 'wp_head', 'jetpack_verification_print_meta', 1 );

function jetpack_verification_options_form() {
	$verification_services_codes = get_option( 'verification_services_codes' );
	?>
<form method="post" action="options.php">
	<?php settings_fields( 'verification_services_codes_fields' ); ?>
	<div class="tools-container">
	<?php
	foreach ( jetpack_verification_services() as $key => $service ) {
		echo "<div class='jp-verification-service'>
				<h4>" . esc_html( $service['name'] ) . "</h4>
					<input value='" . esc_attr( isset( $verification_services_codes[ $key ] ) ? $verification_services_codes[ $key ] : '' ) . "' name='verification_services_codes[" . esc_attr( $key ) . "]' type='text' />
				<small>
					<label for='verification_services_codes[" . esc_attr( $key ) . "]'>" . esc_html( __( 'Example:' , 'jetpack' ) ) . " <span>&lt;meta name='" . esc_attr( $service['key'] ) . "' content='<strong>" . esc_attr( $service['format'] ) . "</strong>'&gt;</span></label>
				</small>
			</div>";
	}
	?>
	</div>
	<p class="submit">
		<input type="submit" class="button-primary" value="<?php _e( 'Save Changes' , 'jetpack' ); ?>" />
	</p>
</form>

<style>
/*  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 */

	.jp-verification-tools h3 a {
		text-decoration: none;
	}

	.jp-verification-service {
		border-bottom: 1px #f1f1f1 solid;
		padding-bottom: 20px;
	}

	.jp-verification-service input[type="text"] {
		width: 100%;
		margin-bottom: 10px;
	}

	.jp-verification-service label {
		font-size: 13px;
	}

	/* mimic 'code' tag style, but this allows for better visuals + line breaks on mobile devices */
	.jp-verification-service span {
		display: block;
		margin-top: 5px;
		font-size: 14px;
		padding: 10px;
		background: #f1f1f1;
		font-family: monospace;
		word-wrap: break-word;
	}

	.jp-verification-service strong {
		font-weight: bold;
	}
</style>

<?php
}

function jetpack_verification_tool_box() {
	global $current_user;

	/**
	 * Decide whether Site Verification tools be added to the Tools menu.
	 *
	 * @module verification-tools
	 *
	 * @since 3.0.0
	 *
	 * @param bool true Should the Site Verification tools be added to the Tools menu.
	 */
	if ( ! apply_filters( 'jetpack_enable_site_verification', true ) )
		return;

	$list = array();
	foreach ( jetpack_verification_services() as $key => $service ) {
		$list[] = '<a href="' . esc_url( $service['url'] ) . '">' . esc_html( $service['name'] ) . '</a>';
	}
	$last = array_pop( $list );

	if ( current_user_can( 'manage_options' ) ) {
		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>';
		echo '<p>' . sprintf( esc_html( __( 'Enter your meta key "content" value to verify your blog with %s' , 'jetpack' ) ), implode( ', ', $list ) ) . ' ' . __( 'and' , 'jetpack' ) . ' ' . $last . '.</p>';
		jetpack_verification_options_form();
		echo '</div>';
	}
}
add_action( 'tool_box', 'jetpack_verification_tool_box', 25 );