Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
gabrielmerovingi / mycred-woo-reward-log-filter-example1
Created October 2, 2017 09:39
Change the log entry users see in their history for points they gain from WooCommerce store purchases.
/**
* Change Woo Rewards Log
* @version 1.0
*/
function mycred_pro_adjust_woo_rewards_log( $log_entry = '' ) {
return 'Store Purchase Reward';
}
add_filter( 'mycred_woo_reward_log', 'mycred_pro_adjust_woo_rewards_log' );
@gabrielmerovingi
gabrielmerovingi / enforce-max-mycred-balance
Last active January 28, 2021 13:24
Example where we enforce a maximum balance of 1000 points in myCRED. If a user is about to get points that exceeds this limit, we decline the transaction. Goes into your custom plugin or child theme's functions.php file.
/**
* Enforce Maximum
* Make sure users can not earn more than 1000 points.
* @version 1.0
*/
function mycred_enforce_max_balance( $run, $request, $mycred ) {
extract( $request );
// The maximum balance a user can have
/**
* Disable Total Balance Updates
* @version 1.0
*/
function mycred_pro_disable_total_balanace_update( $value = NULL, $object_id, $meta_key, $meta_value, $prev_value ) {
if ( $meta_key == 'mycred_default_total' )
return true;
return $value;
stop_current_time( get_current_dimention() );
while ( have_tasks() ) {
assign_task_to_dimention( the_task() );
}
do {
@gabrielmerovingi
gabrielmerovingi / delete-old-mycred-entries
Created September 22, 2017 10:53
Daily cron script that will delete log entries that are "older" than a given timestamp.
/**
* Delete Old Entries
* Uses the daily myCRED cron job "mycred_cron_reset_key" to
* delete entries that are older than a given time each day
* @version 1.0
*/
function mycred_pro_delete_old_entries() {
// The maximum age a log entry can have in seconds
// Example 3 months
@gabrielmerovingi
gabrielmerovingi / mycred-bp-profile-header-filter-example1
Created September 14, 2017 18:33
Show BP profile balances only for admins. Requires you to have selected to show balances in profile headers in your myCRED settings.
function mycred_pro_bp_profile_balance( $output, $balance_template, $buddypress_module ) {
if ( ! mycred_is_admin() )
return '';
return $output;
}
add_filter( 'mycred_bp_profile_header', 'mycred_pro_bp_profile_balance', 10, 3 );
@gabrielmerovingi
gabrielmerovingi / mycred-pt-get-fee-filter-example2
Last active September 14, 2017 14:30
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;
@gabrielmerovingi
gabrielmerovingi / mycred-pt-get-fee-filter-example1
Created September 14, 2017 14:27
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' ) )
@gabrielmerovingi
gabrielmerovingi / mycred-run-this-filter-example3
Created September 9, 2017 09:44
Give users bonus points when they buy points using the buyCRED add-on. Base the amount of bonus a user gets 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;
@gabrielmerovingi
gabrielmerovingi / mycred-transfer-to-field-filter-example1
Created August 28, 2017 14:27
Generates a dropdown menu of transfer recipients that has been set in the mycred_transfer shortcode by providing a comma separated list of ids for the pay_to shortcode attribute. Requires 1.7.9.1 or higher!
/**
* Preselect Transfer Recipient
* Generates a dropdown menu of transfer recipients that has been
* set in the mycred_transfer shortcode by providing a comma separated list of
* ids for the pay_to shortcode attribute.
* @since 1.0
* @version 1.0
*/
function mycred_pro_pre_selected_transfer_recipients( $field, $settings, $atts ) {