我一直在玩弄程序,并试图将注释插入到程序中。我有点麻烦,不知道你们能不能看看。
function wp_insert_comment($commentdata) {
$comment_ID = comment_ID;
$comment_post_ID = comment_post_ID;
$comment_author = comment_author;
$comment_author_email = comment_author_email;
$comment_author_url = comment_author_url;
$comment_author_IP = comment_author_IP;
$comment_date = comment_date;
$comment_date_gmt = comment_date_gmt;
$comment_content = comment_content;
$comment_karma = comment_karma;
$comment_approved = comment_approved;
$comment_agent = comment_agent;
$comment_type = comment_type;
$comment_parent = comment_parent;
$user_id = user_id;
global $wpdb;
extract(wp_unslash($commentdata), EXTR_SKIP);
if ( ! isset($comment_author_IP) )
$comment_author_IP = \'\';
if ( ! isset($comment_date) )
$comment_date = current_time(\'mysql\');
if ( ! isset($comment_date_gmt) )
$comment_date_gmt = get_gmt_from_date($comment_date);
if ( ! isset($comment_parent) )
$comment_parent = 0;
if ( ! isset($comment_approved) )
$comment_approved = 1;
if ( ! isset($comment_karma) )
$comment_karma = 0;
if ( ! isset($user_id) )
$user_id = 0;
if ( ! isset($comment_type) )
$comment_type = \'\';
$wpdb->insert($wpdb->comments, \'$comment_ID\',\'$comment_post_ID\', \'$comment_author\', \'$comment_author_email\', \'$comment_author_url\', \'$comment_author_IP\', \'$comment_date\', \'$comment_date_gmt\', \'$comment_content\', \'$comment_karma\', \'$comment_approved\', \'$comment_agent\', \'$comment_type\', \'$comment_parent\', \'$user_id\');
$id = (int) $wpdb->insert_id;
if ( $comment_approved == 1 )
wp_update_comment_count($comment_post_ID);
$comment = get_comment($id);
do_action( \'wp_insert_comment\', $id, $commen );
wp_cache_set( \'last_changed\', microtime(), \'comment\' );
return $id;
}
所以在这里,我只更改了顶部的变量,因为之前使用的数组对我来说不起作用。我将这些变量发送到:
function _insert_replace_helper( $table, $comment_ID, $comment_post_ID, $comment_author, $comment_author_email, $comment_author_url, $comment_author_IP, $comment_date, $comment_date_gmt, $comment_content, $comment_karma, $comment_approved, $comment_agent, $comment_type, $comment_parent, $user_id, $format = null, $type = \'INSERT\' ) {
$sql = "CALL CommentsProcedure(\'$comment_ID\', \'$comment_post_ID\', \'$comment_author\', \'$comment_author_email\', \'$comment_author_url\', \'$comment_author_IP\', \'$comment_date\', \'$comment_date_gmt\', \'$comment_content\', \'$comment_karma\', \'$comment_approved\', \'$comment_agent\', \'$comment_type\', \'$comment_parent\', \'$user_id\')";
return $this->query( $this->prepare( $sql, $comment_ID, $comment_post_ID, $comment_author, $comment_author_email, $comment_author_url, $comment_author_IP, $comment_date, $comment_date_gmt, $comment_content, $comment_karma, $comment_approved, $comment_agent, $comment_type, $comment_parent, $user_id ) );
}
这是我的存储过程
DELIMITER $$
CREATE PROCEDURE `CommentsProcedure`(IN comment_ID bigint(20), IN comment_post_ID bigint(20), IN comment_author tinytext, IN comment_author_email VARCHAR(100), IN comment_author_url VARCHAR(200), IN comment_author_IP VARCHAR(100), IN comment_date datetime, IN comment_date_gmt datetime, IN comment_content text,
IN comment_karma int(11), IN comment_approved VARCHAR(20), IN comment_agent VARCHAR(255), IN comment_type VARCHAR(20), IN comment_parent bigint(20), IN user_ID bigint(20))
BEGIN
INSERT INTO wp_comments(comment_ID, comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_karma, comment_approved, comment_agent, comment_type, comment_parent, user_id)
VALUES(comment_ID, comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_karma, comment_approved, comment_agent, comment_type, comment_parent, user_id);
END
$$
DELIMITER ;
我不知道我做错了什么,如果有人能给我一些指导,我会很有帮助的,我已经被困这么长时间了,我在拉扯我的头发!(抱歉,英语不好,不是母语,如果有什么不清楚的地方,请尽管问。)提前感谢