Home Forums Community Total Point Limit and ShareThis Limits

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #12437
    Mike Bua

    Hi, Forum!

    I fall in love with MyCRED and will surely get premuim addons for Version 1.6.

    My current version is 1.5.4. I need help with this version:

    (1) Total Point Limit:
    How can I set a limit of total points? For example, when a member reaches the rank of Gold Level, the highest points are 2000. His activities will not be awarded with points when he reaches 2000 points i.e no 2001 or higher.

    (2) ShareThis Limits:
    How can I set a limit for ShareThis hook? For example, a member can share 5 times per day (possibly 1 facebook, 1 twitter, 1 G+, 1 Pin, 1 Email).

    Best regards,

    Mike

    #12493
    WPExperts

    Hey.

    1) This is one is easy with a code snippet:

    add_filter( 'mycred_add', 'mycred_pro_enforce_max_balance', 90, 3 );
    function mycred_pro_enforce_max_balance( $reply, $request, $mycred ) {
    
    	// Not applicable if already declined or amount is below zero
    	if ( $reply === false || $request['amount'] < 0 ) return $reply;
    
    	extract( $request );
    
    	$max = 2000;
    	$current_balance = $mycred->get_users_balance( $user_id, $type );
    
    	// If we already reached max we decline now
    	if ( $current_balance >= $max )
    		return false;
    
    	// If the user exceeds the limit once this process is finished, decline now.
    	if ( $current_balance + $amount > $max )
    		return false;
    
    	return $reply;
    
    }
    

    This code example will make sure no user can ever earn more then 2000 points. The downside of this however is that if a user has lets say 1990 points and is about to get 20 more, then the script will decline it since 1990 + 20 will exceed the limit. There is a way around this as of 1.6 since then we will be able adjust how much points users gets and using my example tell myCRED that instead of 20 only award 10.

    2) In 1.6 you can set a limit for all built-in hooks. In 1.5.4 you will need to do it via script and code in the limit.

    #12497
    Mike Bua

    WOW! Brilliant Gabriel!

    Very professional and technical responses. I will follow your instructions for V1.5.4.

    I am really looking forward to v1.6.

    Best regards,

    Mike

    #12498
    WPExperts

    Hey.

    If you want to limit the shares in 1.5.4 then the following code snippet needs to be used in your child theme’s functions.php file. It will limit shares to 5 per day but you can change this.

    add_filter( 'mycred_add', 'mycred_pro_enforce_max_balance', 90, 3 );
    function mycred_pro_enforce_max_balance( $reply, $request, $mycred ) {
    
    	// Not applicable for shares
    	if ( $reply === false || $request['ref'] != 'share' ) return $reply;
    
    	extract( $request );
    
    	// Maximum daily limit
    	$daily_limit = 5;
    
    	// Get todays cound
    	global $wpdb;
    
    	// Get the timestamps
    	$now = current_time( 'timestamp' );
    	$today = strtotime( 'today midnight', $now );
    
    	// SQL - Count all log entries for shares, made by this user for this point type today
    	$todays_count = $wpdb->get_var( $wpdb->prepare( "
    		SELECT COUNT(*) 
    		FROM {$mycred->log_table} 
    		WHERE ref = %s 
    		AND user_id = %d 
    		AND time BETWEEN %d AND %d 
    		AND ctype = %s;", 'share', $user_id, $now, $today, $type ) );
    
    	// If no rows are found, the result will be NULL, we need to
    	// convert this into a numeric value for comparison
    	if ( $todays_count === NULL )
    		$todays_count = 0;
    
    	// If we are over the limit, decline
    	if ( $todays_count >= $daily_limit )
    		return false;
    
    	return $reply;
    
    }
    
    #78412
    damytechs

    How can i set maximum limit of share using the default mycred social share button

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
11