Skip to content

Commit a1ff9b6

Browse files
committed
Merge pull request #74 from johnbillion/blocked-asset-error
Better blocked assets. props @johnbillion
2 parents 72712dc + a8738b6 commit a1ff9b6

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

airplane-mode.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@ public function block_style_load( $source ) {
284284
}
285285

286286
// If we don't share the same URL as the site itself, return null. Otherwise return the URL.
287-
return isset( $parsed ) && false === strpos( home_url(), $parsed ) ? null : $source;
287+
return isset( $parsed ) && false === strpos( home_url(), $parsed )
288+
? new Airplane_Mode_WP_Error( 'airplane_mode_enabled', __( 'Airplane Mode blocked style', 'airplane-mode' ), array(
289+
'return' => '',
290+
'src' => $source,
291+
) )
292+
: $source;
288293
}
289294

290295
/**
@@ -310,7 +315,12 @@ public function block_script_load( $source ) {
310315
}
311316

312317
// If we don't share the same URL as the site itself, return null. Otherwise return the URL.
313-
return isset( $parsed ) && false === strpos( home_url(), $parsed ) ? null : $source;
318+
return isset( $parsed ) && false === strpos( home_url(), $parsed )
319+
? new Airplane_Mode_WP_Error( 'airplane_mode_enabled', __( 'Airplane Mode blocked script', 'airplane-mode' ), array(
320+
'return' => '',
321+
'src' => $source,
322+
) )
323+
: $source;
314324
}
315325

316326
/**
@@ -888,6 +898,18 @@ public function count_http_requests() {
888898

889899
} //end class_exists
890900

901+
if ( ! class_exists( 'Airplane_Mode_WP_Error' ) ) {
902+
903+
class Airplane_Mode_WP_Error extends WP_Error {
904+
905+
public function __tostring() {
906+
$data = $this->get_error_data();
907+
return $data['return'];
908+
}
909+
910+
}
911+
912+
}
891913

892914
// Instantiate our class.
893915
$Airplane_Mode_Core = Airplane_Mode_Core::getInstance();

0 commit comments

Comments
 (0)