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
Param | Type | Required | Description |
---|---|---|---|
$reply | BOOL | Yes | The result of this filter. Should either be true (run the request) or false (stop the request). |
$request | ARRAY | No | 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. |
$mycred | OBJ | No | The current myCRED_Settings class object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/banking | 1 | The 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.
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
Param | Type | Required | Description |
---|---|---|---|
$result | BOOL | Yes | The transaction result. Returns either TRUE if the transaction was executed or FALSE if the transaction was declined. |
$request | ARRAY | No | The transaction request that was processed as returned by the mycred_run_this shortcode. |
$mycred | OBJ | No | The myCRED_Settings class object processing the transaction request. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/rank | 20 | Used to determine if the transaction promotes or demotes a users rank. |
mycred/badge | 30 | Used to determine if a successful transaction should earn the user a badge. |
mycred/notice | 40 | Used to determine if the transaction should trigger a popup notification. |
mycred/email | 50 | Used 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.
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
Param | Type | Required | Description |
---|---|---|---|
$lifespan | INT | Yes | A unix timestamp when the cookie will expire. By default this is 24 hours from the current time. |
$signup | BOOL | No | Indicates if this is for the signup (true) or the visitor (false) cookie. |
$hook | OBJ | No | The Points for Referrals hook class object. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Example
Example 1: Change the cookies lifespan from 24 hours to 1 year.
mycred_affiliate_key
This filter allows you to adjust the affiliate referral key that the hook uses. By default this is mref.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$key | STRING | Yes | The key. Defaults to |
$hook | OBJ | No | The hook object. |
Used By
Package | Prio. | 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.
Description
This filter allows you to add / remove / rename any of the built-in myCRED references.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$list | ARRAY | Yes | An associative array of references that have been registered in myCRED. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Example
Example 1: Add a custom reference.
Description
This filter allows you to change the HTML elements that myCRED will allow in the history shortcode.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$allowed | ARRAY | Yes | Array of HTML elements and their attributes that are allowed to be used. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Example
Example 1: Change the allowed HTML elements to only accept paragraphs and Emphasized text.
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
Param | Type | Required | Description |
---|---|---|---|
$exchange | INT or FLOAT | Yes | The final exchange value. |
$amount | INT or FLOAT | No | The amount to be exchanged. Usually a real life currency. |
$rate | INT or FLOAT | No | The exchange rate being applied to |
$round | BOOL | No | Indicates if the amount should be rounded (TRUE) or not (FALSE). |
Used By
Package | Prio. | Description |
---|---|---|
mycred/payment | 10 | MarketPress payment gateway. |
mycred/payment | 20 | WooCommerce payment gateway. |
Description
This filter allows you to adjust the badge image element before it is rendered.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$html | STRING | Yes | The badge image element. |
$image | INT or STRING | No | Either |
$badge_object | OBJ | No | The myCRED_Badge object. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Example 1: Add a Bootstrap tooltip to all badge images except for the main badge image.
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
Param | Type | Required | Description |
---|---|---|---|
$new_level | INT | Yes | The new level ID a user earned. Remember that Level IDs start from ZERO and not from 1. |
$user_id | INT | No | The users WordPress id. |
$badge_id | INT | No | The badges post object ID. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Description
This filter allows you to add or adjust the settings saved by the compound interest banking service.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$settings | ARRAY | Yes | An associative array of settings for the service. |
$service | OBJ | No | The Compound Interest class object. |
$rescheduled | BOOL | No | Returns true if the service was re-scheduled or false if not. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Description
This filter allows you to save custom settings you might have added to the Recurring Payout service in the Banking add-on.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$settings | ARRAY | Yes | An associative array of settings for the service. |
$service | OBJ | No | The Recurring Payout class object. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Description
This filter allows you to render the contents of a custom leaderboard column in the myCRED BP Group Leaderboards plugin.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$content | STRING | Yes | The column content as a string. |
$row | OBJ | No | The leaderboard row object. |
$group_id | INT | No | The current BuddyPress Group ID. |
$point_type | STRING | No | The myCRED point type key the leaderboard is based on. |
Used By
Package | Prio. | 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“.
Description
This filter allows you to adjust the leaderboard table columns that the myCRED BP Group Leaderboards plugin creates.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$columns | ARRAY | Yes | An associative array of column IDs and their labels. |
Default columns:
Column ID | Description |
---|---|
position | The users leaderboard position. |
member | The group member. |
balance | The point value. |
Used By
Package | Prio. | 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.
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
Param | Type | Required | Description |
---|---|---|---|
$position | INT | Yes | The users numeric position in the leaderboard. |
$group_id | INT | No | The BuddyPress Group ID. |
$user_id | INT | No | The numeric WordPress user ID. |
$point_type | STRING | No | The point type key the leaderboard is based on. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Example
Example 1: Example showing how we can query a users position in an annual leaderboard.
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
Param | Type | Required | Description |
---|---|---|---|
$leaderboard | ARRAY | Yes | The leaderboard array. |
$group_id | INT | No | The BuddyPress Group id. |
$point_type | STRING | No | The myCRED point type the leaderboard is based on. |
$append_user | INT or BOOL | No | The WordPress user ID of a user to append to the end of the leaderboard. |
$fresh | BOOL | No |
|
Used By
Package | Prio. | 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.
Description
This filter allows you to adjust, add or remove leaderboards types in the myCRED BP Group Leaderboards plugin.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$leaderboards | ARRAY | Yes | An associative array of leaderboard type keys and labels. |
Used By
Package | Prio. | 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' );
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.
Description
This filter allows you to adjust the way ranks are rendered in the BuddyPress user profile (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.
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
Param | Type | Required | Description |
---|---|---|---|
$cost | INT or FLOAT | Yes | The cost of the purchase. |
$amount | INT or FLOAT | No | The amount of points being purchased. |
$type | STRING | No | The point type key being purchased. |
$gateway_prefs | ARRAY | No | The selected payment gateways settings. |
$buycred_prefs | ARRAY | No | The buyCRED add-ons settings. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/purchase | 10 | Used 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.
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
Param | Type | Required | Description |
---|---|---|---|
$references | ARRAY | Yes | An Array of references that should be ignored by the central bank. Defaults to: interest , recurring_payout and transfer . |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$limit | INT | Yes | The number of balances to compound per instance. |
$service | OBJ | No | The compound interest banking service object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/banking | 10 | Default usage |
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
Param | Type | Required | Description |
---|---|---|---|
$limit | INT | Yes | The number of compounded interests to payout per instance. |
$service | OBJ | No | The compound interest banking service object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/banking | 10 | Default usage |
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.
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
Param | Type | Required | Description |
---|---|---|---|
$reference | STRING | Yes | The reference to use. Can not be empty or no points will be awarded! |
$post | OBJ | No | The WordPress post object that is getting deleted. |
$hook | OBJ | No | The hook object. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$override | BOOL | Yes | Should return TRUE if the event should be approved or FALSE if not. |
$booking | OBJ | No | The event booking object. |
$gateway | OBJ | No | The myCRED Gateway object class. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Description
This filter allows you to adjust the details of an email notification before it is sent.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$email | ARRAY | Yes | An associative array of email details:
|
Used By
Package | Prio. | Description |
---|---|---|
mycred/payment | 10 | The WooCommerce gateway uses this filter to render the order details before the email is sent. |
mycred/payment | 20 | The MarketPress gateway uses this filter to render the order details before the email is sent. |
mycred/payment | 30 | The WP E-Commerce gateway uses this filter to render the order details beforethe email is sent. |
mycred/content | 40 | The Sell Content add-on uses this filter to render the purchase details before the email is set. |
mycred/transfer | 50 | The 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.
Description
This filter allows you to add / remove or adjust email instances that is selectable when creating or editing an email notice.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$instances | ARRAY | Yes | 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
Package | Prio. | 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.
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+)
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
Param | Type | Required | Description |
---|---|---|---|
$headers | ARRAY | Yes | An associative array of column ids and their corresponding labels. |
$raw | BOOL | No | Indicates if the export is selected to be done “raw” |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$results | OBJ or BOOL | Yes | The results object or FALSE if no rank was found. |
$user_id | INT | No | The ID of the user for whom we requested to find a rank. |
$point_type | STRING | No | The point type for which the rank is queried. Added in 1.6. |
Results Object
Property | Type | Description | |
---|---|---|---|
Results Object ( | |||
rank_id | INT | The rank ID a user should have. | |
current_id | INT | The rank ID a user currently have. | |
minimum | INT or FLOAT | The minimum point requirement for the rank the user should have. | |
maximum | INT or FLOAT | The maximum point requirement for the rank the user should have. | |
ctype | STRING | The point type associated with the rank. | |
) |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$points | STRING | Yes | The point amount rendered with prefix / suffix (if used). |
$amount | INT or FLOAT | No | The original amount before it was formatted. |
$mycred | OBJ | No | The myCRED_Settings class object. |
Used By
Package | Prio. | 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 ' ' . $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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$formatted | INT or FLOAT | Yes | The point value formatted based on the point type setup. |
$number | INT or FLOAT | No | The original value. |
$mycred | OBJ | No | The myCRED_Settings class object. |
Used By
Package | Prio. | 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 );
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
Param | Type | Required | Description |
---|---|---|---|
$price | INT or FLOAT | Yes | The price in points. |
$post_id | INT | No | The post object ID. |
$point_type | STRING | No | The point type that the price is requested for. |
$user_id | INT | No | The numeric ID of the user who needs to pay for this content. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/content | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$balance | INT or FLOAT | Yes | The balance value. |
$mycred | OBJ | No | The myCRED_Settings class object. |
$user_id | INT | No | The requested users ID. |
$type | STRING | No | The point type being requested. |
Used By
Package | Prio. | 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$run | BOOL | Yes | If the shortcode is set to run ( |
$atts | ARRAY | No | The shortcode attributes that are being used. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Example
Example 1: Disable usage of this shortcode.
add_filter( 'mycred_give_run', '__return_false' );
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
Param | Type | Required | Description |
---|---|---|---|
$result | BOOL | Yes | Returns TRUE if the log entry exists or FALSE. |
$reference | STRING | No | The reference being checked. Is NULL if not used. |
$ref_id | INT | No | The reference ID being checked. Is NULL if not used. |
$user_id | INT | No | The user ID being checked. Is NULL if not used. |
$data | STRING | No | The log data being checked. If used, this can be a string or a serialized array. Is NULL if not used. |
$type | STRING | No | The point type being checked. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Description
Used by the mycred_have_ranks function when checking if any ranks exists for a given point type.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$results | BOOL | Yes | Returns TRUE if ranks exists or FALSE. |
$point_type | STRING | No | The point type being checked. Is NULL if checking no matter which point type is installed. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$label | STRING | Yes | 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';
}
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
Param | Type | Required | Description |
---|---|---|---|
$template | STRING | Yes | The template string. |
$user_id | INT | No | The ID of the users balance we are showing. |
$point_type | STRING | No | The point type used. |
Used By
Package | Prio. | 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%';
}
Description
This filter allows you to adjust the anchor element the mycred_link shortcode renders.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$html | STRING | Yes | The HTML anchor element. |
$atts | ARRAY | No | The shortcode attributes being used. |
$link_title | STRING | No | The link title set for the shortcode. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$content | STRING | Yes | 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. |
$entry | OBJ | No | The database row object for the entry in question. |
Used By
Package | Prio. | 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;
}
Description
This filter allows you to adjust the bulk actions that are available on the log page in the admin area.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$actions | ARRAY | Yes | An array of bulk actions ids and action labels. |
$module | OBJ | No | The myCRED_Log_Module class object. |
Default Bulk Actions
Action ID | Label |
---|---|
-1 | Bulk Actions |
export-raw | Export Raw |
export-format | Export Formatted |
delete | Delete |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$columns | ARRAY | Yes | An array of column IDs and column labels. |
$class | OBJ | No | 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
Package | Prio. | 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$columns | ARRAY | Yes | An array of column IDs and column labels. |
$class | OBJ | No | 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_admin | BOOL | No | 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
Package | Prio. | Description |
---|---|---|
mycred/buddypress | 10 | The 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;
}
Description
This filter allows you to adjust how dates in the log or in exports are presented.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$date | STRING | Yes | The formatted date to show. |
$time | INT | No | The original unix timestamp being formatted. |
$entry | OBJ | No | The log entry object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/log | 10 | Used by the log query class. |
mycred/log | 20 | Used 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';
}
Description
This filter allows you to adjust, add or remove CSS classes for each table row when viewing the log.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$classes | ARRAY | Yes | Array of CSS classes. |
$entry | OBJ | No | The log entry object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/log | 10 | Used 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;
}
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
- Description
- Used by
- Parameters
- Examples
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';
}
Navigation:
- Description
- Used By
- 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.
Navigation:
- Description
- Used By
- 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.
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
Param | Type | Required | Description |
---|---|---|---|
$args | ARRAY | Yes | Associative array of arguments. |
$module | OBJ | No | The myCRED Notifications Plus module object. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Example
Example 1: Disable front end debugging for administrators.
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
Param | Type | Required | Description |
---|---|---|---|
$notifications | ARRAY | No | Array of notifications. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/notice | 10 | Used by the notification add-on to get notifications. |
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
Param | Type | Required | Description |
---|---|---|---|
$template | STRING | Yes | The notification template. |
$request | ARRAY | No | The point request array that triggered this notification. |
$mycred | OBJ | No | The myCRED point type object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/notice | 10 | Used by the notification add-on. |
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
Param | Type | Required | Description |
---|---|---|---|
$content | STRING | Yes | The rendered log entry string. |
$amount | INT or FLOAT | No | The original point amount. |
$mycred | OBJ | No | The myCRED point type object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used 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 );
}
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
Param | Type | Required | Description |
---|---|---|---|
$content | STRING | Yes | The rendered log entry string. |
$comment | OBJ | No | The WordPress comment object. |
$data | ARRAY | No | The value stored in the data column of the log entry. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$content | STRING | Yes | The log entry string. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used by the myCRED_Settings class. |
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
Param | Type | Required | Description |
---|---|---|---|
$content | STRING | Yes | The rendered log entry string. |
$post | OBJ | No | The WordPress post object. |
$data | ARRAY | No | The value stored in the data column of the log entry. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$content | STRING | Yes | The rendered log entry string. |
$user | ARRAY or OBJ | No | 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. |
$data | ARRAY | No | The value stored in the data column of the log entry. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$results | BOOL | Yes | Returns TRUE if the post is for sale or FALSE. |
$post | OBJ | No | The post object being checked. |
$settings | ARRAY | No | The 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;
}
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 );
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
Param | Type | Required | Description |
---|---|---|---|
$new_statuses | ARRAY | Yes | An array of statuses a post needs to transition to. By default these are: |
$post_id | INT | No | The post objects ID. |
$point_type | STRING | No | The point type key currently being processed. |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$old_statuses | ARRAY | Yes | An array of statuses a post needs to transition from. By default these are: |
$post_id | INT | No | The post objects ID. |
$point_type | STRING | No | The point type key currently being processed. |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$reference | STRING | Yes | The reference to use. Can not be empty or no points will be awarded! |
$post | OBJ | No | The WordPress post object that is getting published. |
$new_status | STRING | No | The new status the post is receiving by WordPress. |
$old_status | STRING | No | The posts old status. |
$hook | OBJ | No | The hook object. |
Used By
Package | Prio. | 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 );
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
Param | Type | Required | Description |
---|---|---|---|
$args | ARRAY | Yes | An associative array of arguments. |
$defaults | ARRAY | No | 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
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$row_template | STRING | Yes | The row template. |
$atts | ARRAY | No | The attributes passed to the shortcode. |
$mycred | OBJ | No | The myCRED object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/rank | 10 | Used 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 '%rank%%min%%max%';
}
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
Param | Type | Required | Description |
---|---|---|---|
$layout | STRING | Yes | The row string. |
$template | STRING | No | The original row template. |
$user | OBJ | No | The WordPress user object. |
$position | INT | No | The users position in the leaderboard. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/log | 10 | Used 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 );
}
Description
This filter allows you to adjust the MySQL query string used for generating a leaderboard through the mycred_leaderboard shortcode.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$query | STRING | Yes | The SQL query string. |
$atts | ARRAY | No | Associative array of the shortcode attributes currently being used. Will include custom shortcode attributes that might be used. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$limit | INT | Yes | The number of users to execute per instance. |
$service | OBJ | No | The recurring payout banking service object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/banking | 10 | Default usage |
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
Param | Type | Required | Description |
---|---|---|---|
$args | ARRAY | Yes | The post type settings array. |
$module | OBJ | No | The myCRED_Ranks_Module class. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/rank | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$request | ARRAY | Yes | An associative array representing the transaction that is to be processed. |
$mycred | OBJ | No | The myCRED_Settings class object processing the transaction request. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used 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 );
Description
This filter allows you to add, replace or remove templates for the Scratch Card add-on.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$templates | ARRAY | Yes | An associative array of available templates. You can read more about this in the Scratch Card documentation. |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$allow | BOOL | Yes |
|
$set_id | INT | No | The card sets WordPress post ID. |
Used By
Package | Prio. | 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' );
Description
This filter allows you to change the priority of the Sell Content add-ons content filtering.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$priority | INT | Yes | The priority number. Defaults to |
$sell_content_module | OBJ | No | The Sell Content module. |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$label | STRING | No | The title to show. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/content | 10 | Used 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'; }
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
Param | Type | Required | Description |
---|---|---|---|
$expiration | INT | No | 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. |
$length | INT | No | The length set for this particular post. |
$user_id | INT | No | The numeric ID of the user this calculation is related to. |
$post_id | INT | No | The post ID. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/content | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$button | STRING | Yes | The HTML button element. |
$post | OBJ | No | The WordPress post object that this button is being rendered for. |
$setup | ARRAY | No | 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. |
$mycred | OBJ | No | The myCRED_Settings object currently being used. |
Used By
Package | Prio. | 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( '">', '"> ', $button );
}
add_filter( 'mycred_sell_this_button', 'mycred_pro_insert_buy_button_icon' );
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
Param | Type | Required | Description |
---|---|---|---|
$label | STRING | Yes | The metabox title string. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/content | 10 | Used by the myCRED_Sell_Content_Module class. |
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 transactionserror
– used on transactions that failed.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$instances | ARRAY | Yes | An array of strings used by the mycred_send shortcode. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used by the mycred_send shortcode. |
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
Param | Type | Required | Description |
---|---|---|---|
$addons | ARRAY | Yes | An associative array of add-ons installed. Structure:
|
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used by the myCRED_Addons_Module class. |
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
Param | Type | Required | Description |
---|---|---|---|
$services | ARRAY | Yes | An associated array of installed services. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/banking | 10 | Used 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;
}
Description
This filter allows you to add custom hooks or remove built-in ones.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$hooks | ARRAY | Yes | An associated array of installed hooks. |
$point_type | STRING | No | 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
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$minimum | INT or FLOAT | Yes | The lowest amount a users balance can go when transferring. Defaults to zero. |
$point_type | STRING | No | The point type being transferred. |
$user_id | INT | No | The numeric ID of the user making the transfer. |
$reference | STRING | No | The reference under which the transfer is being made. Usable when you allow multiple types of transfers. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/transfer | 10 | Used by the transfer add-on. |
mycred/core | 20 | Used 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;
}
Description
This filter allows you to add / remove autocomplete options in the Transfer add-on.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$options | ARRAY | Yes | An associative array of autocomplete value and label that is shown in the dropdown menu. |
$settings | ARRAY | No | The transfer add-on settings. |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$instances | ARRAY | Yes | An array of strings used by the mycred_transfer shortcode. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/transfer | 10 | Used by the myCRED_Transfer_Module class. |
Description
This filter allows you to adjust a given phone numbers formating.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$phone_number | STRING | Yes | The phone number formatted by appending the country code and removing non numeric characters. |
$number | STRING | No | The original number before formating. |
$country_code | STRING | No | The country code saved in the plugin settings. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$sender | BOOL or OBJ | Yes | Either |
$number | STRING | No | The phone number as sent from Twilio. Example for North American numbers: |
$meta_key | STRING | No | Either the user meta key where the phone number is stored or the field name if BuddyPress is used. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$user_id | BOOL or INT | Yes | Either |
$number | STRING | No | The phone number as sent from Twilio. Example for North American numbers: |
$meta_key | STRING | No | Either the user meta key where the phone number is stored or the field name if BuddyPress is used. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$number | BOOL or STRING | Yes | Either |
$user_id | INT | No | The users numeric ID. |
$meta_key | STRING | No | Either the user meta key where the phone number is stored or the field name if BuddyPress is used. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Description
This filter allows you to adjust the SMS message body when received by the Twilio Transfers plugin.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$sms | ARRAY | Yes | The message body converted into an array. By default, the body content is split into 4 pieces. |
$body | STRING | No | The SMS message body in it’s raw form. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
Description
This filter allows you to format a Twilio phone number into the way you format phone numbers on your website.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$number | STRING | Yes | The phone number Twilio sends. This is an unformatted phone number with the country code appended to the beginning. |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$template | STRING | Yes | The SMS message body. |
Used By
Package | Prio. | 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' );
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
Param | Type | Required | Description |
---|---|---|---|
$has_paid | BOOL | Yes | 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_id | INT | No | The numeric ID of the user that we are checking payment for. |
$post_id | INT | No | The post object ID that is set for sale. |
$last_payment | OBJ | No | 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
Package | Prio. | Description |
---|---|---|
mycred/content | 10 | Used 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;
}
Description
This filter allows you to remove or add custom action links when viewing your users point balance on the Users page.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$actions | ARRAY | Yes | An array of links to show in the balance column. |
$user_id | INT | No | The numeric user ID. |
$mycred | OBJ | No | The myCRED_Settings object set for the particular point type being shown. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used 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'] = 'Reset Balance';
}
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 'Users account balance successfully reset.
';
}
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
Param | Type | Required | Description |
---|---|---|---|
$message | STRING | Yes | The message to show users. Defaults to “Insufficient Funds” wrapped in a div element to be shown as a warning message. |
$from | INT | No | The numeric ID of the user sending the message. |
$to | INT | No | The numeric ID of the message recipient. |
$hook | OBJ | No | The hook object. |
Used By
Package | Prio. | 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 'Insufficient funds. Please top-up your account to send further messages.';
}
add_filter( 'mycred_userpro_insufficient', 'mycred_pro_custom_userpro_message' );
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
Param | Type | Required | Description |
---|---|---|---|
$response | BOOL | Yes | Return |
$from | INT | No | The numeric ID of the user sending the message. |
$to | INT | No | The numeric ID of the message recipient. |
$hook | OBJ | No | The hook object. |
Used By
Package | Prio. | Description |
---|---|---|
Not used by any built-in package. |
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
Param | Type | Required | Description |
---|---|---|---|
$row_template | STRING | Yes | The row template. |
$atts | ARRAY | No | The attributes passed to the shortcode. |
$mycred | OBJ | No | The myCRED object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/rank | 10 | Used by the mycred_users_of_rank shortcode. |
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
Param | Type | Required | Description |
---|---|---|---|
$url | STRING | Yes | The profile url string. |
$user | OBJ | No | The WordPress user object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used by the mycred_get_users_profile_url function. |
Description
This filter allows you to adjust the video embed that is generated by the mycred_video add-on.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$output | STRING | Yes | The rendered shortcode content. |
$atts | ARRAY | No | The shortcode attributes passed onto the shortcode. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used by the mycred_video shortcode. |
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
Param | Type | Required | Description |
---|---|---|---|
$args | ARRAY | Yes | An associative array of arguments. |
$atts | ARRAY | No | The attributes passed on to the mycred_video shortcode. |
$video_id | STRING | No | The YouTube video id. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/core | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$cost | INT or FLOAT | Yes | The cost of the cart / order in your store currency. |
$order_or_cart | OBJ | No | Either the cart object or the order object, depending on where the filter is used. |
$is_cart | BOOL | No | 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). |
$gateway | OBJ | No | The myCRED payment gateway object. |
Used By
Package | Prio. | Description |
---|---|---|
mycred/payment | 10 | Used 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;
}
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
Param | Type | Required | Description |
---|---|---|---|
$capability | STRING | Yes | The WordPress capability required for the metabox to be accessible. This can be a custom capability as well. |
Used By
Package | Prio. | 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' );
Description
This filter allows you to adjust the log entry myCRED adds with each WooCommerce store reward payout.
Parameters
Param | Type | Required | Description |
---|---|---|---|
$log_template | STRING | Yes | The log template to use. |
$order_id | INT | No | The WooCommerce order ID. |
$point_type | STRING | No | The point type key, representing the point type the user is paid. |
Used By
Package | Prio. | 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 );