Completed
Push — add/jetpack-options-tests-file ( 8ce060...d6f196 )
by
unknown
07:49
created

verification-tools-utils.php ➔ jetpack_verification_validate()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Helper functions that are called from API even when module is inactive should be added here.
5
 * This file will be included in module-extras.php.
6
 */
7
8
function jetpack_verification_validate( $verification_services_codes ) {
9
	foreach ( $verification_services_codes as $key => &$code ) {
10
		// Parse html meta tags if present
11
		if ( stripos( $code, 'meta' ) )
12
			$code = jetpack_verification_get_code( $code );
13
14
		$code = esc_attr( trim( $code ) );
15
16
		// limit length to 100 chars.
17
		$code = substr( $code, 0, 100 );
18
19
		/**
20
		 * Fire after each Verification code was validated.
21
		 *
22
		 * @module verification-tools
23
		 *
24
		 * @since 3.0.0
25
		 *
26
		 * @param string $key Verification service name.
27
		 * @param string $code Verification service code provided in field in the Tools menu.
28
		 */
29
		do_action( 'jetpack_site_verification_validate', $key, $code );
30
	}
31
	return $verification_services_codes;
32
}
33
34
function jetpack_verification_get_code( $code ){
35
	$pattern = '/content=["\']?([^"\' ]*)["\' ]/is';
36
	preg_match( $pattern, $code, $match );
37
	if ( $match ){
0 ignored issues
show
Bug Best Practice introduced by
The expression $match of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
38
		return urldecode( $match[1] );
39
	} else {
40
		return false;
41
	}
42
}
43