@@ -171,8 +171,6 @@ public function wp_embed_handler( array $matches, array $attr, $url, array $rawa
171
171
* @return string HTML content to display the Gist.
172
172
*/
173
173
public function shortcode ( array $ rawattr ) {
174
- global $ post ;
175
-
176
174
$ shortcode = $ this ->rebuild_shortcode ( $ rawattr );
177
175
178
176
$ attr = $ this ->standardize_attributes ( $ rawattr );
@@ -199,35 +197,33 @@ public function shortcode( array $rawattr ) {
199
197
$ url = 'https://gist.github.com/ ' . $ attr ['id ' ];
200
198
$ json_url = $ url . '.json ' ;
201
199
202
- if ( isset ( $ post ->ID ) ) {
203
- if ( is_feed () ) {
204
- $ html = sprintf ( '<a href="%s" target="_blank"><em>%s</em></a> ' , esc_url ( $ url ), __ ( 'View this code snippet on GitHub. ' , 'gistpress ' ) );
205
- return apply_filters ( 'gistpress_feed_html ' , $ html );
206
- }
207
-
208
- $ html = $ this ->get_gist_html ( $ json_url , $ attr );
200
+ if ( is_feed () ) {
201
+ $ html = sprintf ( '<a href="%s" target="_blank"><em>%s</em></a> ' , esc_url ( $ url ), __ ( 'View this code snippet on GitHub. ' , 'gistpress ' ) );
202
+ return apply_filters ( 'gistpress_feed_html ' , $ html );
203
+ }
209
204
210
- if ( $ this ->unknown () === $ html ) {
211
- return make_clickable ( $ url );
212
- }
205
+ $ html = $ this ->get_gist_html ( $ json_url , $ attr );
213
206
214
- // If there was a result, return it.
215
- if ( $ html ) {
216
- if ( $ attr ['embed_stylesheet ' ] ) {
217
- wp_enqueue_style ( 'gistpress ' );
218
- }
207
+ if ( $ this ->unknown () === $ html ) {
208
+ return make_clickable ( $ url );
209
+ }
219
210
220
- $ html = apply_filters ( 'gistpress_html ' , $ html , $ url , $ attr , $ post ->ID );
211
+ // If there was a result, return it.
212
+ if ( $ html ) {
213
+ if ( $ attr ['embed_stylesheet ' ] ) {
214
+ wp_enqueue_style ( 'gistpress ' );
215
+ }
221
216
222
- foreach ( $ attr as $ key => $ value ) {
223
- $ message = '<strong> ' . $ key . __ (' (shortcode attribute) ' , 'gistpress ' ) . ':</strong> ' ;
224
- $ message .= is_scalar ( $ value ) ? $ value : print_r ( $ value , true );
225
- $ this ->debug_log ( $ message , $ shortcode_hash );
226
- }
227
- $ this ->debug_log ( '<strong>Gist:</strong><br /> ' . $ html , $ shortcode_hash );
217
+ $ html = apply_filters ( 'gistpress_html ' , $ html , $ url , $ attr , get_the_ID () );
228
218
229
- return $ html ;
219
+ foreach ( $ attr as $ key => $ value ) {
220
+ $ message = '<strong> ' . $ key . __ (' (shortcode attribute) ' , 'gistpress ' ) . ':</strong> ' ;
221
+ $ message .= is_scalar ( $ value ) ? $ value : print_r ( $ value , true );
222
+ $ this ->debug_log ( $ message , $ shortcode_hash );
230
223
}
224
+ $ this ->debug_log ( '<strong>Gist:</strong><br /> ' . $ html , $ shortcode_hash );
225
+
226
+ return $ html ;
231
227
}
232
228
233
229
return '' ;
@@ -339,8 +335,6 @@ public function parse_line_number_arg( $line_numbers ) {
339
335
* @return string Gist HTML or {{unknown}} if it couldn't be determined.
340
336
*/
341
337
public function get_gist_html ( $ url , array $ args ) {
342
- global $ post ;
343
-
344
338
// Add a specific file from a Gist to the URL.
345
339
if ( ! empty ( $ args ['file ' ] ) ) {
346
340
$ url = add_query_arg ( 'file ' , urlencode ( $ args ['file ' ] ), $ url );
@@ -368,7 +362,7 @@ public function get_gist_html( $url, array $args ) {
368
362
369
363
// Update the post meta fallback.
370
364
// @link http://core.trac.wordpress.org/ticket/21767
371
- update_post_meta ( $ post -> ID , $ raw_key , addslashes ( $ json ->div ) );
365
+ update_post_meta ( get_the_ID () , $ raw_key , addslashes ( $ json ->div ) );
372
366
373
367
$ html = $ this ->process_gist_html ( $ json ->div , $ args );
374
368
@@ -385,7 +379,7 @@ public function get_gist_html( $url, array $args ) {
385
379
// Failures are cached, too. Update the post to attempt to fetch again.
386
380
$ html = ( $ html ) ? $ html : $ this ->unknown ();
387
381
388
- if ( $ this ->unknown () == $ html && ( $ fallback = get_post_meta ( $ post -> ID , $ raw_key , true ) ) ) {
382
+ if ( $ this ->unknown () == $ html && ( $ fallback = get_post_meta ( get_the_ID () , $ raw_key , true ) ) ) {
389
383
// Return the fallback instead of the string representing unknown.
390
384
$ html = $ this ->process_gist_html ( $ fallback , $ args );
391
385
0 commit comments