Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
gabrielmerovingi / Buy Disk Space Example
Last active August 29, 2015 13:57
Custom code example on how to sell disk space updates for Multisites using WooCommerce virtual products and myCRED as a gateway. http://wordpress.org/support/topic/how-to-sell-site-upload-space
add_action( 'mycred_paid_for_woo', 'mycred_apply_purchased_disk_space', 10, 2 );
function mycred_apply_purchased_disk_space( $order, $cui ) {
if ( ! function_exists( 'get_site_option' ) ) return;
$space_bought = 0;
// Loop though all items in order to see if we bought space
$items = $order->get_items();
foreach ( $items as $item ) {
// Check for the custom field we set with the amount
@gabrielmerovingi
gabrielmerovingi / Restrict bbPress Forum Points
Created April 8, 2014 09:08
Place this code snippet in your themes functions.php file to restrict myCRED from giving points for forum actions.
/**
* Restrict bbPress Forum Points
* If a forum has the custom field "NO_MYCRED_POINTS" set to "yes"
* no points are awarded for any action taken in the forum.
* @version 1.0
*/
add_filter( 'mycred_add', 'mycred_disable_bbp_forum_points', 98, 3 );
function mycred_disable_bbp_forum_points( $reply, $request, $mycred ) {
// If already declined or bbPress is not installed, bail.
if ( $reply === false || ! function_exists( 'bbp_get_topic_forum_id' ) )
@gabrielmerovingi
gabrielmerovingi / myCRED Log Example 1
Last active August 29, 2015 14:01
Example of how the myCRED_Query_Log class can be used on a custom admin screen in WordPress.
function custom_mycred_log_admin_screen() {
$args = array(
'number' => 10
);
if ( isset( $_GET['user_id'] ) && ! empty( $_GET['user_id'] ) )
$args['user_id'] = $_GET['user_id'];
if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) )
@gabrielmerovingi
gabrielmerovingi / myCRED Auto Generate Coupon Code
Created June 12, 2014 10:32
This is a simple example of how one could use wp_generate_password to generate coupon codes when creating a new myCRED Coupon.
add_filter( 'default_title', 'mycred_pro_generate_coupon_code', 10, 2 );
function mycred_pro_generate_coupon_code( $post_title, $post ) {
if ( ! isset( $post->post_type ) || $post->post_type != 'mycred_coupon' )
return $post_title;
return wp_generate_password( 12, false, false );
}
@gabrielmerovingi
gabrielmerovingi / mycred-content-sales
Last active August 29, 2015 14:02
Basic WordPress shortcode example to display all content purchases made via the Sell Content add-on for myCRED.
add_shortcode( 'mycred_content_sales', 'mycred_render_content_sales_shortcode' );
function mycred_render_content_sales_shortcode( $attr ) {
global $wpdb;
$mycred_log = $wpdb->prefix . 'myCRED_log';
$sales = $wpdb->get_results( "
SELECT DISTINCT ref_id AS post_id, COUNT( * ) AS sales
FROM {$mycred_log}
@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 / 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 / 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
*/