WPExperts

Having trouble getting myCRED to work as described in the documentation? Open a support ticket! Issues or bug reports posted in the forums will be deleted. Helping out other members or answering questions will get you free Tokens that you can use as payment in the store.

Forum Replies Created

Viewing 15 posts - 2,281 through 2,295 (of 2,309 total)
  • Author
    Posts
  • in reply to: myCRED as a Time Bank with positive/negative limits #4344
    AvatarWPExperts

    Hey.

    Looking at your code, the filter will return a negative value which will allow your users to transfer points even if their account goes minus.

    The only “downside” of this is that the values are hardcoded into your script so if you want to change it or add new ranks, you would need to update your code accordingly.

    I would add a custom meta box to ranks where you can enter the transfer limit for each rank and then use a quick DB query to return the set value.

    add_filter( 'mycred_transfer_acc_limit', 'mycred_adjust_transfer_limit' );
    function mycred_adjust_transfer_limit( $limit = 0 ) {
    	// Get users rank ID
    	$users_rank = mycred_get_users_rank( get_current_user_id(), 'ID' );
    
    	global $wpdb;
    
    	// Get all ranks that has a transfer limit
    	$ranks = $wpdb->get_results( $wpdb->prepare( "
    SELECT p.ID as rank_id, p.post_type as type, pm.meta_value as transfer_limit 
    FROM {$wpdb->posts} p
    INNER JOIN {$wpdb->postmeta} pm 
    	ON ( p.ID = pm.post_id AND pm.meta_key = %s ) 
    WHERE p.post_type = %s ", 'transfer_limit', 'mycred_rank' ) );
    
    	if ( $ranks ) {
    		foreach ( $ranks as $rank ) {
    			if ( $rank->rank_id == $users_rank )
    				return $rank->transfer_limit;
    		}
    	}
    
    	// Default
    	return $limit;
    }
    

    In the above code I would have saved the limit under the ‘transfer_limit’ meta key.

    in reply to: myCRED as a Time Bank with positive/negative limits #4318
    AvatarWPExperts

    Hi.

    Users balances can go minus or plus, thats up to you. The only limit is, as you correctly pointed out the mycred_transfer_acc_limit which by default is set to zero.

    Since Ranks are just a custom post type, you could add a custom meta box to the ranks edit page and save a limit for each rank that you then enforce via the mycred_transfer_acc_limit filter.

    in reply to: Leaderboard, how to use total vs current? #4317
    AvatarWPExperts

    Hi.

    If you feel comfortable with SQL Queries, there is the mycred_ranking_sql filter which is used by the leaderboard to get the results.

    in reply to: Change Rank Name #4284
    AvatarWPExperts

    Hey.

    The above code would go in your themes functions.php file or in your custom plugin (if you are creating one).

    You can pretty much change anything about the “Rank” post type via this filter except for the post type id, which is set to “mycred_rank”.

    And a Merry Christmas to you too.

    in reply to: Hide content if points have been awarded #4275
    AvatarWPExperts

    Hey.

    First of all, please use some sort of code paste bin for larger set of codes!

    Second, your last code snippet has two has_entry checks. Why? You should only have as you are now using one extra database query for each time the shortcode is used.

    Thirdly, you are showing one image when a user has received points already, if you want to show another image if the user not, then you would need to add this after an else statement.

    Also you have inserted an image to show when a user gets points when the shortcode does not use the daily limit but you have not done so when you do use the daily limit.

    Here is an updated example.

    in reply to: Change Rank Name #4273
    AvatarWPExperts

    Hi.

    You can use the mycred_register_ranks filter which is used when the “Rank” post type is registered with WordPress. You could change the labels used for Ranks to anything you want.

    Example:

    add_filter( 'mycred_register_ranks', 'mycred_pro_adjust_rank_post_type' );
    function mycred_pro_adjust_rank_post_type( $args ) {
    	$args['labels']['name'] = 'Reputation';
    	$args['labels']['singular_name'] = 'Rep';
    	
    	return $args;
    }
    

    For more information on what arguments are available, you can consult the WordPress Codex for the register_post_type function.

    in reply to: Spend Token to Create WooCommerce Coupons #4258
    AvatarWPExperts

    Excellent. Just remember to use pastebin or similar for larger code snippets.

    in reply to: Spend Token to Create WooCommerce Coupons #4255
    AvatarWPExperts

    Hey.

    Here is a shortcode that will convert points into coupons.

    Installation:
    1. Insert code snippet into your themes functions.php file.
    2. Adjust the language used in the script.
    3. Upload.

    How it works:
    The shortcode will return a form where the current logged in user can nominate the amount of points they want to convert into a coupon.

    The amount it then taken from the users balance (if they have enough) and a coupon is generated when the page re-loads. The user will then be able to use the generated coupon code in the store.

    Remember that this shortcode will assume that 1 point = 1 your currency. So if you have a different exchange rate you would need to add this into the code yourself by adjusting $amount on line 36.

    in reply to: Hide content if points have been awarded #4246
    AvatarWPExperts

    Hey!

    You would need to adjust the shortcode to instead of just returning when a user has received points for today, show them your image before returning.

    On line 49 in the pastebin code you will find:

    if ( $mycred->has_entry( $ref, $today, $user_id ) ) return;
    

    Change it to something like this:

    // If user has received points today show image.
    if ( $mycred->has_entry( $ref, $today, $user_id ) ) {
    	return '<img src="https://mysite.com/gotpoints.jpg" alt="" />';
    }
    
    in reply to: This week leaderboard with users avatars #4046
    AvatarWPExperts

    Excellent.

    You can always reach me via the contact page. If none of the premium add-ons are to your liking and you would like to donate to the plugin, you can do so here.

    in reply to: This week leaderboard with users avatars #4038
    AvatarWPExperts

    Hey.

    For larger codes, please use pastebin or similar to make it easier to read.

    Your issue is that you just copy pasted the get_avatar function with $row[‘ID’] which does not exists.

    Looking at your code, you have the users ID stored under $data->user_id. Change the following line:

    echo '<li><span class="lbnametop">' . $avatar = get_avatar( $row['ID'], 64 )  
    . $data-> display_name . '</span><span class="lbscoretop">' . $mycred->format_creds( $data->total ) . ' točk</span></li>';
    

    to:

    echo '<li><span class="lbnametop">' . $avatar = get_avatar( $data->user_id, 64 )  
    . $data-> display_name . '</span><span class="lbscoretop">' . $mycred->format_creds( $data->total ) . ' točk</span></li>';
    
    in reply to: This week leaderboard with users avatars #4036
    AvatarWPExperts

    Hi Gregor.

    Each “row” in the leaderboard can be adjusted via the mycred_ranking_row filter. This means that we could add a custom template tag like %avatar% in our row template then hook in via the mentioned filter and replace this custom template tag with the users avatar.

    Example row template:
    %avatar% %display_name%

    Example filter:

    add_filter( 'mycred_ranking_row', 'my_custom_ranking_rows', 10, 4 );
    function my_custom_ranking_rows( $layout, $template, $row, $position )
    {
    	$avatar = get_avatar( $row['ID'], 32 );
    	return str_replace( '%avatar%', $avatar, $layout );
    }
    

    You can add any custom template tag via this filter as long as you understand that all rows will show, in this example, the users avatar.

    If you only want show a users avatar for lets say just the first place, you could check their position:

    add_filter( 'mycred_ranking_row', 'my_custom_ranking_rows', 10, 4 );
    function my_custom_ranking_rows( $layout, $template, $row, $position )
    {
    	// Not first place, remote the tag and show no avatar
    	if ( $position != 1 ) {
    		return str_replace( '%avatar%', '', $layout );
    	}
    	// First place, show avatar
    	else {
    		$avatar = get_avatar( $row['ID'], 32 );
    		return str_replace( '%avatar%', $avatar, $layout );
    	}
    }
    

    The above filter code goes into your themes functions.php file

    in reply to: Is it possible to show an image after the number? #3955
    AvatarWPExperts

    Hi.

    You can add an image via the mycred_format_creds filter which is used before points are displayed with the suffix or prefix you have.

    Example 1 – Add image directly after the format number:
    Any prefix or suffix used under settings are also inserted.

    add_filter( 'mycred_format_creds', 'adjust_how_points_look', 10, 3 );
    function adjust_how_points_look( $string, $amount, $mycred  ) {
    	return $string . '<img src="https://yoursite.com/image.jpg" alt="" />';
    }
    

    Example 2 – Add image directly after the unformated points value:
    Any prefix or suffix set under your settings are not shown here.

    add_filter( 'mycred_format_creds', 'adjust_how_points_look', 10, 3 );
    function adjust_how_points_look( $string, $amount, $mycred  ) {
    	return $amount . '<img src="https://yoursite.com/image.jpg" alt="" />';
    }
    
    in reply to: Recording '0' cred events (posting over daily limit, etc) #3905
    AvatarWPExperts

    Hey Joe.

    You can not use myCRED to log zero transactions but that does not mean you can not log zero yourself. Have a look at how myCRED normally does it in the mycred-functions.php file starting at line 925.

    Regarding min. character requirements, I would hook into mycred_add and insert he check there. So if the reply is less then x characters, I would tell myCRED not to award points.

    Example:

    add_filter( 'mycred_add', 'min_char_count_for_topics', 12, 3 );
    function min_char_count_for_topics( $reply, $request, $mycred ) {
    	if ( $reply === false ) return $reply;
    
    	// Only target new forum replies
    	if ( $request['ref'] == 'new_forum_reply' ) {
    		// Reply ID is stored under ref_id
    		$reply_id = $request['ref_id'];
    		// Get the reply post object
    		$reply = bbp_get_reply( $reply_id );
    		if ( isset( $reply->post_content ) ) {
    			// Min. 10 characters else no points.
    			if ( strlen( $reply->post_content ) < 10 )
    				return false;
    		}
    	}
    
    	return $reply;
    }
    
    in reply to: Deduct a transaction fee #3888
    AvatarWPExperts

    Since points are stored as a user meta, you would need to have a user account on your website that you use as “Bank”. Then when you charge your fee, you deposit the fee into the “Bank” account.

Viewing 15 posts - 2,281 through 2,295 (of 2,309 total)
11