Skip to content

Commit

Permalink
Update to recommended changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurorum authored Aug 11, 2020
1 parent e0dfe1f commit 6314a9f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions modules/shortcodes/gist.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,29 @@ class_exists( 'Jetpack_AMP_Support' )
}

// URL points to the entire gist, including the file name if there was one.
$id = ( ! empty( $file ) ? $id . '?file=' . $file : $id );
$id = ( ! empty( $file ) ? $id . '?file=' . $file : $id );
$return = false;

$request = wp_remote_get( "https://gist.github.com/" . esc_attr( $id ) );
$request = wp_remote_get( esc_url_raw( 'https://gist.github.com/' . esc_attr( $id ) ) );
$request_code = wp_remote_retrieve_response_code( $request );

if ( 200 === $request_code ) {
$request_body = wp_remote_retrieve_body( $request );
$request_data = json_decode( $request_body );

wp_enqueue_style( 'jetpack-gist-styling', $request_data->stylesheet );
wp_enqueue_style( 'jetpack-gist-styling', esc_url( $request_data->stylesheet ), array(), JETPACK__VERSION );

$gist = substr_replace( $request_data->div, sprintf( 'style="tab-size: %1$s" ', absint( $tab_size ) ), 5, 0 );

// inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables.
// Add inline styles for the tab style in the opening div of the gist.
$gist = preg_replace(
'#(\<div\s)+(id=\"gist[0-9]+\")+(\sclass=\"gist\"\>)?#',
sprintf( '$1style="tab-size: %1$s" $2$3', absint( $tab_size ) ),
$request_data->div,
1
);

// Add inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables.
$return = sprintf( '<style>.gist table { margin-bottom: 0; }</style>%1$s', $gist );
}

Expand Down

0 comments on commit 6314a9f

Please sign in to comment.