Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
gabrielmerovingi / display-mycred-affiliate-ids
Created July 22, 2014 08:49
Basic examples of inserting a users affiliate ID in their WordPress or bbPress profiles.
/**
* Show Affiliate ID
* Inserts the displayed users affiliate ID
* in their bbPress profile.
* @version 1.0
*/
add_action( 'bbp_template_after_user_profile', 'mycred_pro_show_affiliate_id_in_bbp_profile' );
function mycred_pro_show_affiliate_id_in_bbp_profile() {
$user_id = bbp_get_displayed_user_id();
$affiliate_link = get_user_meta( $user_id, 'mycred_affiliate_link', true );
@gabrielmerovingi
gabrielmerovingi / adjust-mycred-inline-editor
Created July 28, 2014 13:11
Example of how to adjust the inline editor for myCRED.
add_filter( 'mycred_admin_inline_editor', 'mycred_pro_adjust_inline_editor' );
function mycred_pro_adjust_inline_editor() {
$options = array(
'%plural% for doing something',
'adjustments for something else',
'%plural% for a third thing'
);
ob_start(); ?>
@gabrielmerovingi
gabrielmerovingi / total-points-functions
Created August 5, 2014 09:12
Two small code snippets to show the total number of points currently in circulation on your website. Use the first code snippet if you want to show just one point type and the second snippet if you want to add up all point types into one.
/**
* Get Total Points on Site
* Will add up all your users current balances for a given
* myCRED point type.
* @version 1.0
*/
function mycred_pro_total_points_on_my_site( $type = 'mycred_default' ) {
global $wpdb;
$type = sanitize_text_field( $type );
@gabrielmerovingi
gabrielmerovingi / change-role-based-on-balance
Last active July 26, 2017 11:20
Change a users WordPress role based on their current myCRED balance.
/**
* Promote Based on Balance
* Changes a users role based on their myCRED balance.
* @version 1.0.4
*/
add_filter( 'mycred_add_finished', 'check_for_role_change', 99, 3 );
function check_for_role_change( $reply, $request, $mycred ) {
// Make sure that if any other filter has declined this we also decline
if ( $reply === false ) return $reply;
@gabrielmerovingi
gabrielmerovingi / mycred_conditional_link
Created August 19, 2014 08:31
This custom WordPress shortcodes works exactly like the mycred_link shortcode with the added feature of setting an optional minimum balance requirement for the link to show. Note that links will not be shown for visitors.
@gabrielmerovingi
gabrielmerovingi / mycred_max_link
Created August 19, 2014 09:12
Custom WordPress shortcode that allows you to enforce a maximum number of clicks a certain URL should award points. Once this max has been reached, the link is no longer shown.
@gabrielmerovingi
gabrielmerovingi / mycred-comment-popularity-hook
Created August 21, 2014 09:24
Custom hook that allows you to reward your comment authors for getting their comments voted up or down by fellow member using the Comment Popularity plugin. Simply copy the code and paste it into your theme's functions.php file and you can access the new hook on the myCRED > Hooks page. Supports multiple point types and requires myCRED 1.4 or hi…
/**
* Register Custom Hook
* Comment Popularity
* @see https://github.com/humanmade/comment-popularity
*/
add_filter( 'mycred_setup_hooks', 'mycred_pro_register_comment_pop_hook' );
function mycred_pro_register_comment_pop_hook( $installed ) {
$installed['comment_pop'] = array(
'title' => __( 'Comment Popularity', 'textdomain' ),
@gabrielmerovingi
gabrielmerovingi / class.Wsi_Mycreed.php
Last active August 29, 2015 14:05 — forked from timersys/class.Wsi_Mycreed.php
Added support for multiple point types.
/**
* MyCred Hook
* @since v2
* @version 1.1
*/
class Wsi_MyCreed extends myCRED_Hook {
/**
* Construct
*/
@gabrielmerovingi
gabrielmerovingi / award-content-author-for-share
Created August 22, 2014 14:59
Awards the content author the same amount of points as the user who shares their content using the ShareThis plugin with myCRED.
add_filter( 'mycred_add', 'mycred_award_post_author_for_share', 90, 3 );
function mycred_award_post_author_for_share( $reply, $request, $mycred ) {
// Only applicable if points are being awarded for sharing
if ( $reply === false || $request['ref'] != 'share' ) return $reply;
// Prep
$user_id = absint( $request['user_id'] );
$post_id = absint( $request['ref_id'] );
$post = get_post( $post_id );
@gabrielmerovingi
gabrielmerovingi / mycred-bulk-create-coupons
Created September 12, 2014 10:42
This custom WordPress shortcode can be used for bulk creation of myCRED Coupons. Make sure you use this shortcode in the admin area or on a protected page only available admins.
add_shortcode( 'mycred_create_bulk_coupons', 'mycred_render_bulk_coupon_creation' );
function mycred_render_bulk_coupon_creation() {
if ( ! current_user_can( 'manage_options' ) ) return 'You do not create coupons.';
if ( ! function_exists( 'mycred_create_new_coupon' ) ) return 'The Coupon add-on is not enabled!';
if ( isset( $_POST['mycred_coupon_bulk'] ) && isset( $_POST['cc-token'] ) && wp_verify_nonce( $_POST['cc-token'], 'mycred-coupon-bulk-create' ) ) {
$number = $_POST['mycred_coupon_bulk']['number'];
$value = $_POST['mycred_coupon_bulk']['value'];