ハマログ

株式会社イーツー・インフォの社員ブログ

WordPressで管理画面からテーマ編集時にエラー

はじめに
WordPressの管理画面からテーマファイル(外観→テーマ編集)を編集して保存する際に、
「致命的なエラーをチェックするためにサイトと通信できないため、PHP の変更は取り消されました。SFTP を使うなど、他の手段で PHP ファイルの変更をアップロードする必要があります。」
というエラーが発生して上書き更新することができませんでした。
ウェブで調べると、テーマのエラー/Basic認証/IP制限/コアコードをコメントアウトすればよい、などいろいろな記事があったので調べてみました。
ソースコードをたどります
wp-content/languages/admin-ja.po
#: wp-admin/includes/file.php:543
msgid "Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP."
msgstr "致命的なエラーをチェックするためにサイトと通信できないため、PHP の変更は取り消されました。SFTP を使うなど、他の手段で PHP ファイルの変更をアップロードする必要があります。"
もとのエラーメッセージは「Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.」でした。
wp-admin/includes/file.php
これか。
$loopback_request_failure = array(
	'code' => 'loopback_request_failed',
	'message' => __( 'Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.' ),
);
これですね。
wp_edit_theme_plugin_file関数。
/**
 * Attempt to edit a file for a theme or plugin.
 *
 * When editing a PHP file, loopback requests will be made to the admin and the homepage
 * to attempt to see if there is a fatal error introduced. If so, the PHP change will be
 * reverted.
 *
 * @since 4.9.0
 *
 * @param array $args {
 *     Args. Note that all of the arg values are already unslashed. They are, however,
 *     coming straight from $_POST and are not validated or sanitized in any way.
 *
 *     @type string $file       Relative path to file.
 *     @type string $plugin     Plugin being edited.
 *     @type string $theme      Theme being edited.
 *     @type string $newcontent New content for the file.
 *     @type string $nonce      Nonce.
 * }
 * @return true|WP_Error True on success or `WP_Error` on failure.
 */
function wp_edit_theme_plugin_file( $args ) {
PHPファイル(テーマとプラグイン)を編集するときに、エラーがあるかどうかを確認するために、の関数のようです。
もしシンタックスエラーがあるとWordPress全体が落ちるからね。
今回ひっかかっていた処理としてはこのへんでした。IP制限でループバックに対してレスポンスを応答できないのが原因でした。
// Attempt loopback request to editor to see if user just whitescreened themselves.
if ( $plugin ) {
	$url = add_query_arg( compact( 'plugin', 'file' ), admin_url( 'plugin-editor.php' ) );
} elseif ( isset( $stylesheet ) ) {
	$url = add_query_arg(
		array(
			'theme' => $stylesheet,
			'file' => $file,
		),
		admin_url( 'theme-editor.php' )
	);
} else {
	$url = admin_url();
}
$url = add_query_arg( $scrape_params, $url );
$r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout' ) );
$body = wp_remote_retrieve_body( $r );
$scrape_result_position = strpos( $body, $needle_start );
ErrorpluginthemeWordpressエラーテーマテーマ編集プラグイン致命的

  kaneko tomo   2019年1月31日


関連記事

テスト設計技法 – デシジョンテーブルテスト

どうもーyasuです~ そろそろ涼しくなってきたかな? 一つ報告、8/25にテス…

先日使えるようになったGitHub CopilotのChatとfor CLIが便利だった

今年、2023年2月にGitHub Copilot for Businessが正…

Laravelのマイグレーション(Migrations)

こんにちは、かねこです。 はじめに Laravelでのデータベースマイグレーショ…


← 前の投稿

次の投稿 →