We’ve been accepted!

Allowing users to have more than one Bracket

One of the most frequently asked questions we get about BracketPress is “how can I have my users have multiple brackets?”

Awesomely, the core of BracketPress already has that capability. If you’d like to give an additional bracket (or two) to your users, here’s what you as the site owner can do:

a) Login in to the Administrator
b) Click on “Brackets”
c) Click “Add New”
d) Give the new bracket a title
e) In the content area, type in the shortcode: [bracketpress_display_bracket]
f) Scroll down to “Author” and select the owner of this bracket.
g) Hit “Publish”

Hint: If you don’t see the “Author” section, make sure that it’s enabled in the “screen options” drop-down available from the top right of the Add New Bracket admin screen.

Now, when your user logs in, all their brackets will be listed.

But what if you want to do this automatically? For example, making sure that all of your users have two brackets to start with?

Below is a a function that checks to see how many brackets a user has, and if they don’t have enough, adds them up to the limit.

Chances are, you’ll want to run the function when a user signs on:


add_action( 'wp_login', 'my_bracketpress_add_brackets', 10, 2 );

function my_bracketpress_add_brackets($username, $user) {

$num_brackets = 2;

// Get the brackets for this user
$query = new WP_Query(array('post_type' => 'brackets', "author" => $user->ID) );

// Add a new bracket up to the limit defined in num brackets
for ($i = $query->post_count; $i < $num_brackets) { $title = 'Bracket For ' . $username bracketpress()->create_bracket_post($user->ID, $title, true)

}

}

To put the code in your site, simply use Otto’s pluginception, enter the above code, and activate the plugin. Be sure to change num_brackets to the number of brackets you want each person to have, and feel free to make the bracket title unique to your site.

There’s certainly more you could do. For example, if you get the users role, you could have different levels of users have a different number of brackets. You could also store the number of brackets each user has in the user meta-data, then use Easy Digital Downloads, s2Member, or another ecommerce system to increment the count … thereby “selling” brackets.

We’ll leave the above expansions as an exercise for the reader, as they are very site dependent. However we can provide additional development services on request as time allows.

Master Bracket Tip

BracketPress uses the concept of a “master” bracket for scoring. To use, simply let the system know which Bracket is the “master” in the settings.

Then, when scoring is run, the win / losses are tallied against this bracket.

There are some times when you would prefer for people not to see or comment on your Master Bracket … as it will be empty at least until the first game is played.

In this case, simply set the Master to “Pending Review” or “Draft” – scoring will still happen normally, but your visitors won’t be able to see the master bracket.

Over 100 Downloads!

We feel like this is is just a quick blip on our radar, but at the same time want to take the time to thank everyone for the feedback and support. We hope to see that number climb into the thousands pretty soon! We’d love for you to spread the word about what we are doing.

Our sincerest thanks!

-Team BracketPress