@@ -581,9 +581,17 @@ private function update_mu_plugin_loader( $which ) {
581581 }
582582 $ contents .= " */ \n" ;
583583 } else {
584+ error_clear_last ();
584585 $ contents = $ wp_filesystem ->get_contents ( $ file );
585586 if ( $ contents === false ) {
586- return is_wp_error ( $ wp_filesystem ->errors ) && $ wp_filesystem ->errors ->has_errors () ? $ wp_filesystem ->errors : new WP_Error ( 'fs_error ' , "Unknown error while reading {$ this ->plugin_slug ()}-loader.php " );
587+ if ( is_wp_error ( $ wp_filesystem ->errors ) && $ wp_filesystem ->errors ->has_errors () ) {
588+ return $ wp_filesystem ->errors ;
589+ }
590+ $ err = error_get_last ();
591+ if ( ! empty ( $ err ['message ' ] ) ) {
592+ return new WP_Error ( 'fs_error ' , "PHP error while reading {$ this ->plugin_slug ()}-loader.php: " . esc_html ( $ err ['message ' ] ) );
593+ }
594+ return new WP_Error ( 'fs_error ' , "Unknown error while reading {$ this ->plugin_slug ()}-loader.php " );
587595 }
588596 if ( ! str_starts_with ( $ contents , '<?php ' ) ) {
589597 return new WP_Error ( 'bad_mu_loader ' , "Mu-plugin loader {$ this ->plugin_slug ()}-loader.php is unparseable " );
@@ -600,16 +608,25 @@ private function update_mu_plugin_loader( $which ) {
600608 // Write the file, or delete it if it's our auto-generated file and turns out to be empty.
601609 if ( preg_match ( '#^<\?php\s*/\*\*\n \* Loader generated by Jetpack Beta plugin\n\n(?: \* Plugin Name: .*\n)?(?: \* Description: .*\n)? \*/\s*$# ' , $ new_contents ) ) {
602610 $ what = 'deleting ' ;
603- $ ok = $ wp_filesystem ->delete ( $ file );
611+ error_clear_last ();
612+ $ ok = $ wp_filesystem ->delete ( $ file );
604613 } elseif ( $ contents !== $ new_contents ) {
605614 $ what = 'updating ' ;
606- $ ok = $ wp_filesystem ->put_contents ( $ file , $ new_contents );
615+ error_clear_last ();
616+ $ ok = $ wp_filesystem ->put_contents ( $ file , $ new_contents );
607617 } else {
608618 $ what = 'nothing ' ;
609619 $ ok = true ;
610620 }
611621 if ( ! $ ok ) {
612- return is_wp_error ( $ wp_filesystem ->errors ) && $ wp_filesystem ->errors ->has_errors () ? $ wp_filesystem ->errors : new WP_Error ( 'fs_error ' , "Unknown error while $ what {$ this ->plugin_slug ()}-loader.php " );
622+ if ( is_wp_error ( $ wp_filesystem ->errors ) && $ wp_filesystem ->errors ->has_errors () ) {
623+ return $ wp_filesystem ->errors ;
624+ }
625+ $ err = error_get_last ();
626+ if ( ! empty ( $ err ['message ' ] ) ) {
627+ return new WP_Error ( 'fs_error ' , "PHP error while $ what {$ this ->plugin_slug ()}-loader.php: " . esc_html ( $ err ['message ' ] ) );
628+ }
629+ return new WP_Error ( 'fs_error ' , "Unknown error while $ what {$ this ->plugin_slug ()}-loader.php " );
613630 }
614631 return null ;
615632 }
0 commit comments