@@ -130,3 +130,34 @@ function post_comment($commentdata)
130
130
131
131
add_filter ('preprocess_comment ' , 'post_comment ' );
132
132
133
+ /**
134
+ * 黑客派同步到博客
135
+ * 指定参数 hacpai-api = sync-comment
136
+ */
137
+ function sync_comment ()
138
+ {
139
+ if ($ _GET ['hacpai-api ' ] === 'sync-comment ' ) {//判断是不是同步的接口
140
+ $ data = json_decode (file_get_contents ("php://input " ));
141
+ $ comment = $ data ->comment ;
142
+ $ key = $ data ->client ->key ;
143
+ if ($ key == $ GLOBALS ['client ' ]['key ' ]) {//判断是否配置了正确的key
144
+ $ commentdata = array (
145
+ 'comment_post_ID ' => $ comment ->articleId ,
146
+ 'comment_author ' => $ comment ->authorName ,
147
+ 'comment_author_email ' => $ comment ->authorEmail ,
148
+ 'comment_author_url ' => $ comment ->authorURL ,
149
+ 'comment_content ' => $ comment ->content ,
150
+ 'comment_type ' => '' , //empty for regular comments, 'pingback' for pingbacks, 'trackback' for trackbacks
151
+ 'comment_parent ' => 0 , //0 if it's not a reply to another comment; if it's a reply, mention the parent comment ID here
152
+ 'user_id ' => 0 , //passing current user ID or any predefined as per the demand
153
+ );
154
+ //Insert new comment and get the comment ID
155
+ $ comment_id = wp_new_comment ($ commentdata );
156
+ test ($ comment_id );
157
+ } else {
158
+ echo 'Key not match ' ;
159
+ }
160
+ }
161
+ }
162
+
163
+ add_action ('template_redirect ' , 'sync_comment ' );
0 commit comments