Completed
Push — deprecate/google-plus-shortcod... ( f485e4 )
by
unknown
07:43
created

googleplus.php ➔ jetpack_googleplus_embed_handler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Google+ embeds
5
 * Google+ has shut down. Output the link for history's sake.
6
 * Other than that, there's not much we can do.
7
 */
8
9
define( 'JETPACK_GOOGLEPLUS_EMBED_REGEX', '#^https?://plus\.(sandbox\.)?google\.com/(u/\d+/)?([^/]+)/posts/([^/]+)$#' );
10
11
// Example URL: https://plus.google.com/114986219448604314131/posts/LgHkesWCmJo
12
// Alternate example: https://plus.google.com/u/0/100004581596612508203/posts/2UKwN67MBQs  (note the /u/0/)
13
wp_embed_register_handler( 'googleplus', JETPACK_GOOGLEPLUS_EMBED_REGEX, 'jetpack_deprecated_embed_handler' );
14
15
add_shortcode( 'googleplus', 'jetpack_googleplus_shortcode_handler' );
16
17
function jetpack_googleplus_shortcode_handler( $atts ) {
18
	global $wp_embed;
19
20
	if ( empty( $atts['url'] ) ) {
21
		return;
22
	}
23
24
	if ( ! preg_match( JETPACK_GOOGLEPLUS_EMBED_REGEX, $atts['url'] ) ) {
25
		return;
26
	}
27
28
	return sprintf( '<p>%s</p>', $wp_embed->shortcode( $atts, $atts['url'] ) );
29
}
30