diff --git a/tencentcloud-tms/TencentWordpressTMSActions.php b/tencentcloud-tms/TencentWordpressTMSActions.php index 3c13ab4239fae49be4995c5cce983ff388e323f6..2b9c5ff566d741f9df9884b5cbbda80a4563d83c 100644 --- a/tencentcloud-tms/TencentWordpressTMSActions.php +++ b/tencentcloud-tms/TencentWordpressTMSActions.php @@ -151,6 +151,7 @@ class TencentWordpressTMSActions * @param $id * @param $comment * @return bool + * @throws Exception */ public function examineCommentAfterInsertDatabase($id, $comment) { @@ -186,6 +187,51 @@ class TencentWordpressTMSActions wp_die($error, '评论检测不通过,已屏蔽.', ['back_link' => true]); } + /** + * + * @param $post_id + * @return string + */ + public function examineCommentWhenSaveArticle($post_id) + { + if (!$post_id) + { + $error = new WP_Error( + 'comment_examined_fail', + __('文章不存在') + ); + wp_die($error, '文章不存在。', ['back_link' => true]); + exit; + } + $post = get_post( $post_id ); + if (!is_object($post)) { + return true; + } + $content = ''; + if (isset($post->post_title)) { + $content .= $post->post_title; + } + + if (isset($post->post_content)) { + $content .= $post->post_content; + } + $TMSOptions = self::getTMSOptionsObject(); + $response = $this->textModeration($TMSOptions, $content); + //检测接口异常不影响用户提交评论 + if ( !($response instanceof TextModerationResponse) ) { + return true; + } + if ( $response->getData()->EvilFlag === 0 || $response->getData()->EvilType === 100 ) { + return true; + } + + $error = new WP_Error( + 'comment_examined_fail', + __('内容检测不通过,包含关键字' . $response->getData()->Keywords[0] . '请修改后重新提交') + ); + wp_die($error, '内容检测不通过,请修改后重新提交.', ['back_link' => true]); + } + /** * 腾讯云文本检测 * @param TencentWordpressTMSOptions $TMSOptions diff --git a/tencentcloud-tms/readme.txt b/tencentcloud-tms/readme.txt index 23b87ece492a7004aa0cad635b76c8fac0182a0f..20e8d513a30fa5b077aa18b062064a560e7b8dd9 100644 --- a/tencentcloud-tms/readme.txt +++ b/tencentcloud-tms/readme.txt @@ -26,6 +26,8 @@ tencentcloud-tms插件是一款腾讯云研发的,提供给WordPress站长使 2. screenshot-2.png == Changelog == += 1.0.2 = +1. 对用户发布文章的文字出现违规涉黄、爆、恐的内容,进行内容检测和过滤 = 1.0.1 = 1. 支持在windows环境下运行 diff --git a/tencentcloud-tms/tencentcloud-tms.php b/tencentcloud-tms/tencentcloud-tms.php index 41240b9b729b4db315602cf2eaf71c0b5fdf7c73..e044728cfdfb6e0c883b1b19ab75220de5662895 100644 --- a/tencentcloud-tms/tencentcloud-tms.php +++ b/tencentcloud-tms/tencentcloud-tms.php @@ -71,6 +71,10 @@ if ($TMSOptions->getFailOption() === $TMSOptions::FAIL_TO_FORBID_SUBMISSION) { //评论提交后审核 add_action('wp_insert_comment', array($tmsPluginActions, 'examineCommentAfterInsertDatabase'), 101, 2); } + +//新增或修改文章时对文章内容审核 +add_action( 'publish_post', array($tmsPluginActions, 'examineCommentWhenSaveArticle')); + //js脚本引入 add_action('admin_enqueue_scripts', array($tmsPluginActions, 'loadMyScriptEnqueue')); add_action('login_enqueue_scripts', array($tmsPluginActions, 'loadMyScriptEnqueue'));