Plugin Directory

Changeset 364169


Ignore:
Timestamp:
03/24/2011 12:42:36 PM (15 years ago)
Author:
esserq
Message:

Added user_ID to filter in both rhb_get_badges and rhb_list_badges functions.

Location:
rockhoist-badges
Files:
6 added
2 edited

Legend:

Unmodified
Added
Removed
  • rockhoist-badges/trunk/readme.txt

    r362888 r364169  
    55Requires at least: 3.1
    66Tested up to: 3.1
    7 Stable tag: 1.1
     7Stable tag: 1.2
    88
    99A Stack Overflow inspired plugin for WordPress which allows users to acquire badges for contributing website content.
     
    1212
    1313A Stack Overflow inspired plugin for WordPress which allows users to acquire badges for contributing website content. Badges are created and managed through the WordPress Dashboard.
     14
     15Key features include:
     16
     17* Administration page to manage badges and conditions
     18* A widget to display recently awarded badges
     19* Function which generates a table of badges
     20* Manually award and revoke badges
     21* Automatically check/ award badges after publishing posts/ comments
     22
     23Contact me if you find any bugs, issues or have a feature request and I will do my best to accommodate.
     24
     25More examples and information @ [blarrr.com](http://blarrr.com/wordpress-badges-plugin/)
    1426
    1527== Installation ==
     
    2739== Changelog ==
    2840
     41= 1.2 =
     42* Added user ID to the filter in both `rhb_list_badges()` and `rhb_get_badges()`.
     43
    2944= 1.1 =
    3045* Added 'Latest Badges' widget.
     
    3449* First release.
    3550
    36 == Features ==
    37 
    38 * Create and edit custom badges and badge conditions.
    39 * Manually award/ revoke badges.
    40 * Automatically check badge conditions and award badges after user creates a new post.
    41 * Dashboard administration.
    42 
    4351== Limitations ==
    4452
    4553* Does not support OR conditions or nested conditions.
    4654* The current version only supports limited object types: post_tag, post_count and comment_count.
    47 * Conditions cannot be restricted by post type or category (without modifying plugin code).
    48 
    49 
    50 For more info, visit [blarrr](http://blarrr.com/wordpress-badges-plugin/).
     55* Conditions cannot be restricted by post type or category without modifying plugin code.
  • rockhoist-badges/trunk/rh-badges.php

    r362839 r364169  
    22/*
    33Plugin Name: Rockhoist Badges
    4 Version: 1.1
     4Version: 1.2
    55Plugin URI: http://blarrr.com/wordpress-badges-plugin/
    66Description: A Stack Overflow inspired plugin which allows users to acquire badges. Badges are created and managed through the standard WordPress Dashboard.
     
    2929
    3030// Change Log
    31 $current_version = array('1.1');
     31$current_version = array('1.2');
    3232
    3333// Database schema version
     
    140140    if ( empty($filter ) ) { $filter = array(); }
    141141   
    142     $sql = 'SELECT badge_id, name, description, type FROM ' . $wpdb->prefix . 'rh_badges';
    143        
     142    // Select all rows by default
     143    $sql = 'SELECT badge_id, name, description, type FROM ' . $wpdb->prefix . 'rh_badges b WHERE 1=1';
     144       
     145    // If a user ID was entered.
     146    if ( array_key_exists('user_ID', $filter) ) {
     147           
     148        $user_ID = $filter['user_ID'];
     149           
     150        // Join the rh_user_badges table.
     151        $sql = 'SELECT b.badge_id, b.name, b.description, b.type
     152                FROM ' . $wpdb->prefix . 'rh_badges b,
     153                    ' . $wpdb->prefix . 'rh_user_badges ub
     154                WHERE b.badge_id = ub.badge_id
     155                AND ub.user_id = ' . $user_ID;
     156
     157    }
     158
    144159    // If a badge ID was entered.
    145     if (array_key_exists('badge_ID', $filter)) {
     160    if ( array_key_exists('badge_ID', $filter) ) {
    146161           
    147162        $badge_ID = $filter['badge_ID'];
    148163           
    149164        // Append a WHERE clause to the SQL.
    150         $sql .= " WHERE badge_id = $badge_ID";
     165        $sql .= " AND b.badge_id = $badge_ID";
    151166    }
    152167                       
     
    156171}
    157172
    158 function rhb_list_badges() {
     173function rhb_list_badges( $filter = '' ) {
     174   
     175
     176    if ( empty($filter ) ) { $filter = array(); }
    159177
    160178    print '<div id="badge-table">
    161179        <table>
    162180            <tbody>';
    163    
    164             foreach (rhb_get_badges() as $badge) {
     181           
     182            foreach (rhb_get_badges( $filter ) as $badge) {
    165183           
    166184            print '<tr>
Note: See TracChangeset for help on using the changeset viewer.