PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.2.1
Jetpack – WP Security, Backup, Speed, & Growth v7.2.1
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / modules / shortcodes / medium.php
medium.php
72 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Embed support for Medium https://medium.com/p/3eaed64aed8a
4
5 /**
6 * Faux-oembed support for Medium permalinks
7 *
8 * e.g.
9 * https://medium.com/help-center
10 * https://medium.com/@richroll
11 */
12 wp_embed_register_handler( 'medium', '#^https?://medium.com/([a-zA-z0-9-_@]+)#', 'jetpack_embed_medium_oembed' );
13
14 function jetpack_embed_medium_oembed( $matches, $attr, $url ) {
15 $attr = jetpack_embed_medium_args( $attr );
16 $attr['url'] = $url;
17
18 return jetpack_embed_medium_embed_html( $attr );
19 }
20
21 function jetpack_embed_medium_embed_html( $args ) {
22 $args = jetpack_embed_medium_args( $args );
23
24 if ( empty( $args['url'] ) ) {
25 return;
26 }
27
28 $args['type'] = jetpack_embed_medium_get_embed_type( $args['url'] );
29
30 return sprintf( '<script async src="https://static.medium.com/embed.js"></script><a class="m-%1$s" href="%2$s" target="_blank" data-width="%3$s" data-border="%4$s" data-collapsed="%5$s">View %1$s at Medium.com</a>', esc_attr( $args['type'] ), esc_url( $args['url'] ), esc_attr( $args['width'] ), esc_attr( $args['border'] ), esc_attr( $args['collapsed'] ) );
31 }
32
33 /**
34 * Shortcode support that allows passing in URL
35 *
36 * [medium url="https://medium.com/help-center" width="100%" border="false" collapsed="true"]
37 */
38 add_shortcode( 'medium', 'jetpack_embed_medium_shortcode' );
39
40 function jetpack_embed_medium_shortcode( $atts ) {
41 $atts = jetpack_embed_medium_args( $atts );
42
43 if ( ! empty( $atts['url'] ) ) {
44 global $wp_embed;
45 return $wp_embed->shortcode( $atts, $atts['url'] );
46 }
47 }
48
49 function jetpack_embed_medium_get_embed_type( $url ) {
50 $url_path = parse_url( $url, PHP_URL_PATH );
51 if ( preg_match( '/^\/@[\.\w]+$/', $url_path ) ) {
52 return 'profile';
53 } elseif ( preg_match( '/^\/[\da-zA-Z-]+$/', $url_path ) ) {
54 return 'collection';
55 }
56
57 return 'story';
58 }
59
60 function jetpack_embed_medium_args( $atts ) {
61 return shortcode_atts(
62 array(
63 'url' => '',
64 'width' => '400',
65 'border' => true,
66 'collapsed' => false,
67 ),
68 $atts,
69 'medium'
70 );
71 }
72