Skip to content

Instantly share code, notes, and snippets.

function mycred_pro_detect_point_purchases( $ran, $request, $mycred ) {
extract( $request );
// New point purchase
if ( substr( $ref, 14 ) == 'buy_creds_with' ) {
$transaction = explode( '|', $data['sales_data'] );
$transaction_id = $data['txn_id'];
@gabrielmerovingi
gabrielmerovingi / mycred-disable-notice-on-blog
Last active September 19, 2017 14:41
Example: Disable the built-in Notifications add-on on blog 4.
/**
* Disable Notifications
* @since 1.0
* @version 1.0.1
*/
function mycred_pro_disable_notices( $modules ) {
$blog_to_block = 4;
if ( get_current_blog_id() == $blog_to_block && array_key_exists( 'notices', $modules['solo'] ) ) {
@gabrielmerovingi
gabrielmerovingi / mycred-bp-charges-message
Last active August 25, 2017 16:44
Hide BP Charges cost messages.
// Hide cost messages for everyone
add_filter( 'mycred_bp_show_charge_message_cost', '__return_false' );
add_filter( 'mycred_bp_show_charge_reply_cost', '__return_false' );
// Hide cost messages for users with a certain capability
function mycred_pro_maybe_hide_bp_charge_cost( $show = true ) {
if ( current_user_can( 'bp_charges_pay' ) )
return false;
if ( function_exists( 'mycred_get_woo_product_reward' ) ) {
$product_id = 1;
$point_type = MYCRED_DEFAULT_TYPE_KEY;
$reward = mycred_get_woo_product_reward( $product_id, NULL, $point_type );
if ( $reward !== false && $reward != '' )
printf( 'Earn %s Points buying this product.', $reward );
}
function mycred_pro_timeframe_total_balance( $query, $atts ) {
if ( ! empty( $atts ) && array_key_exists( 'based_on', $atts ) && $atts['based_on'] == 'balance' ) {
if ( array_key_exists( 'total', $atts ) && $atts['total'] == 1 && array_key_exists( 'timeframe', $atts ) && $atts['timeframe'] != '' )
$query = str_replace( "l.ref = 'manual' ) )", "l.ref = 'manual' ) ) AND time >= " . strtotime( $atts['timeframe'], current_time( 'timestamp' ) ), $query );
}
return $query;
function mycred_pro_maybe_hide_message_charge( $content ) {
// Only applicable to texts starting with New Reply:
if ( substr( $content, 0, 10 ) == 'New Reply:' && function_exists( 'bp_loggedin_user_id' ) ) {
$user_id = bp_loggedin_user_id();
// If a user does not the bp_charges_pay capability
// hide the message
if ( ! user_can( 'bp_charges_pay', $user_id ) )
@gabrielmerovingi
gabrielmerovingi / bp-charges-pretend-we-can-afford
Created August 2, 2017 12:14
Pretend users that are exempt from being charged can afford to send new messages even if their balance is zero.
/**
* Pretend User Can Afford
* Pretend users that are exempt from being charged can afford to send
* new messages even if their balance is zero.
* @version 1.0
*/
function mycred_pro_pretend_user_can_afford( $can_afford ) {
$user_id = bp_loggedin_user_id();
@gabrielmerovingi
gabrielmerovingi / bp-charges-messages
Created August 2, 2017 12:08
Exempt users with a specific capability from being charged for sending private messages in BP Charges.
/**
* Maybe Charge Message
* Exempt users with a specific capability from being
* charged for sending private messages in BP Charges.
* @version 1.0
*/
function mycred_pro_maybe_charge_new_message( $charge, $thread_id, $module ) {
$user_id = bp_loggedin_user_id();
@gabrielmerovingi
gabrielmerovingi / reward-woo-owners-with-points
Created July 5, 2017 15:58
For each completed WooCommerce order, give the product author 1 point for each product they sell. If the order is refunded, take those points away. Note that this will only run once per order.
/**
* Reward Store Sales
* @version 1.0
*/
function mycred_pro_reward_store_sales( $order_id ) {
// Prevent crashes if myCRED gets disabled
if ( ! function_exists( 'mycred' ) ) return;
// Get order
@gabrielmerovingi
gabrielmerovingi / mycred-userpro-insufficient-filter-example1
Created July 3, 2017 23:20
Display a custom message with a link when users run out of points and can not send further private messages in UserPro.
/**
* Customize UserPro Message
* @version 1.0
*/
function mycred_pro_custom_userpro_message( $message ) {
return '<div class="userpro-msg-notice">Insufficient funds. Please <a href="http://yourwebsite.com/buy-points/">top-up</a> your account to send further messages.</div>';
}
add_filter( 'mycred_userpro_insufficient', 'mycred_pro_custom_userpro_message' );