Skip to:
Content
Pages
Categories
Search
Top
Bottom

Suggested integration

  • Avatar of Hugo
    Hugo
    Moderator

    @hnla

    As you have integrated a number of other plugins to the points system i.e ‘Links’ it might be worth considering working in Boonegorges ‘Invite Anyone’ plugin. If the points system is used in the attempt to create and foster site activity then members inviting new members to join ought to be rewarded., probably on the acceptance of an invite e.g the members invite list shows an accepted ‘True’ in the DB rather than on the simple act of sending an invite otherwise joeuser@example.com might be sent rather a lot of invites.

Viewing 25 replies - 1 through 25 (of 62 total)
  • Avatar of Tosh
    Tosh
    Participant

    @xberserker

    I did look into the invite anyone plugin. So far I just have the invite my email giving points correctly.

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Not sure it’s such an easy one as most functions seem to rely on an action of the logged in user to add/update points whereas the action of the table updating the field is_joined from 0 to 1 ‘accepted’ is not reliant on a logged in user so I guess there would need to be a function that ran and queried the table for is_joined = 1 along with inviter_id to find which user to give the points to, not sure how that would be triggered though or how to ensure that points weren’t awarded for is_joined that had already been checked.

    Completely off tangent but sadly find that although the DB prefix issue for wpmu was cleared up there appears to be a major issue with being able to extract top lists or top tens as the functions are passing invalid arguments to the foreach loop where an array must be passed to foreach it appears not to be, It’s odd as it’s mentioned twice on the cubepoints site comments and the second time the only response was to ask for details via email but no clear up of the issue, it’s a pity as without these functions it’s not possible to construct a meaningful member display page.

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    Ya, it will be more complicated that’s for sure. CubePoints doesn’t officially support WordPressMU.

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    No it doesn’t officially support it but it can deal with the wpmu DB prefix, so really one wonders why dragging out user data is such an issue, which is all it seems to be must be something to do with the mu users status as subscribers to the main blog but not having higher privileges or something.

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    Let us know what you figure out.

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    @xberserker – Let me know where you need hooks in Invite Anyone and I’ll add them.

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    @boonebgorges Oh great! Let’s see.. a do_action for the following if possible:

    Invite New Members
    Group Invite
    Send invitations by email.

    @hnla @dennis_h
    Anyone else have something to add?

    Make so many points (do_action)’s for each individual invite. If not possible, just a general one would work.

    Would would be great if they accepted the invite, then the referrer got the points somehow, but now sure how to do that.. But this is a started point at least.

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Without meaning or wishing to rain on the parade, it’s the referrer aspect that imho is the important aspect I would award big points for invitations accepted i.e invitees actually signing up as that is growing the community but I can’t think out the logic required, but Boone may be able to help. Other than that I think you covered things.

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    Ya, ideally the referrer gets points if the invite is successful. I’m stumped on how to do that right now though ..

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Just to update earlier angst trying to get CP to play nice with WPMU: found and updated the SQL DB queries to prepend the correct prefix. The queries to the user and usermeta tables was using $wpdb->prefix which produces wp_1_ which is the WPMU table prefix and wrong, users and usermeta are prefixed by wp_ cubepoints being designed for single WP doesn’t expect to have to deal with different prefixes it expects all tables to have the same one so $wpdb->prefix is fine in that circumstance. Where queries are made to cubepoint tables this works fine as these are made under the primary blog in WPMU case this is wp_1_ so alls well.

    Dirty hack was to create a new $db_prefix = ‘wp_’ and use that in place of all queries to user and usermeta tables in cubepoint.php

    There is a file provided with these mods in on the cubepoints site in the comments but it is using an old version lacking in much of the newer functionality.

    Avatar of Kunal17
    Kunal17
    Participant

    @kunal17

    @hnla,

    Thanks for the update on the wpmu problem. Would it be possible to post a quick step by step instructions of implementing the solution you have proposed above? I personally have never done any manual tweaking to the database and am afraid of breaking something.

    Thanks again!

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    You don’t need to go near the DB. but you will need to edit the main cubepoints file

    Open cubepoints.php in a suitable text/code editor (line numbers mentioned may not exactly match)

    Near the top locate the block starting at line 11 – after last line 18 ‘load_plugin_textdomain’ add this new line:

    $db_prefix = $wpmuBaseTablePrefix; // Base DB prefix to avoid prepending WPMU prefix for users/usersmeta e.g wp_1_

    Next bit is trickier and probably simplest to try initially simply overwriting a block with what I’ll show below.

    Find the function ‘ function cp_getAllPoints()’ that starts around line 194

    Copy this block:

    function cp_getAllPoints($amt=0,$filter_users=array(),$start=0){
    global $wpdb, $db_prefix;
    if($amt>0){ $limit = ' LIMIT ' . $start.','.$amt; }
    if (count($filter_users)>0){
    $extraquery = ' WHERE '.$db_prefix.'users.user_login != '';
    $extraquery .= implode("' AND ".$db_prefix."users.user_login != '",$filter_users);
    $extraquery .= '' ';
    }
    $array = $wpdb->get_results('SELECT '.$db_prefix.'users.id, '.$db_prefix.'users.user_login, '.$db_prefix.'users.display_name, '.$db_prefix.'usermeta.meta_value
    FROM `'.$db_prefix.'users`
    LEFT JOIN `'.$db_prefix.'usermeta` ON '.$db_prefix.'users.id = '.$db_prefix.'usermeta.user_id
    AND '.$db_prefix.'usermeta.meta_key=''.POINTS.'''.$extraquery.'
    ORDER BY '.$db_prefix.'usermeta.meta_value+0 DESC'
    . $limit . ';'
    ,ARRAY_A);
    return $array;

    }

    And copy over the existing block – make sure you select up to and including the ‘}’ curly brace before the next function starts.

    This should now work, it’s a bit of a dirty hack and I’m sure there’s a better approach, but it works. One thing to remember if you upgrade cubepoints plugin (not the BP plugin tosh has created) you will lose these changes and have to re do them as this is core file.

    Lastly before starting make a copy of cubepoints.php, name it cubepoints.php.original or something and work on the other file that way you can quickly and easily revert back to a working file if things go wrong.

    EDIT/ please note this line above is incorrect (code not being displayed correctly!)
    $extraquery .= ” ‘;

    It should be:

    $extraquery .= singlequote backslash singlequote singlequote semicolon

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    @Kunal17 Hope the above was helpful?

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    I’m adding the following hooks to Invite Anyone, in version 0.6.2 that I’m about to tag:
    – After email invitations are sent,
    do_action( 'sent_email_invites', $bp->loggedin_user->id, $emails, $groups );
    – After email invitations are accepted,
    do_action( 'accepted_email_invite', $user_id, $inviters );

    I use the core groups_send_invites() for group invitations, and there’s already a hook at the end of that function with all the data you’ll need.

    Let me know if there’s anything else I can do!

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    @boonebgorges Thanks! :)
    On the “accepted_email_invite” do_action. Would that give the person who accepted the invite points? Or the referrer?

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    @xberserker $user_id is the person who accepted (the hook happens at the very end of the process, after the person has registered and therefore has a user id), and $inviters should be an array of those people who had sent invitations to that person (the referrers).

    Avatar of Kunal17
    Kunal17
    Participant

    @kunal17

    @hnla,

    Thanks for the instructions. It works now!

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    @boonebgorges oh nice. I’m trying to figure out a similar function with the BuddyPress friend request/accept feature. What I would like to see happen is:

    User sends a friend invite. When the friend request is accepted both the requester and new friend both gets points.

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    I think it’s this (in bp-friends.php)
    do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    @boonebgorges

    I’m using that one actually. But I need to figure out how to give points to both users instead of just the logged in user. This is the API CubePoints uses.

    // Add Points for Accepting a Friend Request
    function my_bp_friend_add_cppoints() {
    if( function_exists(‘cp_alterPoints’) && is_user_logged_in() ){
    cp_alterPoints(cp_currentUser(), get_option(‘bp_friend_add_cp_bp’) );
    cp_log(‘Friend Added’, cp_currentUser(), get_option(‘bp_friend_add_cp_bp’), BuddyPress);
    }
    }
    add_action(‘friends_friendship_accepted’,’my_bp_friend_add_cppoints’);

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    @xberserker

    friends_friendship_accepted passes along three arguments to any function that hooks to it. Try something like this:
    function do_some_stuff( $friendship_id, $inviter_id, $invitee_id ) {
    // Do some stuff here
    }
    add_action( 'friends_friendship_accepted', 'do_some_stuff', 10, 3 );

    The 3 on the add_action is very important, as it makes add_action take all three arguments from friends_friendship_accepted and pass them to do_some_stuff (the number of arguments passed defaults to 1).

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    @boonebgorges

    Thanks I’ll give that a shot. What is the 10 for?

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    10 is the priority, which is used to reconcile when different functions are hooked to the same action. 10’s the default, so putting it there doesn’t change anything, but it’s needed so that 3 is understood as the $accepted_args argument.

    See http://codex.wordpress.org/Function_Reference/add_action

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    I see, thanks! :)

    Avatar of Tosh
    Tosh
    Participant

    @xberserker

    @boonebgorges

    I tried this out, but only the person who accepts the invite gets points instead of both members. This would be the same case with the “accepted_email_invite” do_action on your plugin.

    // Add Points for Accepting a Friend Request
    function my_bp_friend_add_cppoints($friendship_id, $inviter_id, $invitee_id) {
    if( function_exists(‘cp_alterPoints’) ){
    cp_alterPoints(cp_currentUser($inviter_id, $invitee_id), get_option(‘bp_friend_add_cp_bp’) );
    cp_log(‘Friend Added’, cp_currentUser($inviter_id, $invitee_id), get_option(‘bp_friend_add_cp_bp’), BuddyPress);
    }
    }
    add_action(‘friends_friendship_accepted’,’my_bp_friend_add_cppoints’, 10, 3);

Viewing 25 replies - 1 through 25 (of 62 total)

You must be logged in to reply to this topic.