Filters

Estimated reading: 70 minutes 1573 views

mycred_add

Package: mycred/balance Category: Filters
 

Description

This filter is one of the most central filters in myCRED. Each time a user is to gain or loose points, the request is passed through this filter to allow external parties or custom code snippets from stopping a transaction.

When using this filter, keep in mind other scripts that also use this filter. Code snippets using this filter before your code snippet fires might have already declined the transaction which you will need to honour.

 

Parameters

ParamTypeRequiredDescription
$replyBOOLYes

The result of this filter. Should either be true (run the request) or false (stop the request).

$requestARRAYNo

The request array with information that will be passed on to the processor if the request is approved. The array structure is the same as the log structure.

$mycredOBJNo

The current myCRED_Settings class object.

 

Used By

PackagePrio.Description
mycred/banking1The central banking service uses this filter to stop transactions if the central bank runs out of points.

Examples

Example 1: Stop user 1 from gaining points for approved comments.

Example 2: Prevent your users balance from going minus.

 

mycred_add_finished

Package: mycred/balance Category: Filters
 

Description

This filter is the last filter that runs once a transaction has been processed, no matter of the outcome. You can use this filter to detect point gains / loses in order to do some custom tasks based on the request.

 

Parameters

ParamTypeRequiredDescription
$resultBOOLYes

The transaction result. Returns either TRUE if the transaction was executed or FALSE if the transaction was declined.

$requestARRAYNo

The transaction request that was processed as returned by the mycred_run_this shortcode.

$mycredOBJNo

The myCRED_Settings class object processing the transaction request.

Used By

PackagePrio.Description
mycred/rank20Used to determine if the transaction promotes or demotes a users rank.
mycred/badge30Used to determine if a successful transaction should earn the user a badge.
mycred/notice40Used to determine if the transaction should trigger a popup notification.
mycred/email50Used to determine if the transaction should trigger an email notification.

Example

Example 1: Send an email when a user buys points using the buyCRED add-on.

 

mycred_affiliate_cookie

Package: mycred/core Category: Filters
 

Description

This filter allows you to change the lifespan of the cookies your users receive from the “Points for referrals” hook. By default the cookies lifespan is set to 24 hours.

 

Parameters

ParamTypeRequiredDescription
$lifespanINTYes

A unix timestamp when the cookie will expire. By default this is 24 hours from the current time.

$signupBOOLNo

Indicates if this is for the signup (true) or the visitor (false) cookie.

$hookOBJNo

The Points for Referrals hook class object.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Change the cookies lifespan from 24 hours to 1 year.

 

mycred_affiliate_key

Package: mycred/core Category: Filters
Description

This filter allows you to adjust the affiliate referral key that the hook uses. By default this is mref.

 

 

Parameters

ParamTypeRequiredDescription
$keySTRINGYes

The key. Defaults to mref.

$hookOBJNo

The hook object.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Change the affiliate key in myCRED to “affiliate_id“ instead of “mref“.

 

Example 2: Change the affiliate key only for a custom point type. Keep the default one for the default point type.

 

mycred_all_references

Package: mycred/log Category: Filters
 

Description

This filter allows you to add / remove / rename any of the built-in myCRED references.

 

Parameters

ParamTypeRequiredDescription
$listARRAYYes

An associative array of references that have been registered in myCRED.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Add a custom reference.

 

 

mycred_allowed_tags

Package: mycred/log Category: Filters
 

Description

This filter allows you to change the HTML elements that myCRED will allow in the history shortcode.

 

Parameters

ParamTypeRequiredDescription
$allowedARRAYYes

Array of HTML elements and their attributes that are allowed to be used.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Change the allowed HTML elements to only accept paragraphs and Emphasized text.

 

 

mycred_apply_exchange_rate

Package: mycred/core Category: Filters
 

Description

This filter allows you to change the results of the apply_exchange() class method in the myCRED_Settings object. This class method is used by the MarketPress and WooCommerce payment gateways to calculate the cost of an order in points.

 

 

Parameters

ParamTypeRequiredDescription
$exchangeINT or FLOATYes

The final exchange value.

$amountINT or FLOATNo

The amount to be exchanged. Usually a real life currency.

$rateINT or FLOATNo

The exchange rate being applied to $amount in order to get the $exchange.

$roundBOOLNo

Indicates if the amount should be rounded (TRUE) or not (FALSE).

Used By

PackagePrio.Description
mycred/payment10MarketPress payment gateway.
mycred/payment20WooCommerce payment gateway.

 

mycred_badge_image

Package: mycred/badge Category: Filters
 

Description

This filter allows you to adjust the badge image element before it is rendered.

 

Parameters

ParamTypeRequiredDescription
$htmlSTRINGYes

The badge image element.

$imageINT or STRINGNo

Either main when the main badge image is requested or the image level. Note that image levels start from zero and not one. So if your badge only has one level, that first level will have the ID zero.

$badge_objectOBJNo

The myCRED_Badge object.

Used By

PackagePrio.Description
Not used by any built-in package.
Example

Example 1: Add a Bootstrap tooltip to all badge images except for the main badge image.

 

mycred_badge_user_value

Package: mycred/badge Category: Filters
 

Description

This filter allows you to adjust the value that badges add-on saves when a user earns a new badge / badge level. By default, the add-on saves the badges level ID but if you do not use levels you can use this to store other types of data as long as it is a string or integer value.

 

Parameters

ParamTypeRequiredDescription
$new_levelINTYes

The new level ID a user earned. Remember that Level IDs start from ZERO and not from 1.

$user_idINTNo

The users WordPress id.

$badge_idINTNo

The badges post object ID.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_banking_save_interest

Package: mycred/banking Category: Filters
 

Description

This filter allows you to add or adjust the settings saved by the compound interest banking service.

 

Parameters

ParamTypeRequiredDescription
$settingsARRAYYes

An associative array of settings for the service.

$serviceOBJNo

The Compound Interest class object.

$rescheduledBOOLNo

Returns true if the service was re-scheduled or false if not.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_banking_save_recurring

Package: mycred/banking Category: Filters
 

Description

This filter allows you to save custom settings you might have added to the Recurring Payout service in the Banking add-on.

 

Parameters

ParamTypeRequiredDescription
$settingsARRAYYes

An associative array of settings for the service.

$serviceOBJNo

The Recurring Payout class object.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_bp_leaderboard_{$column_id}_column

Package: mycred/buddypress Category: Filters
 

Description

This filter allows you to render the contents of a custom leaderboard column in the myCRED BP Group Leaderboards plugin.

 

Parameters

ParamTypeRequiredDescription
$contentSTRINGYes

The column content as a string.

$rowOBJNo

The leaderboard row object.

$group_idINTNo

The current BuddyPress Group ID.

$point_typeSTRINGNo

The myCRED point type key the leaderboard is based on.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Render the content of a custom leaderboard column we created with the ID “avatar“.

 

 

mycred_bp_leaderboard_columns

Package: mycred/buddypress Category: Filters
 

Description

This filter allows you to adjust the leaderboard table columns that the myCRED BP Group Leaderboards plugin creates.

 

Parameters

ParamTypeRequiredDescription
$columnsARRAYYes

An associative array of column IDs and their labels.

Default columns:

Column IDDescription
positionThe users leaderboard position.
memberThe group member.
balanceThe point value.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Rename the position column to “Rank“ in BP Group Leaderboards.

 

Example 2: Re-order the leaderboard columns.

Example 3: Add a custom column called “Avatar“ for leaderboards.

 

mycred_bp_leaderboard_find_position

Package: mycred/buddypress Category: Filters
 

Description

This filter allows you to adjust or query a users leaderboard position. The myCRED BP Group Leaderboard plugin will cache the users position automatically, which means that this filter only fires when the cache has been deleted and a new query is needed. This means you do not need to check if a cached version exists when this filter runs.

 

Parameters

ParamTypeRequiredDescription
$positionINTYes

The users numeric position in the leaderboard.

$group_idINTNo

The BuddyPress Group ID.

$user_idINTNo

The numeric WordPress user ID.

$point_typeSTRINGNo

The point type key the leaderboard is based on.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Example showing how we can query a users position in an annual leaderboard.

 

 

mycred_bp_leaderboard_get

Package: mycred/buddypress Category: Filters
 

Description

This filter allows you to adjust or run your own custom query for BuddyPress leaderboards. This filter used by the myCRED BP Group Leaderboards plugin. The filter is used each time a leaderboard is rendered so it is important that you cache your results to prevent having to run potentially expensive queries on every page load.

 

Parameters

ParamTypeRequiredDescription
$leaderboardARRAYYes

The leaderboard array.

$group_idINTNo

The BuddyPress Group id.

$point_typeSTRINGNo

The myCRED point type the leaderboard is based on.

$append_userINT or BOOLNo

The WordPress user ID of a user to append to the end of the leaderboard. FALSE if no appending should occur. Note that users that are excluded from the point type will never be appended to  leaderboard so there is no need in your script to check if the user ID is excluded or not.

$freshBOOLNo

TRUE if a new fresh query should be made (ignoring cached results) or FALSE if cached results should be used (if one exists).

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Example of how to run a custom leaderboard query based on annual point gains.

 

 

mycred_bp_leaderboard_types

Package: mycred/buddypress Category: Filters
 

Description

This filter allows you to adjust, add or remove leaderboards types in the myCRED BP Group Leaderboards plugin.

 

Parameters

ParamTypeRequiredDescription
$leaderboardsARRAYYes

An associative array of leaderboard type keys and labels.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Example on how to remove one type and adding another.

 
				
					function mycred_pro_adjust_bp_leaderboard_types( $leaderboards ) {

	// Remove total balance lederboards
	unset( $leaderboards['total'] );

	// Add a custom leaderboard
	$leaderboards['year'] = 'Annual Leaderboard';

	return $leaderboards;

}
add_filter( 'mycred_bp_leaderboard_types', 'mycred_pro_adjust_bp_leaderboard_types' );
				
			

 

mycred_bp_rank_in_header

Package: mycred/rank Category: Filters
 

Description

This filter allows you to adjust the way ranks are rendered in the BuddyPress user profile header (if used).


Parameters

Param Type Required Description
$content STRING Yes

The rendered HTML elements.

$user_id INT No

The user ID of the profile where the ranks are being rendered.

$buddypress OBJ No

The BuddyPress module class object.

Used By

Package Prio. Description
Not used by any built-in package.

Example

Example 1: Only show the users rank title without any extra HTML elements in their profile header.

 

 

mycred_bp_rank_in_profile

Package: mycred/rank Category: Filters
 

Description

This filter allows you to adjust the way ranks are rendered in the BuddyPress user profile (if used).

 

Parameters

ParamTypeRequiredDescription
$contentSTRINGYes

The rendered HTML elements.

$user_idINTNo

The user ID of the profile where the ranks are being rendered.

$buddypressOBJNo

The BuddyPress module class object.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Only show the users rank title without any extra HTML elements in their profile header.

 

 

mycred_buycred_get_cost

Package: mycred/purchase Category: Filters
 

Description

This filter allows you to adjust the cost of buying points using the buyCRED add-on. This filter is used both when calculating the cost when the request is made and when the payment gateway verifies the amount the user actually paid.

 

Parameters

ParamTypeRequiredDescription
$costINT or FLOATYes

The cost of the purchase.

$amountINT or FLOATNo

The amount of points being purchased.

$typeSTRINGNo

The point type key being purchased.

$gateway_prefsARRAYNo

The selected payment gateways settings.

$buycred_prefsARRAYNo

The buyCRED add-ons settings.

 

Used By

PackagePrio.Description
mycred/purchase10Used by the selected payment gateway to calculate the cost.

Examples

Example 1: Adjust the price of buying points based on the amount of points a user selects to buy.

 

Example 2: Apply a 10% discount on point purchases no matter how many points a user buys.

 

Example 3: Apply a 10% discount on purchases of a custom point type, no matter how many points the user selects to buy.

 

 

mycred_central_banking_ignore

Package: mycred/banking Category: Filters
 

Description

Used by the central banking service in the Banking add-on, this filter allows you to inform the add-on which references it should ignore. By default, transfers and interest payouts are ignored by the central bank, preventing large number of log entries to be saved with each event.

 

Parameters

ParamTypeRequiredDescription
$referencesARRAYYesAn Array of references that should be ignored by the central bank. Defaults to: interestrecurring_payout and transfer.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Add the custom reference “gift“ to the list.

				
					function mycred_pro_add_bank_exception( $references ) {

	$references[] = 'gift';
	return $references;

}
add_filter( 'mycred_central_banking_ignore', 'mycred_pro_add_bank_exception' );
				
			

 

mycred_compound_max_limit

Package: mycred/banking Category: Filters
 

Description

This filter allows you to adjust the number of balances the compound interest banking service will process per instance. By default this is 1500. If more then 1500 balances need to be compounded, the compound interest schedule will re-schedule itself and run another 1500 users 2 min later until all balances are processed.

 

Parameters

ParamTypeRequiredDescription
$limitINTYes

The number of balances to compound per instance.

$serviceOBJNo

The compound interest banking service object.

Used By

PackagePrio.Description
mycred/banking10Default usage

mycred_compound_pay_max_limit

Package: mycred/banking Category: Filters
 

Description

This filter allows you to adjust the number of compounded interests the banking service will payout per instance. By default this is 1500. If more then 1500 compounded interests that need to be compounded, the compound interest schedule will re-schedule itself and run another 1500 users 2 min later until everyone has been paid.

 

Parameters

ParamTypeRequiredDescription
$limitINTYes

The number of compounded interests to payout per instance.

$serviceOBJNo

The compound interest banking service object.

Used By

PackagePrio.Description
mycred/banking10Default usage

mycred_decline_store_purchase

Package: mycred/payment Category: Filters
 

Description

This filter allows you to decline a store purchase where points are used as payment. This filter is usable for all supported shopping cart plugins.


Parameters

Param Type Required Description
$result BOOL or STRING Yes

Should return false if the transaction should complete or a string message if the transaction should be declined. This string message is then shown to the user as the reason why the transaction was declined.

$cart ARRAY or OBJ No

This is either the cart object or the order object, depending on the shopping cart plugin used.

$gateway OBJ No

The gateway object.

Used By

Package Prio. Description
Not used by any built-in package.

Example

Example 1: Decline point payment in WooCommerce if a user does not have at least 100 point left after payment.

 

 

mycred_delete_hook_ref

Package: mycred/hook Category: Filters
 

Description

This filter allows you to adjust the reference that the Points for Deleting Content hook uses when awarding / deducting points. Defaults to deleted_content.

 

Parameters

ParamTypeRequiredDescription
$referenceSTRINGYes

The reference to use. Can not be empty or no points will be awarded!

$postOBJNo

The WordPress post object that is getting deleted.

$hookOBJNo

The hook object.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_em_approve_on_pay

Package: mycred/payment Category: Filters
 

Description

When using Events Manager, you can select if bookings should be approved on payment or if admin approval is required. In case you select admin approval, you can use this filter to override this and approve the booking when paid using points.

 

Parameters

ParamTypeRequiredDescription
$overrideBOOLYes

Should return TRUE if the event should be approved or FALSE if not.

$bookingOBJNo

The event booking object.

$gatewayOBJNo

The myCRED Gateway object class.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_email_before_send

Package: mycred/email Category: Filters
 

Description

This filter allows you to adjust the details of an email notification before it is sent.

 

Parameters

ParamTypeRequiredDescription
$emailARRAYYes

An associative array of email details:

  • to – The email recipient
  • subject – The email subject
  • message – The email body
  • headers – The email headers
  • attachments – Email attachments
  • request – The myCRED Request that triggered this email
  • email_id – The email notice id

Used By

PackagePrio.Description
mycred/payment10The WooCommerce gateway uses this filter to render the order details before the email is sent.
mycred/payment20The MarketPress gateway uses this filter to render the order details before the email is sent.
mycred/payment30The WP E-Commerce gateway uses this filter to render the order details beforethe email is sent.
mycred/content40The Sell Content add-on uses this filter to render the purchase details before the email is set.
mycred/transfer50The Transfer add-on uses this filter to render the transfer before the email is sent.

Example

Example 1: Append a footer to all emails sent by the Email Notifications add-on.

 

 

mycred_email_instances

Package: mycred/email Category: Filters
 

Description

This filter allows you to add / remove or adjust email instances that is selectable when creating or editing an email notice.

 

Parameters

ParamTypeRequiredDescription
$instancesARRAYYes

An associative array of grouped email instances.

Instances

Email instances are presented in groups. For example gaining or loosing points are both part of the “General” instance. myCRED groups instances by add-on, so there is one group for “Transfers” which contains two instances: receiving points and sending points.

When you add your own instance, you must select between adding your own group (even if you only want to add one instance) or add your unique instance into an existing group.

Instance Example

This is the “General” group which contains 5 unique instances.

				
					Array
(
    [general] => Array
        (
            [label] => General
            [all] => users balance changes
            [positive] => user gains %_plural%
            [negative] => user lose %_plural%
            [zero] => users balance reaches zero
            [minus] => users balance goes minus
            [end] => 
        )

)
				
			
 

When adding your own group, the settings array must contain at minimum 3 items:

  • label – The label shown in the dropdown menu when editing an email notice. This must always be the first item in the array.
  • yourinstance – A unique ID identifying your custom instance.  This ID is then used by you when you need to identify an instance that should trigger these type of emails.
  • end – Always the last item in the array, this item indicates the end of the group. Left for backwards compatibility.

You might have noticed from the above example that the instance labels are always lowercase. This is because your label will be appended after the sentence: “Send email notice when …”. For example: “Send email notice when … users balance changes”.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Add a custom email instance for when a users balance reaches 1000 points. Insert the instance under the “General“ group.

 

 

mycred_exclude_user

Package: mycred/core Category: Filters
 

Description

This filter allows you to exclude users from using myCRED via script. This filter is part of the exclude_user() method in the myCRED_Settings class and is used extensively in myCRED. Returning true will stop the user in question from gaining points or using myCRED features.


Parameters

Param Type Required Description
$exclude BOOL Yes

Should return TRUE if user is to be excluded or FALSE if not.

$user_id INT No

The ID of the user in question.

$mycred OBJ No

The myCRED_Settings class object being used.

Used By

Package Prio. Description
Not used by any built-in package.

Examples

Example 1: Exclude users with the subscriber role in WordPress from using myCRED.

 

Example 2: Example 2: Exclude users with the Paid Membership Pro level of “Gold“ from using myCRED.

 

Example 3: Exclude subscribers from a custom point type.

Example 4: Exclude users from using points based on their BuddyPress Member Type (2.7+)

 

mycred_export_headers

Package: mycred/core Category: Filters
 

Description

This filter allows you to adjust what columns should be included when myCRED log entries are exported. You can use this in combination with the mycred_log_$column filter to render each columns content.

 

Parameters

ParamTypeRequiredDescription
$headersARRAYYes

An associative array of column ids and their corresponding labels.

$rawBOOLNo

Indicates if the export is selected to be done “raw” TRUE or “formatted” FALSE.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_find_users_rank

Package: mycred/rank Category: Filters
 

Description

Used by the mycred_find_users_rank function, the results of that search is passed through this filter. This allows you to execute custom code when myCRED needs to look if a user gains a new rank.

 

Parameters

ParamTypeRequiredDescription
$resultsOBJ or BOOLYes

The results object or FALSE if no rank was found.

$user_idINTNo

The ID of the user for whom we requested to find a rank.

$point_typeSTRINGNo

The point type for which the rank is queried. Added in 1.6.

Results Object

 PropertyTypeDescription
Results Object (
 rank_idINTThe rank ID a user should have.
current_idINTThe rank ID a user currently have.
minimumINT or FLOATThe minimum point requirement for the rank the user should have.
maximumINT or FLOATThe maximum point requirement for the rank the user should have.
ctypeSTRINGThe point type associated with the rank.
)

Used By

PackagePrio.Description
Not used by any built-in package.
Example

Example 1: Reward users with 10 bonus points each time they gain a new rank. Note that this example assumes users only gain rank and do not get demoted. If they do, they will gain points for that as well.

				
					/**
 * Rank Bonus
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_find_users_rank', 'mycredpro_bonus_points_for_rank', 10, 3 );
function mycredpro_bonus_points_for_rank( $result, $user_id, $point_type ) {

	if ( isset( $result->rank_id ) && $result->rank_id != $result->current_id ) {

		$mycred = mycred( $point_type );

		// Make sure we only give points once for each new rank we get
		if ( ! $mycred->has_entry( 'rank_bonus', $result->rank_id, $user_id ) )
			$mycred->add_creds(
				'rank_bonus',
				$user_id,
				10,
				'Rank bonus',
				$result->rank_id,
				'',
				$point_type
			);

	}

	return $result;

}
				
			

 

mycred_format_creds

Package: mycred/balance Category: Filters
 

Description

This filter allows you to make adjustments to points before they are rendered on your website. If your point type is setup to use a prefix or suffix, these will be attached to the balance when passed through this filter.

Besides the myCRED_Settings class, this filter is also triggered by the AffiliateWP Hook.

 

Parameters

ParamTypeRequiredDescription
$pointsSTRINGYes

The point amount rendered with prefix / suffix (if used).

$amountINT or FLOATNo

The original amount before it was formatted.

$mycredOBJNo

The myCRED_Settings class object.

Used By

PackagePrio.Description
Not used by any built-in package.

Examples

Example 1: Since prefixes and suffixes can not contain HTML in your settings, lets add a FontAwesome icon as a prefix to points before they are rendered.

				
					/**
 * Add FontAwesome Icon to Points
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_format_creds', 'mycredpro_add_html_to_rendered_points' );
function mycredpro_add_html_to_rendered_points( $points ) {

	return '<i class="fa fa-diamond"></i> ' . $points;

}
				
			

Example 2: Adjust the layout of how our custom point type is presented. In this example, we present it as US Dollars with two decimals. Default point type is rendered as is.

				
					/**
 * Adjust Custom Point Type Layout
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_format_creds', 'mycredpro_adjust_custom_point_layout', 10, 3 );
function mycredpro_adjust_custom_point_layout( $points, $amount, $mycred ) {

	if ( $mycred->cred_id == 'mycustomtype' )
		return '$ ' . number_format( $amount, 2, '.', ' ' );

	return $points;

}
				
			

 

mycred_format_number

Package: mycred/balance Category: Filters
 

Description

This filter is used to format a points value before it is displayed. You can use this filter to adjust how points are displayed before the value gets a prefix or suffix appended to it (if used). Not used in point calculations.

 

Parameters

ParamTypeRequiredDescription
$formattedINT or FLOATYes

The point value formatted based on the point type setup.

$numberINT or FLOATNo

The original value.

$mycredOBJNo

The myCRED_Settings class object.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Even though we use decimals, when displaying points, we always display them as integers.

 
				
					/**
 * Hide Using Decimals
 * Show points without decimals.
 * @version 1.0
 */
function mycred_pro_hide_decimals( $creds, $number ) {

	return number_format( $number, 0, '.', '' );

}
add_filter( 'mycred_format_number', 'mycred_pro_hide_decimals', 10, 2 );
				
			

 

mycred_get_content_price

Package: mycred/content Category: Filters
 

Description

This filter allows you to adjust the price of a content that has been set for sale using the Sell Content add-on. If you are looking to customize who needs to pay for the content, consider using the mycred_user_has_paid_for_content filter instead.

 

Parameters

ParamTypeRequiredDescription
$priceINT or FLOATYes

The price in points.

$post_idINTNo

The post object ID.

$point_typeSTRINGNo

The point type that the price is requested for.

$user_idINTNo

The numeric ID of the user who needs to pay for this content.

Used By

PackagePrio.Description
mycred/content10Used by the Sell Content add-on.

Example

Example 1: Set a custom price for post authors as they view other authors content, with an override option using custom post meta.

 
				
					/**
 * Customize Sell Content Prices
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_get_content_price', 'mycred_pro_custom_content_price', 10, 4 );
function mycred_pro_custom_content_price( $price, $post_id, $point_type, $user_id ) {

	// If the user is an author
	if ( user_can( $user_id, 'edit_published_posts' ) ) {

		// Get our custom price that we stored as a custom post meta
		$custom_price = get_post_meta( $post_id, 'custom_price', true );
		if ( $custom_price != '' )
			$price = $custom_price;

	}

	return $price;

}
				
			

Example 2: Example of how the filter can be used to set custom prices based on post type or taxonomy relationships.

				
					/**
 * Customize Sell Content Price
 * Set a custom price for post content based on post type or
 * taxonomy relationships.
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_get_content_price', 'mycred_pro_content_price_by_type', 10, 4 );
function mycred_pro_content_price_by_type( $price, $post_id, $point_type, $user_id ) {

	$post_type = get_post_type( $post_id );

	// Pages always cost 5 points
	if ( $post_type == 'page' )
		return 5;

	// Posts in the category "premium plus" costs 10 while all other posts cost 15
	if ( $post_type == 'post' ) {

		$terms = wp_get_object_terms( $post_id, 'category', array( 'fields' => 'slugs' ) );
		if ( ! empty( $terms ) && in_array( 'premium-plus', $terms ) )
			return 10;

		return 15;

	}

	// Returns default
	return $price;

}
				
			

 

mycred_get_users_cred

Package: mycred/balance Category: Filters
 

Description

Each time a users balance is requested by a feature, the balance is passed through this filter. This could for example be used as a mean to retrieve balances from a different source then the user meta table.

 

Parameters

ParamTypeRequiredDescription
$balanceINT or FLOATYes

The balance value.

$mycredOBJNo

The myCRED_Settings class object.

$user_idINTNo

The requested users ID.

$typeSTRINGNo

The point type being requested.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Load balances that exist in a separate database table and not in the user meta table.

 
				
					/**
 * Load Balance
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_get_users_cred', 'mycredpro_load_balance', 10, 3 );
function mycredpro_load_balance( $balance, $mycred, $user_id ) {

	global $wpdb;

	$table   = $wpdb->prefix . 'customtable';
	$balance = $wpdb->get_var( $wpdb->prepare( "SELECT balance FROM {$table} WHERE user_id = %d;", $user_id ) );

	if ( $balance === NULL )
		$balance = $mycred->zero();

	return $balance;

}
				
			

 

mycred_give_run

Package: mycred/core Category: Filters
 

Description

This filter controls if the mycred_give shortcode should run or not. It can be used to either disable this shortcode or to limit when or by whom it can be used.

 

Parameters

ParamTypeRequiredDescription
$runBOOLYes

If the shortcode is set to run (TRUE) or not (FALSE).

$attsARRAYNo

The shortcode attributes that are being used.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Disable usage of this shortcode.

 
				
					add_filter( 'mycred_give_run', '__return_false' );
				
			

 

mycred_has_entry

Package: mycred/log Category: Filters
 

Description

Used by the has_entry() class method when checking if a particular log entry exists for a given user. Mainly used to make sure log entries are unique.

 

Parameters

ParamTypeRequiredDescription
$resultBOOLYes

Returns TRUE if the log entry exists or FALSE.

$referenceSTRINGNo

The reference being checked. Is NULL if not used.

$ref_idINTNo

The reference ID being checked. Is NULL if not used.

$user_idINTNo

The user ID being checked. Is NULL if not used.

$dataSTRINGNo

The log data being checked. If used, this can be a string or a serialized array. Is NULL if not used.

$typeSTRINGNo

The point type being checked.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_have_ranks

Package: mycred/rank Category: Filters
 

Description

Used by the mycred_have_ranks function when checking if any ranks exists for a given point type.

 

Parameters

ParamTypeRequiredDescription
$resultsBOOLYes

Returns TRUE if ranks exists or FALSE.

$point_typeSTRINGNo

The point type being checked. Is NULL if checking no matter which point type is installed.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_label

Package: mycred/core Category: Filters
 

Description

This filter allows you to change the value of the MYCRED_DEFAULT_LABEL constant, re-naming  the myCRED plugin. While it is recommended to use the constant to change the label, this filter is a better solution when the constant can not be used, e.g. when re-naming the plugin via another plugin.

 

Parameters

ParamTypeRequiredDescription
$labelSTRINGYes

The MYCRED_DEFAULT_LABEL value.

Example

Example 1: Change the myCRED plugin name to SuperPoints.

 
				
					/**
 * Re-name myCRED
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_label', 'mycredpro_relabel_mycred' );
function mycredpro_relabel_mycred( $label ) {

	return 'SuperPoints';

}
				
			

 

mycred_label_my_balance

Package: mycred/balance Category: Filters
 

Description

This filter allows you to change how a users balance is displayed in the toolbar (if used). The default layout used is: %plural%: %cred_f%. You can use any general template tags or amount related template tags.

 

Parameters

ParamTypeRequiredDescription
$templateSTRINGYes

The template string.

$user_idINTNo

The ID of the users balance we are showing.

$point_typeSTRINGNo

The point type used.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Change the template to show the word “Your Balance“ followed by the users balance.

				
					/**
 * Change Toolbar Template
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_label_my_balance', 'mycredpro_change_toolbar_template' );
function mycredpro_change_toolbar_template( $template ) {

	return 'Your Balance: %cred_f%';

}
				
			

 

mycred_link

Package: mycred/core Category: Filters
 

Description

This filter allows you to adjust the anchor element the mycred_link shortcode renders.

 

Parameters

ParamTypeRequiredDescription
$htmlSTRINGYes

The HTML anchor element.

$attsARRAYNo

The shortcode attributes being used.

$link_titleSTRINGNo

The link title set for the shortcode.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_log_{column}

Package: mycred/log Category: Filters
 

Description

This filter allows you to return the content of a custom column that you have added using the mycred_log_column_headers filter. This filter is used by both the myCRED_Query_Log class when showing log entries and the myCRED_Export class when exporting. The filter name consists of mycred_log_ followed by the column ID you set.

 

Parameters

ParamTypeRequiredDescription
$contentSTRINGYes

The default column content. If the filter is used by the myCRED_Query_Log class, this will be FALSE while if it is used myCRED_Export class it will be an empty string.

$entryOBJNo

The database row object for the entry in question.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Render the content of a custom column with the id “row-id“.

 
				
					/**
 * Add Log Column Content
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_log_row-id', 'mycredpro_add_log_column_content', 10, 2 );
function mycredpro_add_log_column_content( $content, $entry ) {

	return '#' . $entry->id;

}
				
			

 

mycred_log_bulk_actions

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust the bulk actions that are available on the log page in the admin area.

 

Parameters

ParamTypeRequiredDescription
$actionsARRAYYes

An array of bulk actions ids and action labels.

$moduleOBJNo

The myCRED_Log_Module class object.

Default Bulk Actions

Action IDLabel
-1Bulk Actions
export-rawExport Raw
export-formatExport Formatted
deleteDelete

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Remove bulk actions in the logs.

 
				
					/**
 * Remove Bulk Actions
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_log_bulk_actions', '__return_empty_array' );
				
			

 

mycred_log_column_{type}_headers

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust or add columns that are shown when viewing the log in the admin area for a specific point type.

 

Parameters

ParamTypeRequiredDescription
$columnsARRAYYes

An array of column IDs and column labels.

$classOBJNo

Either the log module class object if in the admin area or the myCRED_Query_Log class object if used in the front end.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Remove the date column from the default point type only.

 
				
					/**
 * Remove Time Column
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_log_column_mycred_default_headers', 'mycredpro_remove_default_time_column' );
function mycredpro_remove_default_time_column( $columns ) {

	// Remove Date Column
	if ( array_key_exists( 'time', $columns ) )
		unset( $columns['time'] );

	return $columns;

}
				
			

 

mycred_log_column_headers

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust or add columns that are shown when viewing the log history table. This filter is used both in the front end when viewing your history or on the log pages in the admin area.

If you want to change / add columns only when viewing a specific point type in the admin area, use the mycred_log_column_{type}_headers filter instead.

 

Parameters

ParamTypeRequiredDescription
$columnsARRAYYes

An array of column IDs and column labels.

$classOBJNo

Either the log module class object if in the admin area or the myCRED_Query_Log class object if used in the front end.

$is_adminBOOLNo

Returns TRUE if the filter is used in the front end when for example using the mycred_history shortcode or FALSE if used in the admin area.

Used By

PackagePrio.Description
mycred/buddypress10The BuddyPress module uses this filter to remove the User column when showing the log entry in a users profile.

Examples

Example 1: Add a custom column called “Entry ID“ that are shown both in the front end and in the admin area.

 
				
					/**
 * Add Log Column
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_log_column_headers', 'mycredpro_add_log_column' );
function mycredpro_add_log_column( $columns ) {

	// Add our own column
	$columns['row-id'] = 'Entry ID';

	return $columns;

}
				
			

Example 2: Remove the date column when viewing the log in the front end

 
				
					/**
 * Remove Time Column
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_log_column_headers', 'mycredpro_remove_time_column', 10, 3 );
function mycredpro_remove_time_column( $columns, $class, $is_admin ) {

	// Only applicable on the front end
	if ( $is_admin === true ) return $columns;

	// Remove Date Column
	if ( array_key_exists( 'time', $columns ) )
		unset( $columns['time'] );

	return $columns;

}
				
			

 

mycred_log_date

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust how dates in the log or in exports are presented.

 

Parameters

ParamTypeRequiredDescription
$dateSTRINGYes

The formatted date to show.

$timeINTNo

The original unix timestamp being formatted.

$entryOBJNo

The log entry object.

Used By

PackagePrio.Description
mycred/log10Used by the log query class.
mycred/log20Used by the export module.

Example

Example 1: Instead of showing a date for each log entry, we show time ago.

 
				
					/**
 * Log Date Time Ago
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_log_date', 'mycred_log_date_time_ago', 10, 3 );
function mycred_log_date_time_ago( $date, $time, $entry ) {

	return human_time_diff( $time ) . ' ago';

}
				
			

 

mycred_log_row_classes

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust, add or remove CSS classes for each table row when viewing the log.

 

Parameters

ParamTypeRequiredDescription
$classesARRAYYes

Array of CSS classes.

$entryOBJNo

The log entry object.

Used By

PackagePrio.Description
mycred/log10Used by the log query class.

Example

Example 1: Add custom CSS classes indicating if the entry value is positive or negative.

 
				
					/**
 * Add Class Indicating Value
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_log_row_classes', 'mycred_pro_add_custom_log_entry_class', 10, 2 );
function mycred_pro_add_custom_log_entry_class( $classes, $entry ) {

	if ( $entry->creds < 0 )
		$classes[] = 'negative';
	else
		$classes[] = 'positive';

	return $classes;

}
				
			

 

mycred_lotto_payout_type

Package: mycred/game Category: Filters
 

Filter Description

This filter allows you to change what point type you want users to be paid out in when playing a lottery. Requires you to have more then one point type setup.

Available since

myCRED Lottery add-on 1.2.2.

Navigation

Used by

  • Function: mycred_lottery_do_draw

Parameters

  • ctype (string)
    The point type metakey to use.
  • lottery (object)
    The lottery object.

Examples

Example 1: Basic usage example where we set users to be paid in the custom point type “mytype”.

				
					add_filter( 'mycred_lotto_payout_type', 'adjust_mycred_lottery_payouttype' );
function adjust_mycred_lottery_payouttype( $type ) {
	return 'mytype';
}
				
			

 

mycred_lotto_times12

Package: mycred/game Category: Filters
 

Navigation:

  1. Description
  2. Used By
  3. Parameters

Description

This filter allows you to adjust the available times a lottery can be scheduled using the 12 hour system. This filter is used by the drop-down menus for the lottery schedules.

See the mycred_lotto_times24 filter for 24 hour systems.

 

Used By

  • Function: mycred_lotto_time_dropdown

 

Parameters

  • times (array)
    An assosiative array of times and textual labels to show in the dropdown menu.
 

mycred_lotto_times24

Package: mycred/game Category: Filters
 

Navigation:

  1. Description
  2. Used By
  3. Parameters

Description

This filter allows you to adjust the available times a lottery can be scheduled using the 24 hour system. This filter is used by the drop-down menus for the lottery schedules.

See the mycred_lotto_times12 filter for 12 hour systems.

 

Used By

  • Function: mycred_lotto_time_dropdown

 

Parameters

  • times (array)
    An assosiative array of times and textual labels to show in the dropdown menu.
 

mycred_notice_js

Package: mycred/notice Category: Filters
 

Description

This filter allows you to adjust the JavaScript variables for the Notifications Plus script. You can use this to make adjustments to the notifications before they are rendered or adjust the add-on settings.

 

 

Parameters

ParamTypeRequiredDescription
$argsARRAYYes

Associative array of arguments.

$moduleOBJNo

The myCRED Notifications Plus module object.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Disable front end debugging for administrators.

mycred_notifications

Package: mycred/notice Category: Filters
 

Description

This filter is used to pass on notifications from the saved transient to the jQuery script. It can be used to filter existing notifications or adding / removing a particular notice.

 

Parameters

ParamTypeRequiredDescription
$notificationsARRAYNo

Array of notifications.

Used By

PackagePrio.Description
mycred/notice10Used by the notification add-on to get notifications.

mycred_notifications_note

Package: mycred/notice Category: Filters
 

Description

This filter allows you to adjust the popup notification template before it is saved. This is then rendered and shown to the user on the next page load.

 

Parameters

ParamTypeRequiredDescription
$templateSTRINGYes

The notification template.

$requestARRAYNo

The point request array that triggered this notification.

$mycredOBJNo

The myCRED point type object.

Used By

PackagePrio.Description
mycred/notice10Used by the notification add-on.

mycred_parse_tags_amount

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust or add your own custom amount related template tag, to use in log entries. Should be used in combination with the mycred_has_tags filter in order to work.

 

Parameters

ParamTypeRequiredDescription
$contentSTRINGYes

The rendered log entry string.

$amountINT or FLOATNo

The original point amount.

$mycredOBJNo

The myCRED point type object.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Settings class.

Example

Example 1: Add a custom template tag that renders the points amount with a dollar sign.

 
				
					/**
 * Add Custom Amount Related Template Tag
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_parse_tags_amount', 'mycred_pro_custom_amount_template_tags', 10, 3 );
function mycred_pro_custom_amount_template_tags( $content, $amount, $mycred ) {

	return str_replace( '%dollars%', '$ ' . $amount, $content );

}
				
			

 

mycred_parse_tags_comment

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust or add your own custom comment related template tag to use in log entries. Should be used in combination with the mycred_has_tags filter in order to work.

 

Parameters

ParamTypeRequiredDescription
$contentSTRINGYes

The rendered log entry string.

$commentOBJNo

The WordPress comment object.

$dataARRAYNo

The value stored in the data column of the log entry.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Settings class.

Example

Example 1: Add a custom comment related template tag that shows the comment authors IP when the comment was posted.

 
				
					/**
 * Add Custom Comment Related Template Tag
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_parse_tags_comment', 'mycredpro_custom_comment_template_tag', 10, 3 );
function mycredpro_custom_comment_template_tag( $content, $comment, $data ) {

	$content = str_replace( '%IP%', $comment->comment_author_IP, $content );

	return $content;

}
				
			

 

mycred_parse_tags_general

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust or add your own custom generic template tag to use in log entries. It is important to remember that generic template tags are parsed on every single log entry! This means that you should only use this if you need to adjust every single log entry in your database! Furthermore, this filter is a very generic and no log entry detail besides the visible entry string is available.

 

Parameters

ParamTypeRequiredDescription
$contentSTRINGYes

The log entry string.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Settings class.

mycred_parse_tags_post

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust or add your own custom post related template tag to use in log entries. Should be used in combination with the mycred_has_tags filter in order to work.

 

Parameters

ParamTypeRequiredDescription
$contentSTRINGYes

The rendered log entry string.

$postOBJNo

The WordPress post object.

$dataARRAYNo

The value stored in the data column of the log entry.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Settings class.

Example

Example 1: Add a custom post related template tag showing a posts status in the log entries.

				
					/**
 * Add Custom Post Related Template Tag
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_parse_tags_post', 'mycredpro_custom_post_template_tag', 10, 3 );
function mycredpro_custom_post_template_tag( $content, $post, $data ) {

	$content = str_replace( '%post_status%', $post->post_status, $content );

	return $content;

}
				
			

 

mycred_parse_tags_user

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust or add your own custom user related template tag to use in log entries. Should be used in combination with the mycred_has_tags filter in order to work.

 

Parameters

ParamTypeRequiredDescription
$contentSTRINGYes

The rendered log entry string.

$userARRAY or OBJNo

The WordPress user object or the object in array form. When a user is deleted from the database, and you have selected not to remove their log entries, myCRED will save their user object in an array form in the data column. So when rendering log entries, you need to keep this in mind accessing data.

$dataARRAYNo

The value stored in the data column of the log entry.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Settings class.

Example

Example 1: Add a custom user related template tag showing the users avatar.

 
				
					/**
 * Add User Avatar Template Tag
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_parse_tags_user', 'mycredpro_add_user_avatar_template_tag', 10, 3 );
function mycredpro_add_user_avatar_template_tag( $content, $user, $data ) {

	if ( ! is_object( $user ) && is_array( $user ) )
		$user = (object) $user;

	if ( ! isset( $user->ID ) ) return $content;

	$content = str_replace( '%avatar_small%', get_avatar( $user->ID, 32 ), $content );
	$content = str_replace( '%avatar_large%', get_avatar( $user->ID, 64 ), $content );

	return $content;

}
				
			

 

mycred_post_is_for_sale

Package: mycred/content Category: Filters
 

Description

This filter allows you to adjust the results of checking if a given post is set for sale using the Sell Content add-on. This only checks if the post is set for sale based on your settings. It does not check if a user has paid for the content!

 

Parameters

ParamTypeRequiredDescription
$resultsBOOLYesReturns TRUE if the post is for sale or FALSE.
$postOBJNoThe post object being checked.
$settingsARRAYNoThe Sell Content add-on settings array.

Example

Example 1: Set all content for sale that are authored by the user with the ID 123.

 
				
					/**
 * Set Content for Sale by Author
 * @mycred
 * @version 1.0
 */
add_filter( 'mycred_post_is_for_sale', 'mycredpro_set_for_sale_by_author', 10, 2 );
function mycredpro_set_for_sale_by_author( $result, $post ) {

	if ( $post->post_author == 123 )
		return true;

	return $result;

}
				
			

 

mycred_pt_get_fee

Package: mycred/transfer Category: Filters
 

Description

When using the Transfer Plus add-on in myCRED, you can select to charge a fee for each transfer a user makes on your website. This filter allows you to adjust the fee amount for each transfer based on your preference.


Parameters

Param Type Required Description
$fee INT or FLOAT Yes

The fee amount in points. Use zero for no fee.

$amount INT or FLOAT No

The amount of points a user is transferring.

$user_id INT No

The numeric ID of the user that is making the transfer.

$point_type STRING No

The point type key of the point type we are transferring.

$prefs ARRAY No

The fee feature settings.

Used By

Package Prio. Description
Not used by any built-in package.

Example

Example 1: Charge a custom fee based on a users WordPress role when making a transfer in myCRED.

				
					/**
 * Custom transfer Fees
 * Charge a custom fee based on a users WordPress role when making
 * a transfer in myCRED.
 * @version 1.0
 */
function mycred_pro_transfer_fee_by_role( $fee, $amount, $user_id, $point_type, $prefs ) {

	// if we are just a subscriber, impose 10% fee
	if ( ! user_can( $user_id, 'publish_posts' ) )
		$fee = $amount * 0.1;

	// else if we are an "contributor", impose 5% fee
	elseif ( ! user_can( $user_id, 'delete_published_posts' ) )
		$fee = $amount * 0.05;

	// everyone else pays no fee
	else $fee = 0;

	return $fee;

}
add_filter( 'mycred_pt_get_fee', 'mycred_pro_transfer_fee_by_role', 10, 5 );
				
			

Example 2: Charge a custom fee based on a users myCRED rank when making a transfer in myCRED.

				
					/**
 * Custom transfer Fees
 * Charge a custom fee based on a users myCRED rank when making
 * a transfer in myCRED.
 * @version 1.0
 */
function mycred_pro_transfer_fee_by_rank( $fee, $amount, $user_id, $point_type, $prefs ) {

	// Make sure the rank add-on is enabled to prevent crashes
	if ( ! function_exists( 'mycred_get_rank_object_id' ) ) return $fee;

	$users_rank_id = mycred_get_rank_object_id( $user_id );

	// Make sure the user has a rank
	if ( $users_rank_id !== false ) {

		// If users has the rank with the ID of 12, impose 10% fee
		if ( $users_rank_id == 12 )
			$fee = $amount * 0.1;

		// Else if user has the rank with the ID of 13, impose 25% fee
		elseif ( $users_rank_id == 13 )
			$fee = $amount * 0.25;

	}

	return $fee;

}
add_filter( 'mycred_pt_get_fee', 'mycred_pro_transfer_fee_by_rank', 10, 5 );
				
			

 

mycred_publish_hook_new

Package: mycred/hook Category: Filters
 

Description

The “Points for Publishing Content” hook reward users with points for publishing content. This act is rewarded when a posts status transitions from an “old status” to a “new status”.

The old status would include: drafts, pending for approval and scheduled post statuses. The new statuses include: published and privately published post statuses.

Any custom post statuses needs to be added in here if the status indicates content that is “published”. If your custom post status is a different type of “not published content” indicator, e.g. “Pending Approval”, the status need to be added using the mycred_publish_hook_old filter instead!

 

Parameters

ParamTypeRequiredDescription
$new_statusesARRAYYes

An array of statuses a post needs to transition to. By default these are: publish and private.

$post_idINTNo

The post objects ID.

$point_typeSTRINGNo

The point type key currently being processed.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Add a custom “Archived“ post status to the “Points for publishing content“ hook in myCRED.

 
				
					/**
 * Add Custom Post Status
 * @version 1.0
 */
function mycred_pro_add_custom_post_status( $new_statuses ) {

	$new_statuses[] = 'archived';

	return $new_statuses;

}
add_filter( 'mycred_publish_hook_new', 'mycred_pro_add_custom_post_status' );
				
			

 

mycred_publish_hook_old

Package: mycred/hook Category: Filters
 

Description

The “Points for Publishing Content” hook reward users with points for publishing content. This act is rewarded when a posts status transitions from an “old status” to a “new status”.

The old status would include: drafts, pending for approval and scheduled post statuses. The new statuses include: published and privately published post statuses.

Any custom post statuses needs to be added in here if the status is used BEFORE the content is published. If your custom post status is a different type of “published content” indicator, e.g. “Archived”, the status need to be added using the mycred_publish_hook_new filter instead!

 

Parameters

ParamTypeRequiredDescription
$old_statusesARRAYYes

An array of statuses a post needs to transition from. By default these are: newauto-draftdraftprivatepending and future.

$post_idINTNo

The post objects ID.

$point_typeSTRINGNo

The point type key currently being processed.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Add a custom “Pre Approved“ post status to the “Points for publishing content“ hook in myCRED.

 
				
					/**
 * Add Custom Post Status
 * @version 1.0
 */
function mycred_pro_add_custom_post_status( $old_statuses ) {

	$old_statuses[] = 'pre-approved';

	return $old_statuses;

}
add_filter( 'mycred_publish_hook_old', 'mycred_pro_add_custom_post_status' );
				
			

 

mycred_publish_hook_ref

Package: mycred/hook Category: Filters
 

Description

This filter allows you to adjust the reference that the Points for Publishing Content hook uses when awarding / deducting points. Defaults to publishing_content.

Parameters

ParamTypeRequiredDescription
$referenceSTRINGYes

The reference to use. Can not be empty or no points will be awarded!

$postOBJNo

The WordPress post object that is getting published.

$new_statusSTRINGNo

The new status the post is receiving by WordPress.

$old_statusSTRINGNo

The posts old status.

$hookOBJNo

The hook object.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Log the event under a unique reference based on the post type being publish

				
					/**
 * Adjust Publish Reference
 * Log the event under a unique reference based on the post type being published.
 * @version 1.0
 */
function mycred_pro_publish_ref_by_type( $reference, $post ) {

	return 'publish_' . $post->post_type;

}
add_filter( 'mycred_publish_hook_ref', 'mycred_pro_publish_ref_by_type', 10, 2 );
				
			

 

mycred_query_log_args

Package: mycred/log Category: Filters
 

Description

Used by the myCRED_Query_Log class, this filter allows you to make adjustments to the query arguments before it is run by class.

 

Parameters

ParamTypeRequiredDescription
$argsARRAYYes

An associative array of arguments.

$defaultsARRAYNo

An array of the default set of arguments the query supports.

Default Query Arguments

				
					array
(
	'entry_id' => NULL,
	'user_id'  => NULL,
	'ctype'    => MYCRED_DEFAULT_TYPE_KEY,
	'time'     => NULL,
	'ref'      => NULL,
	'ref_id'   => NULL,
	'amount'   => NULL,
	's'        => NULL,
	'data'     => NULL,
	'number'   => 25,
	'offset'   => '',
	'orderby'  => 'time',
	'order'    => 'DESC',
	'ids'      => false,  // depreciated as of 1.7.5
	'fields'   => 'all',  // in favor for fields
	'paged'    => 1
)
				
			

 

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Make sure that admins and editors can only view their own manual adjustments when viewing the log.

				
					/**
 * Adjust myCRED Query Args
 * @version 1.0
 */
function mycred_pro_my_adjustments( $args ) {

	if ( $args['ref'] == 'manual' && current_user_can( 'moderate_comments' ) )
		$args['ref_id'] = get_current_user_id();

	return $args;

}
add_filter( 'mycred_query_log_args', 'mycred_pro_my_adjustments' );
				
			

 

mycred_rank_list

Package: mycred/rank Category: Filters
 

Description

This filter allows you to adjust the template used by the mycred_list_ranks shortcode when rendering each rank you have setup for a particular point type. While you can set the template when using the shortcode, this filter accomplishes the exact same task.

 

Parameters

ParamTypeRequiredDescription
$row_templateSTRINGYes

The row template.

$attsARRAYNo

The attributes passed to the shortcode.

$mycredOBJNo

The myCRED object.

Used By

PackagePrio.Description
mycred/rank10Used by the mycred_list_ranks shortcode.

Example

Example 1: Change the template used when listing ranks via the mycred_list_ranks shortcode to render details with Bootstrap support.

				
					/**
 * Adjust Rank Listing Template
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_rank_list', 'mycredpro_adjust_rank_listing_template' );
function mycredpro_adjust_rank_listing_template( $row_template ) {

	return '<div class="row"><div class="col-xs-6">%rank%</div><div class="col-xs-3">%min%</div><div class="col-xs-3">%max%</div></div>';

}
				
			

 

mycred_ranking_row

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust how each row is rendered in the leaderboard. The word “ranking” refers to a users ranking in the leaderboard and has nothing to do with the users Rank.

 

Parameters

ParamTypeRequiredDescription
$layoutSTRINGYes

The row string.

$templateSTRINGNo

The original row template.

$userOBJNo

The WordPress user object.

$positionINTNo

The users position in the leaderboard.

Used By

PackagePrio.Description
mycred/log10Used by the mycred_leaderboard shortcode.

Example

Example 1: Add avatars to each user shown in your leaderboard.

 
				
					/**
 * Add Avatars To Leaderboard
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_ranking_row', 'mycredpro_add_avatars_to_leaderboard', 10, 4 );
function mycredpro_add_avatars_to_leaderboard( $layout, $template, $user, $position ) {

	if ( isset( $user->ID ) )
		$user_id = $user->ID;

	elseif ( isset( $user['ID'] ) )
		$user_id = $user['ID'];

	else return $layout;

	$avatar = get_avatar( $user_id, 32 );

	return str_replace( '%avatar%', $avatar, $layout );

}
				
			

 

mycred_ranking_sql

Package: mycred/log Category: Filters
 

Description

This filter allows you to adjust the MySQL query string used for generating a leaderboard through the mycred_leaderboard shortcode.

 

Parameters

ParamTypeRequiredDescription
$querySTRINGYes

The SQL query string.

$attsARRAYNo

Associative array of the shortcode attributes currently being used. Will include custom shortcode attributes that might be used.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_recurring_max_limit

Package: mycred/banking Category: Filters
 

Description

This filter allows you to adjust the number of users the recurring payout banking service will process per instance. By default this is 1500. If more then 1500 users needs to be paid out, the recurring payout schedule will re-schedule itself and run another 1500 users 2 min later until all users are processed.

 

Parameters

ParamTypeRequiredDescription
$limitINTYes

The number of users to execute per instance.

$serviceOBJNo

The recurring payout banking service object.

Used By

PackagePrio.Description
mycred/banking10Default usage

mycred_register_ranks

Package: mycred/rank Category: Filters
 

Description

This filter lets you make adjustments to the Ranks post type settings before it is handed over to the register_post_type function.

 

Parameters

ParamTypeRequiredDescription
$argsARRAYYes

The post type settings array.

$moduleOBJNo

The myCRED_Ranks_Module class.

Used By

PackagePrio.Description
mycred/rank10Used by the myCRED_Ranks_Module class.

Example

Example 1: Change the rank post type capability.

 
				
					/**
 * Adjust Rank Post Type
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_register_ranks', 'mycredpro_adjust_rank_post_type' );
function mycredpro_adjust_rank_post_type( $args ) {

	$args['capability_type'] = 'post';

	return $args;

}
				
			

 

mycred_run_this

Package: mycred/balance Category: Filters
 

Description

This filter allows you to make adjustments to a transaction request before it is executed. If you need to stop a transaction you can set the amount to zero, however you should use the mycred_add filter to determine if a transaction should be stopped.

 

Parameters

ParamTypeRequiredDescription
$requestARRAYYes

An associative array representing the transaction that is to be processed.

$mycredOBJNo

The myCRED_Settings class object processing the transaction request.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Settings class.

Example

Example 1: Multiply the amount of points users gets based on their WordPress role. Administrators are excluded.

 
				
					/**
 * 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 );
				
			

Example 2: Whenever a user on our website is to gain points, we double the value.

				
					/**
 * Duplicate Points
 * @since 1.0
 * @version 1.0
 */
function mycred_pro_duplicate_points( $request ) {

	// If a user is to gain points, double the value
	if ( $request['amount'] > 0 ) {
		$request['amount'] = $request['amount'] * 2;
	}

	return $request;

}
add_filter( 'mycred_run_this', 'mycred_pro_duplicate_points' );
				
			

Example 3: Give users bonus points when they buy points using buyCRED. The amount depends on their current rank.

				
					/**
 * Bonus Points
 * Give users bonus points when they buy points using buyCRED
 * based on their rank. Required us to know the Rank post ID for comparisons.
 * @version 1.0
 */
function mycred_pro_buycred_bonus( $run_this, $mycred ) {

	// Only applicable for point purchases via buyCRED and if the Ranks add-on is enabled
	if ( substr( $run_this['ref'], 0, 15 ) != 'buy_creds_with_' || ! function_exists( 'mycred_get_users_rank_id' ) ) return $run_this;

	extract( $run_this );

	// Get the users current rank post ID
	$users_rank_id = mycred_get_users_rank_id( $user_id, $type );

	// Example: Newbee rank post ID 10
	// If user has this rank, give the user 10 points more
	if ( $users_rank_id == 10 )
		$run_this['amount'] = $amount + 10;

	// Example: Master rank post ID 12
	// If user has this rank, give the user 100 points more
	elseif ( $users_rank_id == 12 )
		$run_this['amount'] = $amount + 100;

	return $run_this;

}
add_filter( 'mycred_run_this', 'mycred_pro_buycred_bonus', 10, 2 );
				
			

 

mycred_scratch_card_templates

Package: mycred/game Category: Filters
 

Description

This filter allows you to add, replace or remove templates for the Scratch Card add-on.

 

Parameters

ParamTypeRequiredDescription
$templatesARRAYYes

An associative array of available templates. You can read more about this in the Scratch Card documentation.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Add a custom template from a theme.

 
				
					/**
 * Add Custom Scratch Card Template
 * @since 1.0
 * @version 1.0
 */
function mycred_add_custom_scratch_card_template( $templates ) {

	$templates['mytemplate'] = array(
		'label'               => 'My Custom Template',
		'minimum_scratch'     => 75,
		'brush_diameter'      => 15,
		'card_width'          => 300,
		'card_height'         => 400,
		'coin_image'          => get_template_directory_uri() . '/images/card/coin.png',
		'cover_image'         => get_template_directory_uri() . '/images/card/cover-image.png',
		'buy_log'             => '', // optional
		'win_log'             => '', // optional
		'win_message'         => '', // optional
		'setup'               => array(
			array(
				'number'         => 100,
				'value'          => 0,
				'attachment_ids' => array(
					get_template_directory_uri() . '/images/card/nowin.png'
				)
			),
			array(
				'number'         => 10,
				'value'          => 10,
				'attachment_ids' => array(
					get_template_directory_uri() . '/images/card/10points.png'
				)
			)
		)
	);

	return $templates;

}
add_filter( 'mycred_scratch_card_templates', 'mycred_add_custom_scratch_card_template' );
				
			

Example 2: Add a custom template from a plugin.

				
					/**
 * Add Custom Scratch Card Template
 * @since 1.0
 * @version 1.0
 */
function mycred_add_custom_scratch_card_template( $templates ) {

	$templates['mytemplate'] = array(
		'label'               => 'My Custom Template',
		'minimum_scratch'     => 75,
		'brush_diameter'      => 15,
		'card_width'          => 300,
		'card_height'         => 400,
		'coin_image'          => plugins_url( 'images/card/coin.png', __FILE__ ),
		'cover_image'         => plugins_url( 'images/card/cover-image.png', __FILE__ ),
		'buy_log'             => '', // optional
		'win_log'             => '', // optional
		'win_message'         => '', // optional
		'setup'               => array(
			array(
				'number'         => 100,
				'value'          => 0,
				'attachment_ids' => array(
					plugins_url( '/images/card/nowin.png', __FILE__ )
				)
			),
			array(
				'number'         => 10,
				'value'          => 10,
				'attachment_ids' => array(
					plugins_url( '/images/card/10points.png', __FILE__ )
				)
			)
		)
	);

	return $templates;

}
add_filter( 'mycred_scratch_card_templates', 'mycred_add_custom_scratch_card_template' );
				
			

 

mycred_scratch_everyonewins

Package: mycred/game Category: Filters
 

Description

By default, a scratch card set must consist of cards that represents a “win” and cards that represents “no wins”. This filter can be used to change this and create sets where all cards are winners. Without this filter, if you attempt to create zero “No Win” cards, the set will decline your request when you save.

 

Parameters

ParamTypeRequiredDescription
$allowBOOLYes

TRUE to allow or FALSE. Defaults to FALSE.

$set_idINTNo

The card sets WordPress post ID.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Enable all cards to be winning cards.

add_filter( 'mycred_scratch_everyonewins', '__return_true' );

mycred_sell_content_priority

Package: mycred/content Category: Filters
 

Description

This filter allows you to change the priority of the Sell Content add-ons content filtering.

 

Parameters

ParamTypeRequiredDescription
$priorityINTYes

The priority number. Defaults to 25.

$sell_content_moduleOBJNo

The Sell Content module.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Lower the priority of the content filter.

 
				
					/**
 * Movie Sell Content Filter
 * @version 1.0
 */
function mycred_pro_run_sale_filter_later( $priority ) {

	return 50;

}
add_filter( 'mycred_sell_content_priority', 'mycred_pro_run_sale_filter_later' );
				
			

 

mycred_sell_exp_title

Package: mycred/content Category: Filters
 

Description

This filter lets you change the title used to mark the expiration length measurement. Defaults to “Hours”. If you are looking to change hours to any other time measurement, consult the mycred_sell_expire_calc filter.

 

Parameters

ParamTypeRequiredDescription
$labelSTRINGNo

The title to show.

Used By

PackagePrio.Description
mycred/content10Used by the Sell Content add-on.

Example

Example 1: Change the Expiration Label.

 
				
					/**
 * Change the Expiration Label to "Days"
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_sell_exp_title', 'mycredpro_adjust_expiration_length_title' );
function mycredpro_adjust_expiration_length_title() { return 'Days'; }
				
			

 

mycred_sell_expire_calc

Package: mycred/content Category: Filters
 

Description

By default, myCRED allows you to let purchases expire after a certain number of hours. This filter lets you change this calculation from hours to any other time measurement. If you use this filter you should also consult the mycred_sell_exp_title filter.

 

Parameters

ParamTypeRequiredDescription
$expirationINTNo

The expiration length in seconds. This value is multiplied with the length you set e.g. 2 hours, and added to the time a user last paid.

$lengthINTNo

The length set for this particular post.

$user_idINTNo

The numeric ID of the user this calculation is related to.

$post_idINTNo

The post ID.

Used By

PackagePrio.Description
mycred/content10Used by the mycred_content_purchase_has_expired function.

Example

Example 1: Change the expiration length calculation from using hours to days.

 
				
					/**
 * Change the Expiration Calculation to use Days
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_sell_expire_calc', 'mycredpro_adjust_expiration_length', 10, 4 );
function mycredpro_adjust_expiration_length( $expire, $length, $user_id, $post_id ) {

	return DAY_IN_SECONDS;

}
				
			

 

mycred_sell_this_button

Package: mycred/content Category: Filters
 

Description

This filter allows you to make adjustments to the button the Sell Content add-on renders for users who have not purchased access to content set for sale. You can for example use this filter to adjust the button elements attributes or customize the button label.

 

Parameters

ParamTypeRequiredDescription
$buttonSTRINGYes

The HTML button element.

$postOBJNo

The WordPress post object that this button is being rendered for.

$setupARRAYNo

An associated array of the point type setup. This is the values set in the Sell Content add-ons settings for a particular point type. Note that if multiple point types are allowed to be used as payment, this settings might differ.

$mycredOBJNo

The myCRED_Settings object currently being used.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Insert an icon into the buttons label.

 
				
					/**
 * Insert Icon
 * Insert an icon for all buy buttons.
 * @version 1.0
 */
function mycred_pro_insert_buy_button_icon( $button ) {

	return str_replace( '">', '"><i class="fa fa-bolt" aria-hidden="true"></i> ', $button );

}
add_filter( 'mycred_sell_this_button', 'mycred_pro_insert_buy_button_icon' );

				
			

 

mycred_sell_this_label

Package: mycred/content Category: Filters
 

Description

This filter allows you to rename the Sell Content metabox that is inserted into your post editor screen. As of version 1.7, this will only run if you have set to sell content using “Manual Mode”.

 

Parameters

ParamTypeRequiredDescription
$labelSTRINGYes

The metabox title string.

Used By

PackagePrio.Description
mycred/content10Used by the myCRED_Sell_Content_Module class.

mycred_send_language

Package: mycred/core Category: Filters
 

Description

This filter allows you to change the language used when using the mycred_send shortcode. There are by default three messages that can be translated / adjusted:

  • working – used when the button is clicked and we are waiting for the AJAX call to finish.
  • done – used on successfull transactions
  • error – used on transactions that failed.

 

Parameters

ParamTypeRequiredDescription
$instancesARRAYYes

An array of strings used by the mycred_send shortcode.

Used By

PackagePrio.Description
mycred/core10Used by the mycred_send shortcode.

mycred_setup_addons

Package: mycred/core Category: Filters
 

Description

This filter allows you to register a custom add-on or remove / rename a built-in one.

When creating a custom add-on, it is not required to use this filter unless you want users to select to enable the add-on on the myCRED > Add-ons page in the admin area. If you are adding a custom add-on via a plugin, you could however make the add-on auto enable when the plugin is enabled.

 

Parameters

ParamTypeRequiredDescription
$addonsARRAYYes

An associative array of add-ons installed.

Structure:

  • name – The name shown in the add-on list.
  • description – Optional description for the add-on.
  • addon_url – Optional information url.
  • version – The version of the add-on.
  • author – The add-on authors name.
  • author_url – The add-on authors url.
  • screenshot – The add-on image.
  • pro_url – Option to show a different version of the add-on via a url.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Addons_Module class.

mycred_setup_banking

Package: mycred/banking Category: Filters
 

Description

This filter allows you to add custom banking services or remove built-in ones. Banking services are loaded just like hooks, meaning that you will need to provide the class or function name that loads the service for the add-on to load the service once enabled by the user.

 

Parameters

ParamTypeRequiredDescription
$servicesARRAYYes

An associated array of installed services.

Used By

PackagePrio.Description
mycred/banking10Used by the myCRED_Banking_Module class.

Example

Example 1: Add a custom banking service.

 
 
				
					/**
 * Add Custom Banking Service
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_setup_banking', 'mycredpro_add_custom_bank_service' );
function mycredpro_add_custom_bank_service( $services ) {

	$services['my_custom_service'] = array(
		'title'       => __( 'My Custom Service' ), // Service title
		'description' => __( 'This is a custom service' ), // Description (optional)
		'callback'    => array( 'My_Custom_Service_Class' ) // Class name
	);

	return $services;

}
				
			

 

mycred_setup_hooks

Package: mycred/core Category: Filters
 

Description

This filter allows you to add custom hooks or remove built-in ones.

 

Parameters

ParamTypeRequiredDescription
$hooksARRAYYes

An associated array of installed hooks.

$point_typeSTRINGNo

The point type being rendered when the filter fires. This can be used which hooks are available for each point type you might have installed.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Hooks_Module class.

Examples

Example 1: Add a custom hook.

 
				
					/**
 * Add Custom Hook
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_setup_hooks', 'mycredpro_add_custom_hook' );
function mycredpro_add_custom_hook( $hooks ) {

	$hooks['my_custom_hook'] = array(
		'title'       => __( 'My Custom Hook' ), // Hook title
		'description' => __( 'This is a custom hook' ), // Description (optional)
		'callback'    => array( 'My_Custom_Hook_Class' ) // Class name
	);

	return $hooks;

}
				
			

Example 2: Remove certain hooks from being usable for custom point types.

				
					/**
 * Remove Hooks for Point Type
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_setup_hooks', 'mycredpro_remove_hooks_per_type', 10, 2 );
function mycredpro_remove_hooks_per_type( $hooks, $point_type ) {

	// Remove hooks for custom point types
	if ( $point_type != MYCRED_DEFAULT_TYPE_KEY ) {
		unset( $hooks['publishing_content'] );
		unset( $hooks['deleted_content'] );
	}

	return $hooks;

}
				
			

 

mycred_transfer_acc_limit

Package: mycred/transfer Category: Filters
 

Description

When a user transfers points to another user on your website, one of the checks myCRED makes it to ensure that he is solvent for the amount he wants to transfer. So by default, users can not send more points then they actually have. This filter allows you to override this and allow users to transfer more.

 

Parameters

ParamTypeRequiredDescription
$minimumINT or FLOATYes

The lowest amount a users balance can go when transferring. Defaults to zero.

$point_typeSTRINGNo

The point type being transferred.

$user_idINTNo

The numeric ID of the user making the transfer.

$referenceSTRINGNo

The reference under which the transfer is being made. Usable when you allow multiple types of transfers.

Used By

PackagePrio.Description
mycred/transfer10Used by the transfer add-on.
mycred/core20Used by the mycred_send shortcode processor.

Example

Example 1: Give contributors 100 points “credit“ when making a transfer.

 
				
					/**
 * Give Crontributors Transfer Credit
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_transfer_acc_limit', 'mycredpro_transfer_credit_for_contributors', 10, 3 );
function mycredpro_transfer_credit_for_contributors( $minimum, $point_type, $user_id ) {

	$user = get_userdata( $user_id );
	if ( in_array( 'contributor', $user->roles ) )
		return 0 - 100;

	return $minimum;

}
				
			

Example 2: Allow users to transfer up to 500 points more than they have on their account when making a “donation“.

				
					/**
 * Credit for Donations
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_transfer_acc_limit', 'mycredpro_transfer_credit_for_donations', 10, 4 );
function mycredpro_transfer_credit_for_donations( $minimum, $point_type, $user_id, $reference ) {

	if ( $reference == 'donation' )
		return 0 - 500;

	return $minimum;

}
				
			

 

mycred_transfer_autofill_by

Package: mycred/transfer Category: Filters
 

Description

This filter allows you to add / remove autocomplete options in the Transfer add-on.

 

Parameters

ParamTypeRequiredDescription
$optionsARRAYYes

An associative array of autocomplete value and label that is shown in the dropdown menu.

$settingsARRAYNo

The transfer add-on settings.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Add the option to disable Autocomplete in our transfer settings.

 
				
					function mycred_pro_disable_autocomplete_option( $options ) {

	$options['none'] = 'Disable Autocomplete';

	return $options;

}
add_filter( 'mycred_transfer_autofill_by', 'mycred_pro_disable_autocomplete_option' );
				
			

 

mycred_transfer_messages

Package: mycred/transfer Category: Filters
 

Description

This filter allows you to adjust the transfer messages that the javascript uses when processing transfer requests. You can use this to adjust existing language being used or add your own.

Default messages:

  • completed – Message to show when the transfer was successfully completed.
  • error_1 – WordPress nonce has expired (page has been opened too long without running the form).
  • error_2 – Communications error (bad form submission).
  • error_3 – Recipient not found.
  • error_4 – Transaction declined by recipient (recipient is excluded from points).
  • error_5 – Incorrect amount (usually zero points or empty).
  • error_6 – Transfer add-on has not been setup.
  • error_7 – Insufficient funds.
  • error_8 – Transfer limit exceeded.
  • error_9 – Processing error (transfer declined or duplicate transfer).
  • error_10 – Selected point type not set to be transferrable.

 

Parameters

ParamTypeRequiredDescription
$instancesARRAYYes

An array of strings used by the mycred_transfer shortcode.

Used By

PackagePrio.Description
mycred/transfer10Used by the myCRED_Transfer_Module class.

mycred_twilio_format_phone_number

Package: mycred/twilio Category: Filters
 

Description

This filter allows you to adjust a given phone numbers formating.

 

Parameters

ParamTypeRequiredDescription
$phone_numberSTRINGYes

The phone number formatted by appending the country code and removing non numeric characters.

$numberSTRINGNo

The original number before formating.

$country_codeSTRINGNo

The country code saved in the plugin settings.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_twilio_get_sender

Package: mycred/twilio Category: Filters
 

Description

This filter allows you to adjust the results when the Twilio Transfer plugin tries to tie a phone number to a user on your website.

 

Parameters

ParamTypeRequiredDescription
$senderBOOL or OBJYes

Either FALSE if the user could not be found or the WordPress user object on success.

$numberSTRINGNo

The phone number as sent from Twilio. Example for North American numbers: +11234567890

$meta_keySTRINGNo

Either the user meta key where the phone number is stored or the field name if BuddyPress is used.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_twilio_get_senders_id

Package: mycred/twilio Category: Filters
 

Description

This filter allows you to adjust the results when the Twilio Transfer plugin tries to tie a phone number to a user on your website.

 

Parameters

ParamTypeRequiredDescription
$user_idBOOL or INTYes

Either FALSE if the user could not be found or the numeric ID if a match is made.

$numberSTRINGNo

The phone number as sent from Twilio. Example for North American numbers: +11234567890

$meta_keySTRINGNo

Either the user meta key where the phone number is stored or the field name if BuddyPress is used.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_twilio_get_users_number

Package: mycred/twilio Category: Filters
 

Description

This filter allows you to adjust the results where the Twilio Transfers plugin tries to find the phone number of a given user.

 

Parameters

ParamTypeRequiredDescription
$numberBOOL or STRINGYes

Either FALSE if the phone number is not found or the number as it is stored in the database.

$user_idINTNo

The users numeric ID.

$meta_keySTRINGNo

Either the user meta key where the phone number is stored or the field name if BuddyPress is used.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_twilio_parse_sms

Package: mycred/twilio Category: Filters
 

Description

This filter allows you to adjust the SMS message body when received by the Twilio Transfers plugin.

 

Parameters

ParamTypeRequiredDescription
$smsARRAYYes

The message body converted into an array. By default, the body content is split into 4 pieces.

$bodySTRINGNo

The SMS message body in it’s raw form.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_twilio_phone_number

Package: mycred/transfer Category: Filters
 

Description

This filter allows you to format a Twilio phone number into the way you format phone numbers on your website.

 

Parameters

ParamTypeRequiredDescription
$numberSTRINGYes

The phone number Twilio sends. This is an unformatted phone number with the country code appended to the beginning.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Phone numbers are stored as (xxx) xxx-xxxx in our database so we convert the Twilio number to the same format

 
				
					/**
 * Adjust Phone Number Formatting
 * Convert Twilio number.
 * @version 1.0
 */
function mycred_pro_format_twilio_number( $number ) {

	// +1234567890 => (123) 456-7890
	return sprintf( "(%s) %s-%s", substr( $number, 2, 3 ), substr( $number, 5, 3 ), substr( $number, 8 ) );

}
add_filter( 'mycred_twilio_phone_number', 'mycred_pro_format_twilio_number' );
				
			

 

mycred_twilio_xml_response

Package: mycred/twilio Category: Filters
 

Description

This filter allows you to make adjustments to the response SMS body before it is sent to Twilio. The filter is used for all SMS responses no matter the instance.

 

Parameters

ParamTypeRequiredDescription
$templateSTRINGYes

The SMS message body.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Append the sites name to all sms messages sent.

 
				
					/**
 * Append Site Name to SMS
 * Append the sites name to all sms messages sent.
 * @version 1.0
 */
function mycred_pro_append_site_to_sms( $template ) {

	$template = get_bloginfo( 'name' ) . ': ' . $template;

	return $template;

}
add_filter( 'mycred_twilio_xml_response', 'mycred_pro_append_site_to_sms' );
				
			

 

mycred_user_has_paid_for_content

Package: mycred/content Category: Filters
 

Description

This filter allows you to indicate if the current user has paid / not paid for a particular content. Before a content is rendered that is set for sale using the Sell Content add-on, myCRED needs to determine if the current user has paid for the content or not. This in turn, determines if we should render the actual content or if we need to load a template asking the user to pay or buy more points (depending on your setup).

 

 

Parameters

ParamTypeRequiredDescription
$has_paidBOOLYes

Either TRUE indicating the has paid and the content should be rendered or FALSE to force the user to pay to see the content.

$user_idINTNo

The numeric ID of the user that we are checking payment for.

$post_idINTNo

The post object ID that is set for sale.

$last_paymentOBJNo

If the user has paid for the content (expired or not expired) this will contain the log entry pulled from the myCRED log. If no payment is found, this will return NULL. Added in 1.7.

Used By

PackagePrio.Description
mycred/content10Used by the mycred_user_paid_for_content function.

Example

Example 1: Allow Authors to see content set for sale using the Sell Content add-on without having to pay.

 
				
					/**
 * Allow Authors to See Content
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_user_has_paid_for_content', 'mycredpro_authors_see_content', 10, 2 );
function mycredpro_authors_see_content( $has_paid, $user_id ) {

	// User has already paid
	if ( $has_paid ) return $has_paid;

	// If the user has the role "author", indicate payment to let them see the content
	$user = get_userdata( $user_id );
	if ( in_array( 'author', $user->roles ) )
		return true;

	return $has_paid;

}
				
			

Example 2: Allow users that has reached a specific myCRED Rank to view content that has been set for sale. Requires myCRED 1.7+

				
					/**
 * Allow Masters to see Content
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_user_has_paid_for_content', 'mycredpro_master_rank_sees_content', 10, 2 );
function mycredpro_master_rank_sees_content( $has_paid, $user_id ) {

	// User has already paid
	if ( $has_paid ) return $has_paid;

	// Make sure the Rank add-on has not been disabled
	if ( function_exists( 'mycred_get_users_rank' ) ) {

		// Get users rank
		$rank = mycred_get_users_rank( $user_id );
		if ( isset( $rank->post_id ) && $rank->title == 'Master' )
			return true;

	}

	return $has_paid;

}
				
			

 

mycred_user_row_actions

Package: mycred/core Category: Filters
 

Description

This filter allows you to remove or add custom action links when viewing your users point balance on the Users page.

 

 

Parameters

ParamTypeRequiredDescription
$actionsARRAYYes

An array of links to show in the balance column.

$user_idINTNo

The numeric user ID.

$mycredOBJNo

The myCRED_Settings object set for the particular point type being shown.

Used By

PackagePrio.Description
mycred/core10Used by the myCRED_Management_Module class.

Example

Example 1: Add the option to reset a users balance from the Users page in your admin area. Requires myCRED 1.7.3+

 
				
					/**
 * Add Option to Reset Users Balance
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_user_row_actions', 'mycredpro_add_reset_balance_option', 10, 3 );
function my_custom_row_action( $actions, $user_id, $mycred ) {

	if ( $mycred->get_users_balance( $user_id ) > $mycred->zero() ) {

		$args = array(
			'action'  => 'reset-points',
			'user_id' => $user_id,
			'ctype'   => $mycred->cred_id,
			'token'   => wp_create_nonce( 'reset-users-balance' )
		);

		$actions['reset'] = '<a href="' . add_query_arg( $args, admin_url( 'users.php' ) ) . '">Reset Balance</a>';

	}

	return $actions;

}

/**
 * Handle Balance Reset
 * @since 1.0
 * @version 1.0
 */
add_action( 'admin_init', 'mycredpro_handle_balance_reset_action' );
function mycredpro_handle_balance_reset_action() {

	if ( isset( $_GET['action'] ) && isset( $_GET['token'] ) && isset( $_GET['user_id'] ) && $_GET['action'] == 'reset-points' ) {

		if ( wp_verify_nonce( $_GET['token'], 'reset-users-balance' ) && mycred_is_admin() ) {

			$point_type = sanitize_key( $_GET['ctype'] );
			$user_id    = absint( $_GET['user_id'] );
			$mycred     = mycred( $point_type );

			$mycred->set_users_balance( $user_id, 0 );

			add_action( 'admin_notices', 'mycredpro_show_balance_reset_notice' );

		}

	}

}

/**
 * Show Message for Resets
 * @since 1.0
 * @version 1.0
 */
function mycredpro_show_balance_reset_notice() {

	echo '<div id="message" class="updated notice notice-success is-dismissible"><p>Users account balance successfully reset.</div>';

}
				
			

 

mycred_userpro_insufficient

Package: mycred/hook Category: Filters
 

Description

This filter allows you to adjust the message a user sees in the chat window when they have run out of funds. Used by the UserPro Private Messaging hook.

 

Parameters

ParamTypeRequiredDescription
$messageSTRINGYes

The message to show users. Defaults to “Insufficient Funds” wrapped in a div element to be shown as a warning message.

$fromINTNo

The numeric ID of the user sending the message.

$toINTNo

The numeric ID of the message recipient.

$hookOBJNo

The hook object.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Display a custom message with a link to users when they run out of funds (assuming you charge users for sending messages).

 
				
					/**
 * Customize UserPro Message
 * @version 1.0
 */
function mycred_pro_custom_userpro_message( $message ) {

	return '<div class="userpro-msg-notice">Insufficient funds. Please <a href="http://yourwebsite.com/buy-points/">top-up</a> your account to send further messages.</div>';

}
add_filter( 'mycred_userpro_insufficient', 'mycred_pro_custom_userpro_message' );
				
			

 

mycred_userpro_stop_message

Package: mycred/hook Category: Filters
 

Description

This filter allows you to stop a private message from being sent and instead trigger the “Insufficient Funds” message. Used by the UserPro Private Messaging hook.

 

Parameters

ParamTypeRequiredDescription
$responseBOOLYes

Return TRUE to stop the message else FALSE.

$fromINTNo

The numeric ID of the user sending the message.

$toINTNo

The numeric ID of the message recipient.

$hookOBJNo

The hook object.

Used By

PackagePrio.Description
Not used by any built-in package.

mycred_users_of_rank

Package: mycred/rank Category: Filters
 

Description

This filter allows you to adjust the template used by the mycred_users_of_rank shortcode when rendering users of a rank you have setup for a particular point type. While you can set the template when using the shortcode, this filter accomplishes the exact same task.

 

Parameters

ParamTypeRequiredDescription
$row_templateSTRINGYes

The row template.

$attsARRAYNo

The attributes passed to the shortcode.

$mycredOBJNo

The myCRED object.

Used By

PackagePrio.Description
mycred/rank10Used by the mycred_users_of_rank shortcode.

mycred_users_profile_url

Package: mycred/core Category: Filters
 

Description

This filter allows you to adjust what URL the %user_profile_url% and the %user_profile_link% template tags point to.

By default, myCRED will use WordPress default author url setup, unless you have BuddyPress or bbPress installed, in which case, the profile URLs these plugins use are returned.

 

Parameters

ParamTypeRequiredDescription
$urlSTRINGYes

The profile url string.

$userOBJNo

The WordPress user object.

Used By

PackagePrio.Description
mycred/core10Used by the mycred_get_users_profile_url function.

mycred_video_output

Package: mycred/core Category: Filters
 

Description

This filter allows you to adjust the video embed that is generated by the mycred_video add-on.

 

Parameters

ParamTypeRequiredDescription
$outputSTRINGYes

The rendered shortcode content.

$attsARRAYNo

The shortcode attributes passed onto the shortcode.

Used By

PackagePrio.Description
mycred/core10Used by the mycred_video shortcode.

mycred_video_query_youtube

Package: mycred/core Category: Filters
 

Description

This filter allows you to adjust the query that is passed on to YouTube in order to embed a video. You can find a complete list of possible values you can use in the YouTube iFrame API documentation.

 

Parameters

ParamTypeRequiredDescription
$argsARRAYYes

An associative array of arguments.

$attsARRAYNo

The attributes passed on to the mycred_video shortcode.

$video_idSTRINGNo

The YouTube video id.

Used By

PackagePrio.Description
mycred/core10Used by the mycred_video shortcode.

Example

Example 1: Remove the YouTube video controller when embedding videos using the mycred_video shortcode.

 
				
					/**
 * Remove YouTube Controls on Embeds
 * @since 1.0
 * @version 1.0
 */
add_filter( 'mycred_video_query_youtube', 'mycredpro_remove_youtube_controls_on_embed' );
function mycredpro_remove_youtube_controls_on_embed( $args ) {

	$args['controls'] = 0;

	return $args;

}
				
			

 

mycred_woo_order_cost

Package: mycred/payment Category: Filters
 

Description

This filter allows you to adjust the point cost calculation in WooCommerce. The filter is used in two different instances in WooCommerce:

a) In Cart

When a user views their cart on both the cart page and on the checkout page, the filter is used to calculate the users cart total in points.

b) When paying using points

When a user selects to pay using points on the checkout page, the filter is used to calculate the amount of points a user must pay for the order. If the user does not have the point amount this filter returns, the payment is declined.

By default, the exchange rate you set in your settings is used to calculate the cost but you can use this filter to run your own calculation.

 

Parameters

ParamTypeRequiredDescription
$costINT or FLOATYes

The cost of the cart / order in your store currency.

$order_or_cartOBJNo

Either the cart object or the order object, depending on where the filter is used.

$is_cartBOOLNo

Returns TRUE if the filter is used when showing the cart total cost in points and FALSE when calculating the cost during checkout (if the buyer selected to pay using points).

$gatewayOBJNo

The myCRED payment gateway object.

Used By

PackagePrio.Description
mycred/payment10Used by the myCRED payment gateway.

Example

Example 1: Apply a custom exchange rate for users with the “Author“ role. Everyone else gets the exchange rate you set in your settings.

				
					/**
 * Custom Cost for Authors
 * Apply a custom exchange rate for WooCommerce costs for
 * users that have the author role.
 * @version 1.0
 */
add_filter( 'mycred_woo_order_cost', 'mycred_pro_custom_woo_cost_for_authors', 10, 4 );
function mycred_pro_custom_woo_cost_for_authors( $cost, $order_or_cart, $is_cart, $gateway ) {

	// Only applicable to "Authors"
	$user = wp_get_current_user();
	if ( empty( $user->roles ) || ! in_array( 'author', $user->roles ) ) return $cost;

	// The custom rate to apply for authors
	$custom_rate = 0.1;

	// Get the amount that needs to be paid depending on where the filter is used
	if ( $is_cart )
		$total_cost = $order_or_cart->total;
	else
		$total_cost = $order_or_cart->order_total;

	// Calculate cost in points
	$custom_cost = $gateway->mycred->number( $total_cost / $custom_rate );

	return $custom_cost;

}
				
			

 

mycred_woo_reward_cap

Package: mycred/payment Category: Filters
 

Description

This filter allow you to adjust the capability required for the “myCRED” point reward metabox to be visible when editing a WooCommerce product. By default, your users (and yourself) need to have the edit_others_posts capability to set how many points a product rewards (if at all). This capability on default WordPress installations is held by the “Administrator” and “Editor” roles.

 

Parameters

ParamTypeRequiredDescription
$capabilitySTRINGYes

The WordPress capability required for the metabox to be accessible. This can be a custom capability as well.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Change the requirement to a capability that only Administrators have in order to prevent Editors from using it.

 
				
					/**
 * Adjust Woo Reward Cap
 * @version 1.0
 */
function mycred_pro_adjust_woo_reward_cap( $cap ) {

	return 'edit_users';

}
add_filter( 'mycred_woo_reward_cap', 'mycred_pro_adjust_woo_reward_cap' );
				
			

 

mycred_woo_reward_log

Package: mycred/hook Category: Filters
 

Description

This filter allows you to adjust the log entry myCRED adds with each WooCommerce store reward payout.

 

Parameters

ParamTypeRequiredDescription
$log_templateSTRINGYes

The log template to use.

$order_idINTNo

The WooCommerce order ID.

$point_typeSTRINGNo

The point type key, representing the point type the user is paid.

Used By

PackagePrio.Description
Not used by any built-in package.

Example

Example 1: Basic Usage

				
					/**
 * Change Woo Reward Template
 * @version 1.0
 */
function mycred_pro_adjust_woo_reward_log( $log_template, $order_id ) {

	return sprintf( 'Reward for your sore order #%d', $order_id );

}
add_filter( 'mycred_woo_reward_log', 'mycred_pro_adjust_woo_reward_log', 10, 2 );