Skip to:
Content
Pages
Categories
Search
Top
Bottom

Achievements for actions through other plugins

  • Avatar of noxdineen
    noxdineen
    Member

    @noxdineen

    I’m using BP Album+ (soon to become BP Media, I hope), and I’d really like to encourage uploading photos by tying achievements to the action of uploading images to your album.

    I see that Invite Anyone actions are already possible to associate with achievements, so I assume this is possible. Could you point me in the right direction please?

Viewing 8 replies - 1 through 8 (of 8 total)
  • http://achievementsapp.com/developer/add-support-for-a-plugin-non-custom-post-type/

    Let me know if you get stuck. I’ve thought about adding support in core for BP Media, but I too am waiting on its next big release.

    I added a record into “wp_achievements_actions”, like category=custom, name=test_event, description=a test!, is_group_event=0. Now I see the event show up in “Other” when I’m in the “create achievements” form when I select “event”. Cool!

    When I reload the achievement details page after I created it, the % goes up every time I reload the page. Now I haven’t even added any code or anything. Shouldn’t it only increment when I have it bound to an action and it’s called like dpa_handle_action(‘test_event’, $args….)?

    Ultimately, I have a method that inserts a record into a custom table based on a set of criteria. It would be nice to figure out how to trigger an event and have the custom achievement increment when this happens. Perhaps I’m missing something really basic?

    Cool plugin!

    I’m still kinda new to WordPress but I’m a fairly seasoned PHP dev. What I learned:

    How to cook a custom event


    1) Action must be defined, ie: add_action(‘action_name’, ‘function_reference’)
    2) If using a class method for your function method, use an array, ie: add_action(‘action_name’, array(&$obj, ‘function_reference’)
    3) Define your hook by inserting a record in the table `wp_achievements_actions`.
    4) Create a function (in functions.php for example) with the same name you inserted into the actions table, prefixed with `dpa_handle_action_`. So, if you named your action “custom_event” then the method should be called “dpa_handle_action_custom_event()”
    5) The dpa_handle_action_ method should contain a reference to the original action (step 1) like dpa_handle_action(‘action_name’, $parameters). The original example from the website, will work literally for the most basic case:

    `
    function dpa_handle_action_bp_example_send_high_five() {
    $func_get_args = func_get_args();
    dpa_handle_action( ‘bp_example_send_high_five’, $func_get_args );
    }
    `

    From what I understand, the “dpa_handle_action_*” method is absolutely necessary. Without it being defined, the event definition you added to the actions table will always fire. Also, this method is somewhat arbitrary in that it seems to just pass-through any arguments and seems like an ideal place to further qualify if the event contributes towards the achievement or not. An error message would be nice to see in case something isn’t defined properly (but I’m not complaining!!!).

    Anyway, I hope these details are helpful for the next developer who gets stuck on how to integrate achievements into their app.

    Well done :) Could you let me know what part of the documentation you found (or maybe you didn’t find it; on achievementsapp.com) tricky to understand so I can improve it?

    As you found, the dpa_handle_action is required. I found a better way to do that, via create_function, have a look in my development SVN on http://code.google.com/p/achievements/source/detail?r=926 (click on the “+”).

    The reason for the intermediate function is because the do_action’s arguments weren’t being passed along to the main handler if triggered directly from another action; something to do with the argument references (it’s been too long since I wrote this to remember 100% without checking in a bit more detail, and it’s a bit too early here to write anything elegantly!).

    Given the context of the type of developer that would potentially find your documentation useful, it’s somewhat appropriate. My issue was that I have a fairly large project that is loosely integrated with wordpress. A lot of my database inserts are performed outside any do_action() or any “official hooks”. I think one thing that threw me off with the example was if the filter method was required or not. I said to myself “What is this filtering business about?!”.

    If anything, it would be helpful to have a very literal example that could be copied and pasted along with more complete explanation of the function reference (Are the parameters stings, arrays, mixed, etc.). Also some links to the codex for hooks relative to plugin integration would be nice but not necessary.

    I want to dive into your code a bit more and have a look around. Actually, I was developing my own achievements plugin before I found yours and decided “I’m wasting my time!”. Perhaps there’s a few components that you could find useful – like a real-time notification framework. I’m at least going to finish that at some point.

    One thing I’m curious about was how events are qualified towards achievements. Are events totaled in some arbitrary space or is there just some select query that returns a count on every page-hit? It will be fun to read through some of the code over the next week.

    Your updated source looks a bit cleaner. It’s rare that I’ve found a use for the create_function method. Good stuff.

    Avatar of dragosstancu
    dragosstancu
    Member

    @dragosstancu

    Paul,

    First of all, thanks a lot for this plugin!

    Question:

    I added my own code, in functions.php:
    `
    function wf_unlock_achievement_coins_register() {
    global $bp;
    $user_id=bp_loggedin_user_id();
    if($user_id>0){
    do_action(‘coins_register’,$user_id);
    }
    }

    function dpa_handle_action_coins_register() {
    $func_get_args = func_get_args();
    dpa_handle_action( ‘coins_register’, $func_get_args );
    }

    function wf_record_coins_register() {
    bla ….
    }
    add_action(‘coins_register’, ‘wf_record_coins_register’);

    When I call wf_unlock_achievement_coins_register() from my register coin page, it happens only once. Is that supposed to be the way it works?
    I want to keep giving points to users for registering more coins.

    Is there a parameter/setting i’m missing?

    Thanks a lot mate!

    Avatar of dragosstancu
    dragosstancu
    Member

    @dragosstancu

    The same time, the login achievement action gives points like crazy! maybe I messed up something :)

Viewing 8 replies - 1 through 8 (of 8 total)

The forum ‘Achievements’ is closed to new topics and replies.