• Resolved Mikel

    (@ogmic)


     * Multiply Point Payouts
     * @since 1.0
     * @version 1.0
     */
    function mycred_pro_balance_adjustment_multiply( $request, $mycred ) {
    
    	// Get the user ID
    	$user_id = absint( $request['user_id'] );
    
    	// Ignore admins
    	if ( user_can( $user_id, 'edit_users' ) ) return $request;
    
    	// If user is an editor, quadruple the amount
    	if ( user_can( $user_id, 'moderate_comments' ) )
    		$request['amount'] = $request['amount'] * 4;
    
    	// If user is a author, triple the amount
    	elseif ( user_can( $user_id, 'publish_posts' ) )
    		$request['amount'] = $request['amount'] * 3;
    
    	// If user is a contributor, double the amount
    	elseif ( user_can( $user_id, 'edit_posts' ) )
    		$request['amount'] = $request['amount'] * 2;
    
    	return $request;
    
    }
    add_filter( 'mycred_run_this', 'mycred_pro_balance_adjustment_multiply', 10, 2 );

    I found this code on your website; on how to multiply user point based on role…

    But as it is now, it is based on user capabilities… Can you please help re-write the code to work to multiple user roles instead of their capabilities.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @ogmic,
    Thank you for contacting us,
    Please use the code shared below.

    function mycred_pro_balance_adjustment_multiply( $request, $mycred ) {
    
    	// Get the user ID
    	$user_id    = absint( $request['user_id'] );
    
    	// Get the user Data
    	$user       = get_userdata( $user_id );
    
    	// Get the user Roles
    	$user_roles = $user->roles;
    
    	if ( ! empty( $user_roles ) ) {
    
    		// Ignore admins
    		if ( user_can( $user_id, 'edit_users' ) ) return $request;
    
    		// If user is an editor, quadruple the amount
    		if ( in_array( 'editor' , $user_roles ) )
    			$request['amount'] = $request['amount'] * 4;
    
    		// If user is a author, triple the amount
    		elseif ( in_array( 'author', $user_roles ) )
    			$request['amount'] = $request['amount'] * 3;
    
    		// If user is a contributor, double the amount
    		elseif ( in_array( 'subscriber', $user_roles ) )
    			$request['amount'] = $request['amount'] * 2;
    	}
    
    	return $request;
    
    }
    add_filter( 'mycred_run_this', 'mycred_pro_balance_adjustment_multiply', 10, 2 );
    Thread Starter Mikel

    (@ogmic)

    Thanks so so much

    Hi @ogmic,
    We hope you loved the plugin. If you do, we would appreciate a kind and honest review.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help rewrite a code’ is closed to new replies.