PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.1.2
Jetpack – WP Security, Backup, Speed, & Growth v6.1.2
16.2-beta 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 All 501 releases
jetpack / modules / shortcodes / medium.php

medium.php in Jetpack – WP Security, Backup, Speed, & Growth 6.1.2, at modules/shortcodes/medium.php

68 lines 1.9 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 } else if ( 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( array(
62 'url' => '',
63 'width' => '400',
64 'border' => true,
65 'collapsed' => false,
66 ), $atts, 'medium' );
67 }
68