WordPress.org

Ready to get started?Download WordPress

Plugin Directory

BuddyPig

A quiz game built on BuddyPress that asks you questions about your fellow members. Built for an Automattic hack day.

Example setup

You have to tell PIG what profile items to use and how to ask the questions. We gave you a function called pig_register_question() to do just that. By default, pig_register_question() takes 2 arguments, the BuddyPress profile field name and a format to use to ask the question. Here's an example:

pig_register_question( 'Address', 'Where does %s live?' );

You'll notice the %s in the question format, which is where we drop in the user's name that the question is about. If you've written PHP before, you may recognize this syntax from the sprintf() function, which is what is used behind the scenes.

You'll also have to tell PIG what BuddyPress group to use, which can be done with pig_set_group() by passing the group's ID. Here's an example:

pig_set_group( 1 );
pig_register_question()

can take two additional arguments. The first one tells PIG whether to make the name possessive when it asks the question. For example, "Where was Beau born?" would not be possessive, but "Where is Beau's house?" would be. If you want PIG to make the name possessive, you can add true as the third argument, like this:

pig_register_question( 'Address', 'Where is %s house?', true );

The last optional argument is a callback. PIG can format answers for you before displaying them. One use case of this is deduplicating multiple phrases that mean the same thing, like "United States" and "USA". If you use this callback, you must also make sure the function exists for PIG to call. Here's an example:

pig_register_question( 'Address', 'Where is %s house?', 'a8c_dedupe_countries' );
function a8c_pig_dedupe_countries( $country ) {
    $usa_versions = array( 'US', 'USA', 'United States', 'U.S.A', 'U.S.', 'America', 'United States of America' );
    $uk_versions = array( 'UK', 'U.K.', 'United Kingdom' );
    foreach ( $usa_versions as $usa_version ) {
        if ( strtolower( $country ) == strtolower( $usa_version ) )
            return 'United States';
    }

    foreach ( $uk_versions as $uk_version ) {
        if ( strtolower( $country ) == strtolower( $uk_version ) )
            return 'United Kingdom';
    }

    return $country;
}

You can put these setup calls into your own plugin and activate it just like any other. If you insist, you could also put them into your theme's functions.php file. To make sure they're loaded after PIG is setup, you can hook them to the pig_loaded action.

Requires: 3.4 or higher
Compatible up to: 3.4.2
Last Updated: 2012-12-20
Downloads: 1,725

Ratings

4 stars
4.5 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1
100,2,2
0,2,0