Completed
Push — fix/visibility-condition-issue... ( eee6fd...a71c15 )
by
unknown
11:07
created

googleplus.php ➔ jetpack_googleplus_add_script()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Google+ embeds
5
 */
6
7
define( 'JETPACK_GOOGLEPLUS_EMBED_REGEX', '#^https?://plus\.(sandbox\.)?google\.com/(u/\d+/)?([^/]+)/posts/([^/]+)$#' );
8
9
// Example URL: https://plus.google.com/114986219448604314131/posts/LgHkesWCmJo
10
// Alternate example: https://plus.google.com/u/0/100004581596612508203/posts/2UKwN67MBQs  (note the /u/0/)
11
wp_embed_register_handler( 'googleplus', JETPACK_GOOGLEPLUS_EMBED_REGEX, 'jetpack_googleplus_embed_handler' );
12
13
function jetpack_googleplus_embed_handler( $matches, $attr, $url ) {
0 ignored issues
show
Unused Code introduced by
The parameter $matches is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $attr is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
	wp_enqueue_script( 'jetpack-gplus-api', 'https://apis.google.com/js/plusone.js', array(), null, true );
15
	return sprintf( '<div class="g-post" data-href="%s"></div>', esc_url( $url ) );
16
}
17
18
add_shortcode( 'googleplus', 'jetpack_googleplus_shortcode_handler' );
19
20
function jetpack_googleplus_shortcode_handler( $atts ) {
21
	global $wp_embed;
22
23
	if ( empty( $atts['url'] ) )
24
		return;
25
26
	if ( ! preg_match( JETPACK_GOOGLEPLUS_EMBED_REGEX, $atts['url'] ) )
27
		return;
28
29
	return $wp_embed->shortcode( $atts, $atts['url'] );
30
}
31