prefix . "rh_badges"; if( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) != $table_name ) { $sql = "CREATE TABLE " . $table_name . " ( badge_id int(9) PRIMARY KEY AUTO_INCREMENT, description text NOT NULL, name varchar(255) NOT NULL, type varchar(10) NOT NULL );"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } // Create the rh_badge_conditions table. $table_name = $wpdb->prefix . "rh_badge_conditions"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $sql = "CREATE TABLE " . $table_name . " ( badge_id int(9) NOT NULL, badge_condition_id int(9) PRIMARY KEY AUTO_INCREMENT, object_type varchar(25) NOT NULL, value varchar(255) NOT NULL, count int(9) NOT NULL );"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } // Create the rh_user_badges table. $table_name = $wpdb->prefix . "rh_user_badges"; if($wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) != $table_name ) { $sql = "CREATE TABLE " . $table_name . " ( badge_id int(9) NOT NULL, user_id int(9) NOT NULL, time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CONSTRAINT rhub_pk UNIQUE KEY (badge_id, user_id) );"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } add_option("rhb_db_version", $rhb_db_version); } // Hook for registering the install function upon plugin activation. register_activation_hook(__FILE__,'rhb_installation'); // Add the badge count to the Dashboard landing page. add_action('right_now_content_table_end', 'rhb_add_badge_counts'); // Check for new badges after a post is published. add_action('publish_post', 'rhb_check_author'); // Check for new badges after a comment is published. add_action('comment_post', 'rhb_check_current_user'); function rhb_add_badge_counts() { $num = intval( rhb_count_badges() ); $text = _n( 'Badge', 'Badges', $num ); if ( current_user_can( 'edit_posts' ) ) { $num = "$num"; $text = "$text"; } echo '
' . $user_badge->name . ' | ' . $user_badge->user_nicename. ' |
'."\n"; } add_action('widgets_init', create_function('', 'return register_widget("LatestBadgesWidget");')); // register LatestBadgesWidget widget add_action('wp_print_styles', 'rhb_css'); // Rockhoist Badges stylesheet