WordPressでPhoto Express for Googleのプラグインを残しておいたためエラーでサイトが表示できなくなってました。
表側のみならず管理側のログイン画面もエラーで表示されず…
以下で解決できたのでメモ。
Photo Express for Googleのプラグインはすでにメンテナンスされておらず、プラグインとしても機能していないので消しておきましょう。
Photo Express for Googleでのエラー現象
ログを見ると以下のようなエラーが出ていました。
[error] 21434#0: *63 FastCGI sent in stderr: "PHP message: PHP Fatal error: Cannot redeclare str_starts_with() (previously declared in /xxx/wp-includes/compat.php:387) in /xxx/wp-content/plugins/photo-express-for-google/photo-express.php on line 250"
エラーの原因
str_starts_with()というメソッドが複数定義されていてエラーになっていました。
今回でいうと「wp-includes/compat.phpの387行目」と「photo-express-for-google/photo-express.phpの250行目」。
なので、もう機能していないphoto-express-for-googleの方をなんとかすればOK。
エラーの対応方法
エラーで管理画面にログインできないので、サーバーにターミナルでログインしてなんとかするしかなさそうです。
Photo Express for Googleプラグインのファイルを削除してしまっても良いですが、いったん復旧させてからプラグインを管理画面で削除することにします。
サーバーにターミナルでログインし作業していきます。
※ファイルのパスはそれぞれの環境に合わせて変更してください。
$ vi /xxx/wp-content/plugins/photo-express-for-google/photo-express.php
     function convert_to_https( $url ) {
-         if ( ! str_starts_with( $url, "https" ) && str_starts_with( $url, "http" ) ) {
+         if ( ! pe_str_starts_with( $url, "https" ) && pe_str_starts_with( $url, "http" ) ) {
             $url = 'https' . substr( $url, 4 );
         }
 
         return $url;
     }
-     function str_starts_with( $haystack, $needle ) { 
+     function pe_str_starts_with( $haystack, $needle ) {
         return substr( $haystack, 0, strlen( $needle ) ) === $needle;
     }
【変更点その1】
「function str_starts_with( $haystack, $needle ) {」でstr_starts_with()メソッドを宣言していて重複していたのでメソッド名をpe_str_starts_withに変更。
※変更後のメソッド名はpe_str_starts_withじゃなくて、ほかの名称でも大丈夫です。
     function str_starts_with( $haystack, $needle ) { 
     ↓
     function pe_str_starts_with( $haystack, $needle ) {
【変更点その2】
str_starts_with()メソッドを使用していた箇所「if ( ! str_starts_with( $url, "https" ) && str_starts_with( $url, "http" ) ) {」のメソッド名を変更後のメソッド名に変更。
         if ( ! str_starts_with( $url, "https" ) && str_starts_with( $url, "http" ) ) {
         ↓
         if ( ! pe_str_starts_with( $url, "https" ) && pe_str_starts_with( $url, "http" ) ) {
これでエラーが解消に画面が表示できると思います。
そしたら管理側にログインし、プラグインのところからPhoto Express for Googleを削除できます。
