Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: medium.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Embed support for Medium
[2] Fix | Delete
*
[3] Fix | Delete
* Supported formats:
[4] Fix | Delete
* - Profiles: https://medium.com/@jeherve
[5] Fix | Delete
* - Stories: https://medium.com/@jeherve/this-is-a-story-19f582daaf5b
[6] Fix | Delete
* - And all the above in shortcode formats:
[7] Fix | Delete
* [medium url="https://medium.com/@jeherve/this-is-a-story-19f582daaf5b" width="100%" border="false" collapsed="true"]
[8] Fix | Delete
*
[9] Fix | Delete
* @package automattic/jetpack
[10] Fix | Delete
*/
[11] Fix | Delete
[12] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[13] Fix | Delete
exit( 0 );
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
// Faux-oembed support for Medium permalinks.
[17] Fix | Delete
wp_embed_register_handler( 'medium', '#^https?://medium.com/([a-zA-z0-9-_@]+)#', 'jetpack_embed_medium_oembed' );
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Callback to modify output of embedded Medium posts.
[21] Fix | Delete
*
[22] Fix | Delete
* @param array $matches Regex partial matches against the URL passed.
[23] Fix | Delete
* @param array $attr Attributes received in embed response.
[24] Fix | Delete
* @param array $url Requested URL to be embedded.
[25] Fix | Delete
*/
[26] Fix | Delete
function jetpack_embed_medium_oembed( $matches, $attr, $url ) {
[27] Fix | Delete
$attr = jetpack_embed_medium_args( $attr );
[28] Fix | Delete
$attr['url'] = $url;
[29] Fix | Delete
[30] Fix | Delete
return jetpack_embed_medium_embed_html( $attr );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Return custom markup to display a Medium profile, collection, or story.
[35] Fix | Delete
*
[36] Fix | Delete
* @param array $args Attributes received in embed response.
[37] Fix | Delete
*/
[38] Fix | Delete
function jetpack_embed_medium_embed_html( $args ) {
[39] Fix | Delete
$args = jetpack_embed_medium_args( $args );
[40] Fix | Delete
[41] Fix | Delete
if ( empty( $args['url'] ) ) {
[42] Fix | Delete
return;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
$args['type'] = jetpack_embed_medium_get_embed_type( $args['url'] );
[46] Fix | Delete
[47] Fix | Delete
if ( 'collection' === $args['type'] ) {
[48] Fix | Delete
return sprintf(
[49] Fix | Delete
'<a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s</a>',
[50] Fix | Delete
esc_url( $args['url'] ),
[51] Fix | Delete
esc_html__( 'View this collection on Medium.com', 'jetpack' )
[52] Fix | Delete
);
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
wp_enqueue_script(
[56] Fix | Delete
'medium-embed',
[57] Fix | Delete
'https://static.medium.com/embed.js',
[58] Fix | Delete
array(),
[59] Fix | Delete
JETPACK__VERSION,
[60] Fix | Delete
true
[61] Fix | Delete
);
[62] Fix | Delete
[63] Fix | Delete
return sprintf(
[64] Fix | Delete
'<a class="m-%1$s" href="%2$s" target="_blank" data-width="%3$s" data-border="%4$s" data-collapsed="%5$s">%6$s</a>',
[65] Fix | Delete
esc_attr( $args['type'] ),
[66] Fix | Delete
esc_url( $args['url'] ),
[67] Fix | Delete
esc_attr( $args['width'] ),
[68] Fix | Delete
esc_attr( $args['border'] ),
[69] Fix | Delete
esc_attr( $args['collapsed'] ),
[70] Fix | Delete
esc_html__( 'View at Medium.com', 'jetpack' )
[71] Fix | Delete
);
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Shortcode support that allows passing in URL
[76] Fix | Delete
*
[77] Fix | Delete
* @param array $atts Shortcode attributes.
[78] Fix | Delete
*/
[79] Fix | Delete
function jetpack_embed_medium_shortcode( $atts ) {
[80] Fix | Delete
$atts = jetpack_embed_medium_args( $atts );
[81] Fix | Delete
[82] Fix | Delete
if ( ! empty( $atts['url'] ) ) {
[83] Fix | Delete
global $wp_embed;
[84] Fix | Delete
return $wp_embed->shortcode( $atts, $atts['url'] );
[85] Fix | Delete
} elseif ( current_user_can( 'edit_posts' ) ) {
[86] Fix | Delete
return esc_html__( 'You did not provide a valid Medium URL.', 'jetpack' );
[87] Fix | Delete
} else {
[88] Fix | Delete
return '<!-- Missing Medium URL -->';
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
add_shortcode( 'medium', 'jetpack_embed_medium_shortcode' );
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Get embed type (profile, collection, or story) based on Medium URL.
[95] Fix | Delete
*
[96] Fix | Delete
* @param string $url Medium URL.
[97] Fix | Delete
*/
[98] Fix | Delete
function jetpack_embed_medium_get_embed_type( $url ) {
[99] Fix | Delete
$url_path = wp_parse_url( $url, PHP_URL_PATH );
[100] Fix | Delete
if ( preg_match( '/^\/@[\.\w]+$/', $url_path ) ) {
[101] Fix | Delete
return 'profile';
[102] Fix | Delete
} elseif ( preg_match( '/^\/(?:s)\/(.+)$/', $url_path ) ) {
[103] Fix | Delete
return 'collection';
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
return 'story';
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Process Medium shortcode attributes.
[111] Fix | Delete
*
[112] Fix | Delete
* @param array $atts Shortcode attributes.
[113] Fix | Delete
*/
[114] Fix | Delete
function jetpack_embed_medium_args( $atts ) {
[115] Fix | Delete
return shortcode_atts(
[116] Fix | Delete
array(
[117] Fix | Delete
'url' => '',
[118] Fix | Delete
'width' => '400',
[119] Fix | Delete
'border' => true,
[120] Fix | Delete
'collapsed' => false,
[121] Fix | Delete
),
[122] Fix | Delete
$atts,
[123] Fix | Delete
'medium'
[124] Fix | Delete
);
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function