Skip to content

Instantly share code, notes, and snippets.

@timersys
Created June 11, 2014 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timersys/01a00a2f8c2f9885141f to your computer and use it in GitHub Desktop.
Save timersys/01a00a2f8c2f9885141f to your computer and use it in GitHub Desktop.
Cubepoints in Wordpress Social Invitations
<?php
//full file located in functions/cubepoints.php
/* Hook WSI Invitations sent */
add_action( 'wsi_invitation_sent', 'wsi_points', 10 );
function wsi_points( $user_id ) {
//this is not a registered user
if( empty($user_id)) return;
// Grab settings
$points_per_invite = get_option( 'wsi_points_invite' );
$max_invites = get_option( 'wsi_max_invite' );
if ( $max_invites != 0 ) {
// Get number of invites already sent by this user
$existing_number_of_invites = get_user_meta( $user_id, 'wsi_invites_counter', true );
if ( !$existing_number_of_invites ) $existing_number_of_invites = 0;
}
else $existing_number_of_invites = 0;
// Check if this invite gives points
if ( $existing_number_of_invites <= $max_invites ) {
// Give Points
cp_points( 'wsi_sentinvite', $user_id, $points_per_invite, '' );
if ( $max_invites != 0 ) {
// Update counter
$new_number_of_invites = $existing_number_of_invites+1;
update_user_meta( $user_id, 'wsi_invites_counter', $new_number_of_invites );
}
}
}
/* Hook into WSI Invite Acceptance */
add_action( 'wsi_invitation_accepted', 'wsi_accepted', 10, 2 );
function wsi_accepted( $user_id, $stat ) {
// Grab settings
$points_per_accept = get_option( 'wsi_points_accept' );
$max_accepts = get_option( 'wsi_max_accept' );
//this is not a registered user
if( empty($user_id)) return;
if ( $max_accepts != 0 ) {
// Grab inviters existing number of acceptances
$existing_number_of_accepts = get_user_meta( $inviter_id, 'wsi_invite_acceptance_counter', true );
if ( !$existing_number_of_accepts ) $existing_number_of_accepts = 0;
}
else $existing_number_of_accepts = 0;
// Check if this acceptance gives points
if ( $existing_number_of_accepts <= $max_accepts ) {
// Give Points
cp_points( 'wsi_accept_invite', $user_id, $points_per_accept, '' );
if ( $max_accepts != 0 ) {
// Update counter
$new_number_of_accepts = $existing_number_of_accepts+1;
update_user_meta( $inviter_id, 'wsi_invite_acceptance_counter', $new_number_of_accepts );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment