I've been playing arround with procedures and tried putting the comment insert into a procedure. I've got some trouble and was wondering if you guys could take a look.
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;
}
So here I only changed the variables on the top because it didn't work out for me with the array that was previously used. I send these variables to:
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 ) );
}
And this is my Storedprocedure
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 ;
I have no clue what i'm do wrong, would be helpful if someone could give me some guidance,I've been stuck for so long and im pulling my hair!(Sorry for the bad english, not native speaker, feel free to ask if something is unclear.) Thanks in advance
$comment_ID = comment_ID;
is no PHP. And you should turn on debugging for PHP and WordPress (php.net and the WordPress codex have info on that).