Skip to content

Instantly share code, notes, and snippets.

@mycred
mycred / Log Entries to BuddyPress Notifications
Created July 19, 2018 10:48
This is an example how you can add BuddyPress notifications for users when they gain / lose myCRED points.
/**
* Register Custom BP Notifications
* Inform BuddyPress about our custom myCRED related notifications.
* @since 1.0
* @version 1.0
*/
function mycredpro_register_custom_bp_notifications() {
buddypress()->mycred_notifications = new stdClass;
buddypress()->mycred_notifications->notification_callback = 'mycredpro_render_bp_notification';
@mycred
mycred / Manual Mycred Badges
Created July 19, 2018 14:12
By default, myCRED will give users a badge automatically based on your setup. This snippet will allow you to create badges that will never be automatically awarded to users. These manual badges would need to be added manually by editing the user in the admin area.
/**
* Manual Badge Reference
* @version 1.0
*/
add_filter( 'mycred_all_references', 'mycred_pro_manual_badge' );
function mycred_pro_manual_badge( $references ) {
$references['disabled_feature'] = 'Badge is manually awarded';
return $references;
@mycred
mycred / myCRED_total.php
Created July 23, 2018 05:40
Display the total current users myCRED awarded and lost points in front end.
<?php
/**
* Plugin Name: myCRED User Awarded
* Plugin URI: http://www.birminghamiu.co.uk
* Description: Display the total current users myCRED awarded and lost points in front end.
* Version: 1.0
* Author: G. Lloyd
* Author URI: http://www.birminghamiu.co.uk
* License: Copyrighted
*
@mycred
mycred / mycred-hook-wp-courseware
Created July 23, 2018 05:49
Custom myCRED Hook for WP Courseware. Points can be awarded or deducted for users completing units, modules and courses. Requires myCRED 1.6 or higher.
/**
* WP Courseware Hook
* @version 1.0.2
*/
add_filter( 'mycred_setup_hooks', 'mycred_register_courseware_hook' );
function mycred_register_courseware_hook( $installed ) {
$installed['courseware'] = array(
'title' => 'WP Courseware',
'description' => 'Award or deduct %plural% for users completing WP Courseware courses, modules or units.',
'callback' => array( 'myCRED_Hook_CourseWare' )
@mycred
mycred / mycred-hook-wp-postviews
Created July 23, 2018 05:56
Custom myCRED Hook for WP Postviews. Points can be awarded or deducted for each post view registered by the plugin with an option to set a limit. Requires myCRED 1.6 or higher.
/**
* WP Postviews Hook
* @version 1.0
* @author Gabriel S Merovingi
*/
add_filter( 'mycred_setup_hooks', 'register_wp_postviews_hook_in_mycred' );
function register_wp_postviews_hook_in_mycred( $installed ) {
$installed['wp_postviews'] = array(
'title' => __( 'WP Postviews', 'textdomain' ),
@mycred
mycred / mycred-woo-payout-on-completed
Created July 23, 2018 06:08
By default myCRED will payout points for WooCommerce orders when an order has been marked as "paid". This means that no points will be paid out if a users pays using a manual gateway such as Check or Bank Transfers. This code snippet will force myCRED to payout when an order has been marked as "Completed" instead of paid.
/**
* Adjust myCRED Point Rewards
* Will move the points payout from when an order is "paid" to when
* an order is "completed".
* @version 1.0
*/
add_action( 'after_setup_theme', 'mycred_pro_adjust_woo_rewards', 110 );
function mycred_pro_adjust_woo_rewards() {
remove_action( 'woocommerce_payment_complete', 'mycred_woo_payout_rewards' );
@mycred
mycred / mycred-users-rank-progress-shortcode
Created July 23, 2018 06:19
myCRED Custom Shortcode: Rank Progress
<?php
// Get user's rank progress
function get_mycred_users_rank_progress( $user_id, $show_rank ) {
global $wpdb;
if ( ! function_exists( 'mycred' ) ) return '';
// Change rank data to displayed user when on a user's profile
if ( function_exists( 'bp_is_user' ) && bp_is_user() && empty( $user_id ) ) {
@mycred
mycred / limit-bp-group-creation
Created July 23, 2018 06:24
Will only allow users with more then 5000 myCRED points to create groups in BuddyPress.
/**
* Limit BP Group Creation
* Only users with x amount of points can create groups.
* @version 1.0
*/
add_filter( 'bp_user_can_create_groups', 'mycred_pro_limit_bp_group_creation' );
function mycred_pro_limit_bp_group_creation( $can ) {
if ( ! function_exists( 'mycred' ) ) return $can;
@mycred
mycred / change-post-author-on-purchase
Created July 23, 2018 06:28
Transfers ownership of a post that has been purchased via the myCRED Sell Content add-on to the buyer.
/**
* Change Post Ownership
* Changes the post author to the user who purchased the post using
* the myCRED Sell Content add-on.
* @requires myCRED 1.6 or higher!
* @version 1.0
*/
add_filter( 'mycred_add_finished', 'mycred_pro_change_post_author_on_sale', 10, 3 );
function mycred_pro_change_post_author_on_sale( $reply, $request, $mycred ) {
@mycred
mycred / exclude-subscribers-from-mycred
Created July 23, 2018 06:31
Excludes any user that does not have the "edit_post" capability from using myCRED.
/**
* Exclude Subscribers
* Excludes any user that does not have the "edit_posts" capability.
* On a default WordPress installation this will exclude all users with the
* "Subscriber" role.
* For more information on roles and capabilities please consult the
* WordPress codex: http://codex.wordpress.org/Roles_and_Capabilities
* @version 1.0
*/
add_filter( 'mycred_exclude_user', 'exclude_subscriber_from_mycred', 10, 2 );