| 690 | |
| 691 | /* |
| 692 | * Remove plugins from the list of active plugins when we're on an admin or |
| 693 | * login screen and the plugin appears in the `skip_on_admin` list. |
| 694 | */ |
| 695 | if ( 'wp-login.php' === $GLOBALS['pagenow'] |
| 696 | || ( is_admin() && ! wp_doing_ajax() ) ) { |
| 697 | $skip_on_admin = (array) get_option( 'skip_on_admin', array() ); |
| 698 | |
| 699 | if ( ! array_key_exists( 'plugin', $skip_on_admin ) ) { |
| 700 | return $plugins; |
| 701 | } |
| 702 | |
| 703 | foreach ( $plugins as $index => $plugin ) { |
| 704 | $parts = explode( |
| 705 | '/', |
| 706 | str_replace( WP_CONTENT_DIR . '/', '', $plugin ) |
| 707 | ); |
| 708 | |
| 709 | if ( in_array( $parts[1], $skip_on_admin['plugin'], true ) ) { |
| 710 | unset( $plugins[ $index ] ); |
| 711 | // Store list of skipped plugins for displaying an admin notice. |
| 712 | $GLOBALS['_skipped_plugin'][] = $plugin; |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
| 1280 | |
| 1281 | /** |
| 1282 | * Wrap the shutdown handler function so it can be made pluggable at a later |
| 1283 | * stage. |
| 1284 | * |
| 1285 | * @since 5.0.0 |
| 1286 | * |
| 1287 | * @return void |
| 1288 | */ |
| 1289 | function wp_shutdown_handler_wrapper() { |
| 1290 | if ( defined( 'WP_EXECUTION_SUCCEEDED' ) && WP_EXECUTION_SUCCEEDED ) { |
| 1291 | return; |
| 1292 | } |
| 1293 | |
| 1294 | // Load the pluggable shutdown handler in case we found one. |
| 1295 | if ( function_exists( 'wp_handle_shutdown' ) ) { |
| 1296 | $stop_propagation = (bool) wp_handle_shutdown(); |
| 1297 | |
| 1298 | if ( $stop_propagation ) { |
| 1299 | return; |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | $error = error_get_last(); |
| 1304 | |
| 1305 | // No error, just skip the error handling code. |
| 1306 | if ( null === $error ) { |
| 1307 | return; |
| 1308 | } |
| 1309 | |
| 1310 | // This is only diagnostic code for the POC. |
| 1311 | echo sprintf( |
| 1312 | '<p>WordPress was shut down because a PHP error of type <strong>%d</strong> occurred in the file <strong><code>%s</code></strong> at line <strong><code>%d</code></strong>:<br><strong>%s</strong>', |
| 1313 | $error['type'], |
| 1314 | $error['file'], |
| 1315 | $error['line'], |
| 1316 | $error['message'] |
| 1317 | ); |
| 1318 | |
| 1319 | // For now, we only trigger our safe mode on parse errors. |
| 1320 | if ( E_PARSE === $error['type'] ) { |
| 1321 | $path = str_replace( WP_CONTENT_DIR . '/', '', $error['file'] ); |
| 1322 | |
| 1323 | $parts = explode( '/', $path ); |
| 1324 | $type = rtrim( array_shift( $parts ), 's' ); |
| 1325 | $extension = array_shift( $parts ); |
| 1326 | |
| 1327 | // This is only diagnostic code for the POC. |
| 1328 | echo sprintf( |
| 1329 | '<p>A <strong>parse-time</strong> error was detected. The likely culprit was the <code>%s</code> %s.', |
| 1330 | $extension, |
| 1331 | 'mu-plugin' === $type ? 'must-use plugin' : $type |
| 1332 | ); |
| 1333 | |
| 1334 | $skip_on_admin = get_option( 'skip_on_admin', array() ); |
| 1335 | |
| 1336 | if ( ! array_key_exists( $type, $skip_on_admin ) ) { |
| 1337 | $skip_on_admin[ $type ] = array(); |
| 1338 | } |
| 1339 | |
| 1340 | if ( ! in_array( $extension, $skip_on_admin[ $type ], true ) ) { |
| 1341 | $skip_on_admin[ $type ][] = $extension; |
| 1342 | } |
| 1343 | |
| 1344 | update_option( 'skip_on_admin', $skip_on_admin ); |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | /** |
| 1349 | * Register the WordPress premature shutdown handler. |
| 1350 | * |
| 1351 | * @since 5.0.0 |
| 1352 | * |
| 1353 | * @return void |
| 1354 | */ |
| 1355 | function wp_register_premature_shutdown_handler() { |
| 1356 | register_shutdown_function( 'wp_shutdown_handler_wrapper' ); |
| 1357 | } |