关于代码,css 和 js 上学期间没事儿在大学图书馆看过一段时间,因此多少还有点基础知识,借助 AI 还可以折腾折腾。但 PHP 代码就一窍不通了,早知道这个主题在 PHP8 环境下有问题,但一直没想办法解决,主要是怕自己把时间白白浪费掉。今天打开博客,想着再折腾点啥,却有点无从下手。于是就登陆 1panel 面板,将运行环境从 PHP7 切换到 PHP8,试着看能不能解决这个问题。
其实当我看明白了如何在 1panel 面板中查看 PHP 日志的时候我就知道这个问题解决有希望了,因为从日志里明显看到了是主题的哪个文件在报错,于是打开报错文件,将代码丢给 AI 就这么着分分钟给搞定了。现将修改代码记录如下:
1.将主题 core-rest.php 文件中的如下代码:
if(!$attachment->post_mime_type) return false;
修改为:
if ( !$attachment || !isset($attachment->post_mime_type) ) { return false; }
2.将 core.php 文件中的读者墙代码改为:
// 获取读者墙 function get_readers_wall( $count = 16 ) { global $wpdb; if ( false === ( $result = get_transient( 'readers_wall' ) ) ) { $sql = "SELECT COUNT(comment_ID) AS cnt, comment_author, comment_author_url, comment_author_email FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->posts.ID=$wpdb->comments.comment_post_ID) WHERE comment_date > date_sub( NOW(), INTERVAL 3 MONTH ) AND user_id='0' AND post_password='' AND comment_approved='1' AND comment_type='comment' GROUP BY comment_author_email ORDER BY cnt DESC LIMIT $count"; $result = $wpdb->get_results( $sql ); set_transient( 'readers_wall', $result, DAY_IN_SECONDS ); } return $result; } function refresh_readers_wall_after_approval($comment_id, $status) { $comment = get_comment($comment_id); if ($comment) { delete_transient('readers_wall'); } } add_action('wp_set_comment_status', 'refresh_readers_wall_after_approval', 10, 2);
3 将适配主题的 Easy Location 插件中的 easy-location.php 文件相关代码,替换为如下代码:
if (!function_exists('easy_location_handle_comment')) : function easy_location_handle_comment($comment_text) { $comment_ID = get_comment_ID(); $comment = get_comment($comment_ID); if ($comment && $comment->comment_author_IP && get_user_city($comment->comment_author_IP)) { $comment_text .= '<div class="comment--location"><svg version="1.1" viewBox="0 0 368.666 368.666" width="14" height="14"><g><path d="M184.333,0C102.01,0,35.036,66.974,35.036,149.297c0,33.969,11.132,65.96,32.193,92.515 c27.27,34.383,106.572,116.021,109.934,119.479l7.169,7.375l7.17-7.374c3.364-3.46,82.69-85.116,109.964-119.51 c21.042-26.534,32.164-58.514,32.164-92.485C333.63,66.974,266.656,0,184.333,0z M285.795,229.355 c-21.956,27.687-80.92,89.278-101.462,110.581c-20.54-21.302-79.483-82.875-101.434-110.552 c-18.228-22.984-27.863-50.677-27.863-80.087C55.036,78.002,113.038,20,184.333,20c71.294,0,129.297,58.002,129.296,129.297 C313.629,178.709,304.004,206.393,285.795,229.355z" /><path d="M184.333,59.265c-48.73,0-88.374,39.644-88.374,88.374c0,48.73,39.645,88.374,88.374,88.374s88.374-39.645,88.374-88.374 S233.063,59.265,184.333,59.265z M184.333,216.013c-37.702,0-68.374-30.673-68.374-68.374c0-37.702,30.673-68.374,68.374-68.374 s68.373,30.673,68.374,68.374C252.707,185.341,222.035,216.013,184.333,216.013z" /></g></svg>来自' . get_user_city($comment->comment_author_IP) . '</div>'; } return $comment_text; } endif;
4.将主题 modules.js 如下代码:
<comment-item :info="{ post_id, editor, hyperlinks, browser, os, admin_icon, visitor }" :comment="item" />
修改为:
<comment-item v-if="item" :info="{ post_id, editor, hyperlinks, browser, os, admin_icon, visitor }" :comment="item" />