无法再在本地主机上编辑functions.php和任何网站页面

问题描述 投票:0回答:1

我刚刚安装了 Wordpress 6.4.3 和 MAMP 并成功编辑了functions.php并保存了我的更改。

Twenty Twenty-Four: Theme Functions (functions.php)

当我尝试对文件进行更多更改时,Wordpress 开始显示以下错误消息:

出了点问题。您的更改可能尚未保存。请再试一次。您也有可能需要手动修复并通过 FTP 上传文件。

当我尝试编辑我的网站页面时,我现在开始收到以下错误消息:

更新失败。该响应不是有效的 JSON 响应。

这是我已成功添加到functions.php中的内容,无法再编辑它了

if ($_SERVER["REQUEST_METHOD"] === "POST") {
  $name = sanitize_text_field($_POST["name"]);
  $email = sanitize_email($_POST["email"]);
  $message = sanitize_textarea_field($_POST["description"]);

  // Add code to save the form data to the database
  global $wpdb;
  $table_name = $wpdb->prefix . 'request_form';
  $data = array(
    'name' => $name,
    'email' => $email,
    'description' => $message,
    'submission_time' => current_time('mysql')
  );
  $insert_result = $wpdb->insert($table_name, $data);

  if ($insert_result === false) {
    $response = array(
      'success' => false,
      'message' => 'Error saving the form data.',
    );
  } else {
    $response = array(
      'success' => true,
      'message' => 'Form data saved successfully.'
    );
  }

  // Return the JSON response
  header('Content-Type: application/json');
  echo json_encode($response);
  exit;
}

我做了什么:

  • 我已经检查了文件的权限,并为本地主机上的每个人授予了读写权限。

  • 重新启动服务器

  • 将 WordPress 移至新文件夹

  • 当我在“设置”>“常规”下将 WordPress 地址(URL)和站点地址(URL)的 http 更改为 https 并保存更改时,我被重定向到以下地址 http://localhost:8888/wp-admin/options。 php 并可以看到以下内容:


    注意:未定义索引:名称在 /应用程序/MAMP/htdocs/wp- content/themes/twentytwentyfour/functions.php 在线 209

    注意:未定义索引:电子邮件地址 /应用程序/MAMP/htdocs/wp- content/themes/twentytwentyfour/functions.php 在线 210

    注意:未定义索引:描述在 /应用程序/MAMP/htdocs/wp- content/themes/twentytwentyfour/functions.php 在线 211
    WordPress 数据库 错误: [未知列“submission_time” '字段列表']
    INSERT INTO `wp_request_form` 
      (`name`, `email`, `description`, `submission_time`) VALUES 
      ('', '', '', '2024-03-30 
       07:10:51')

    {"成功":false,"消息":"错误 保存表单数据。"}
wordpress mamp
1个回答
0
投票

为了绕过错误消息,我访问了wordpress文件夹中的functions.php文件,并注释掉了代码的最后一部分,即返回JSON响应。

保存文件后,我在Wordpress上访问了该文件并设法继续编辑它!!!!

© www.soinside.com 2019 - 2024. All rights reserved.