Average Score of all ratings in comments

add this code into your plugin file to register activation hook

// register activation hook
register_activation_hook( __FILE__, 'my_rating_plugin_activation' );

now create a function and add your table creation code into

function my_rating_plugin_activation() {
    global $wpdb, $rating_table_name;
    if($wpdb->get_var("SHOW TABLES LIKE \"$rating_table_name\"") != $rating_table_name) {
        $wpdb->query("CREATE TABLE IF NOT EXISTS $rating_table_name (
            rating_id int(11) NOT NULL AUTO_INCREMENT,
            rating_postid int(11) NOT NULL,
            rating_posttitle text NOT NULL,
            rating_rating int(2) NOT NULL,
            rating_timestamp varchar(15) NOT NULL,
            rating_ip varchar(40) NOT NULL,
            rating_host varchar(200) NOT NULL,
            rating_username varchar(50) NOT NULL,
            rating_userid int(10) NOT NULL DEFAULT '0',
            comment_id int(11) NOT NULL,
            PRIMARY KEY (rating_id)
        ) ENGINE=MyISAM");
    }
}

Leave a Comment