Completed
Push — try/rlt-proxy ( 0254cd...38d230 )
by
unknown
394:47 queued 384:54
created

jetpack-likes-master-iframe.php ➔ jetpack_likes_master_iframe()   C

Complexity

Conditions 12
Paths 196

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
nc 196
nop 0
dl 0
loc 37
rs 6.1666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This function needs to get loaded after the like scripts get added to the page.
5
 */
6
function jetpack_likes_master_iframe() {
7
	$version = gmdate( 'YW' );
8
	$in_jetpack = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? false : true;
9
10
	$_locale = get_locale();
11
12
	// We have to account for w.org vs WP.com locale divergence
13
	if ( $in_jetpack ) {
14
		if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
15
			return false;
16
		}
17
18
		require_once JETPACK__GLOTPRESS_LOCALES_PATH;
19
20
		$gp_locale = GP_Locales::by_field( 'wp_locale', $_locale );
21
		$_locale = isset( $gp_locale->slug ) ? $gp_locale->slug : '';
22
	}
23
24
	$likes_locale = ( '' == $_locale || 'en' == $_locale ) ? '' : '&amp;lang=' . strtolower( $_locale );
25
26
	$protocol = is_ssl() ? 'https' : 'http';
27
	$origin   = isset( $_SERVER['HTTP_HOST'] ) ? "$protocol://" . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : null;
28
29
	$src = sprintf(
30
		'https://widgets.wp.com/likes/master.html?ver=%1$s#ver=%1$s%2$s%3$s',
31
		$version,
32
		$likes_locale,
33
		$origin ? '&amp;origin=' . $origin : ''
34
	);
35
36
	/* translators: The value of %d is not available at the time of output */
37
	$likersText = wp_kses( __( '<span>%d</span> bloggers like this:', 'jetpack' ), array( 'span' => array() ) );
38
	?>
39
	<iframe src='<?php echo $src; ?>' scrolling='no' id='likes-master' name='likes-master' style='display:none;'></iframe>
40
	<div id='likes-other-gravatars'><div class="likes-text"><?php echo $likersText; ?></div><ul class="wpl-avatars sd-like-gravatars"></ul></div>
41
	<?php
42
}
43