Skip to content

Instantly share code, notes, and snippets.

Avatar

Gabriel Merovingi gabrielmerovingi

View GitHub Profile
@gabrielmerovingi
gabrielmerovingi / myCRED: Weekly Leaderboard Example
Last active Jun 21, 2016
Custom WordPress widget to show this weeks leaderboard for myCRED points.
View myCRED: Weekly Leaderboard Example
/**
* Custom myCRED Widget: This weeks leaderboard
* This widget will show this weeks leaderbaord with the option to set
* a title, the number of users to include and if it should be visible for
* non-members.
* @install Paste into your theme or child-themes functions.php file or custom plguin.
* @author Gabriel S Merovingi
* @version 1.3
*/
add_action( 'mycred_widgets_init', 'mycred_load_this_weeks_leaderboard_widget' );
@gabrielmerovingi
gabrielmerovingi / mycred-woo-coupon
Last active Jun 28, 2020
This custom shortcode allows your users to convert their myCRED points into a WooCommerce coupon, in order to give themselves a discount or partial payment on their order. In order for this to work, you need to set an exchange rate between points and your store currency and select. Requires myCRED 1.6+ and WooCommerce 2.4+
View mycred-woo-coupon
/**
* Convert myCRED Points into WooCommerce Coupon
* Requires myCRED 1.4 or higher!
* @version 1.3.1
*/
add_shortcode( 'mycred_to_woo_coupon', 'mycred_pro_render_points_to_coupon' );
function mycred_pro_render_points_to_coupon( $atts, $content = NULL ) {
// Users must be logged in
if ( ! is_user_logged_in() )
View Apply Default OG:Image for Jetpack
/**
* Apply Default OG:Image for Jetpack
* When looking for images in posts that falls under "is_singular"
* and Jetpack does not find an image, we apply our own default image
* instead of the blank WordPress thumb.
* @version 1.0
*/
add_filter( 'jetpack_images_get_images', 'apply_default_image_for_jetpack_seo', 10, 3 );
function apply_default_image_for_jetpack_seo( $media, $post_id, $args ) {
// Jetpack_PostImages::get_images did not find anything
@gabrielmerovingi
gabrielmerovingi / myCRED to MarketPress Coupon
Last active Aug 29, 2015
Simple WordPress shortcode that allows users to convert their myCRED Points into MarketPress Coupons. Version 1.1 requires myCRED 1.4 or higher.
View myCRED to MarketPress Coupon
/**
* Convert myCRED Points into MarketPress Coupon
* @version 1.1
*/
add_shortcode( 'mycred_to_mpress_coupon', 'mycred_pro_render_points_to_marketpress_coupon' );
function mycred_pro_render_points_to_marketpress_coupon( $atts, $content = NULL ) {
// Users must be logged in
if ( ! is_user_logged_in() )
return 'You must be logged in to generate store coupons.';
@gabrielmerovingi
gabrielmerovingi / BP Checkin Hook for myCRED
Created Jan 30, 2014
This custom hook allows you to award or deduct points from your users who checkin or create new places using the BP Checkin plugin.
View BP Checkin Hook for myCRED
/**
* BP Checkins
* @requires myCRED 1.3 +
* @since 0.1
* @version 1.0
*/
if ( class_exists( 'myCRED_Hook' ) && ! class_exists( 'myCRED_BP_Checkins' ) ) {
class myCRED_BP_Checkins extends myCRED_Hook {
/**
@gabrielmerovingi
gabrielmerovingi / WP Shortcode: myCRED Sell Content Limit
Last active Aug 29, 2015
This is a shortcode example for enforcing a limit on the number of times users can buy posts that has been set for sale via the myCRED Sell Content add-on.
View WP Shortcode: myCRED Sell Content Limit
/**
* Custom Shortcode: Limited Content Purchases
* Example WordPress shortcode to impose a maximum number of times
* a user can purchase a post in WordPress using the myCRED Sell Content add-on.
* Requires myCRED 1.4 or higher!
* @version 1.1
*/
add_shortcode( 'mycred_sell_this_limited', 'mycred_render_sell_this_limited' );
function mycred_render_sell_this_limited( $atts, $content = NULL ) {
// First make sure we do not get an error if myCRED gets deactivated
@gabrielmerovingi
gabrielmerovingi / Max Content Purchases
Last active May 30, 2018
This code snippet will limit the number of times a post can be purchased. Once a post reaches the limit, the content will no longer be set for sale but be visible.
View Max Content Purchases
/**
* Disable Content Sales
* Disabled content sales after 3 purchases.
* @version 1.0
*/
add_filter( 'mycred_add', 'mycred_limit_content_sales', 10, 3 );
function mycred_limit_content_sales( $reply, $request, $mycred ) {
// Only apply this to content purchases
if ( $reply === false || $request['ref'] != 'buy_content' ) return $reply;
@gabrielmerovingi
gabrielmerovingi / Custom WP Shortcode: Lottery Winners
Created Feb 13, 2014
Updated version of the mycred_lottery_results shortcode with added option to use user related template tags for each row.
View Custom WP Shortcode: Lottery Winners
/**
* [mycred_lottery_results] Shortcode Render
* @since 1.0
* @version 1.2
*/
if ( ! function_exists( 'mycred_lotto_render_draws' ) ) :
function mycred_lotto_render_draws( $atts, $content = NULL )
{
extract( shortcode_atts( array(
'id' => NULL,
@gabrielmerovingi
gabrielmerovingi / myCRED: Max. Comment Points
Created Feb 14, 2014
A short example of how to enforce a maximum number of times a user can receive points for making a comment. Note that we count the number of times points have been awarded and not the amount of points user have received!
View myCRED: Max. Comment Points
add_filter( 'mycred_add', 'mycred_absolute_limit_for_comments', 20, 3 );
function mycred_absolute_limit_for_comments( $reply, $request, $mycred ) {
// Ignore declined instances or instances that are not comment related
if ( $reply === false || $request['ref'] != 'approved_comment' ) return $reply;
// The user ID
$user_id = absint( $request['user_id'] );
// Count the number of times this user has received points for comments.
$total = mycred_count_ref_instances( 'approved_comment', $user_id );
@gabrielmerovingi
gabrielmerovingi / Award Points based on Tags
Last active Aug 29, 2015
This script will award myCRED Points when a "Post" is published in WordPress. To define which tags gives points, the amount must be saved in the tags description field.
View Award Points based on Tags
/**
* Award myCRED Points based on Tags
* This script will award points when a post is published based on
* what tags a post has. The amount is defined in the post tag description field.
* Requires myCRED 1.4 or higher!
* @version 1.1
*/
add_action( 'transition_post_status', 'mycred_pro_points_by_post_tags', 10, 3 );
function mycred_pro_points_by_post_tags( $new_status, $old_status, $post ) {
// Make sure myCRED is installed