E_WARNING, 'error_message' => 'get_post_types() returned non-array value: ' . gettype($post_types), 'error_file' => __FILE__, 'error_line' => __LINE__, 'timestamp' => date('Y-m-d H:i:s'), 'request_uri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'admin', 'user_agent' => 'disable_comments_post_types_support' )); } $post_types = array('post', 'page'); // 安全的默认值 } if (empty($post_types)) { return; // 如果没有文章类型,直接返回 } // 使用安全的 foreach 循环 foreach ($post_types as $post_type) { // 验证 post_type 是有效的字符串 if (!is_string($post_type) || empty($post_type)) { continue; } // 检查函数是否存在并且文章类型支持评论 if (function_exists('post_type_supports') && post_type_supports($post_type, 'comments')) { remove_post_type_support($post_type, 'comments'); remove_post_type_support($post_type, 'trackbacks'); } } } catch (Exception $e) { // 捕获任何异常并记录 if (function_exists('nenghui_log_foreach_error')) { nenghui_log_foreach_error(array( 'error_type' => E_ERROR, 'error_message' => 'Exception in disable_comments_post_types_support: ' . $e->getMessage(), 'error_file' => __FILE__, 'error_line' => __LINE__, 'timestamp' => date('Y-m-d H:i:s'), 'request_uri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'admin', 'user_agent' => 'disable_comments_post_types_support' )); } } } add_action('admin_init', 'disable_comments_post_types_support'); /** * 禁用评论功能 - 移除工具栏菜单 */ function disable_comments_admin_bar() { if (is_admin_bar_showing()) { remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60); } } add_action('init', 'disable_comments_admin_bar'); /** * 禁用评论功能 - 过滤器 */ add_filter('comments_open', '__return_false', 20, 2); add_filter('pings_open', '__return_false', 20, 2); add_filter('comments_array', '__return_empty_array', 10, 2); /** * 分类图片支持 */ // 添加分类图片字段 function category_image_add_form_fields($taxonomy) { ?>