Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
gabrielmerovingi / WP YouTube Video EMbed Override
Created April 23, 2014 09:47
Override the default WordPress oEmbed for YouTube Videos to always use the myCRED Video Shortcode.
/**
* Override WP oEmbed
* @version 1.0
*/
add_filter( 'embed_oembed_html', 'mycred_override_video_shortcode', 999, 4 );
function mycred_override_video_shortcode( $original, $url, $attr, $post_ID ) {
// If myCRED is not enabled
if ( ! function_exists( 'mycred_render_shortcode_video' ) ) return $original;
// Get cache
@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 / buyCRED + WooCommerce
Created May 20, 2014 19:05
Inserts a buyCRED Button when a users order exceeds their current balance, allowing them to quickly buy more points in order to pay for the order. In this example, the user can buy the points using PayPal.
/**
* Insert buyCRED Button
* Inserts a buyCRED Button when a users order exceeds their current balance,
* allowing them to quickly buy more points in order to pay for the order.
* Required myCRED 1.4 or higher!
* @version 1.0
*/
add_action( 'after_setup_theme', 'mycred_load_woo_gateway_customization', 20 );
function mycred_load_woo_gateway_customization()
{
@gabrielmerovingi
gabrielmerovingi / Simple myCRED Promotion Modal
Last active September 1, 2015 00:02
Show users a pop-up modal when they reach a new rank (promoted) using myCRED.
/**
* Step 1. Catch Promotions
* @version 1.0
*/
add_action( 'mycred_user_got_promoted', 'mycred_pro_catch_promotions', 10, 2 );
function mycred_pro_catch_promotions( $user_id, $rank_id ) {
// Save a temporary marker for this user so on the next page load
// the popup modal is shown
update_user_meta( $user_id, 'show_promotion_box', $rank_id );
}
@gabrielmerovingi
gabrielmerovingi / myCRED Pay on Completed or Shipped Orders
Created June 4, 2014 13:39
By default, myCRED pays out profit shares of WooCommerce orders when the order has been paid. This is an example of how to move the payout process so it's payed out when the order has been marked as "Completed" or "Shipped". Requires the myCRED Gateways "Profit Sharing" value to be set to zero!
/**
* Pay Sale Profit on Completed or Shipped Orders
* @version 1.0
*/
add_action( 'woocommerce_order_status_completed', 'mycred_pro_pay_profit_from_sale' );
add_action( 'woocommerce_order_status_shipped', 'mycred_pro_pay_profit_from_sale' );
function mycred_pro_pay_profit_from_sale( $order_id ) {
// Get current user id
$cui = get_current_user_id();
@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 / mycred-custom-content
Last active July 20, 2019 04:20
Custom myCRED hook example where points are awarded / deducted for newly published posts, based solely on amounts set via a custom taxonomies description field.
/**
* Custom Hook: Points based on taxonomy
* Register the hook so myCRED can load it.
* @since 1.0
* @version 1.1
*/
add_action( 'mycred_setup_hooks', 'mycredpro_register_custom_taxonomy_hook' );
function mycredpro_register_custom_taxonomy_hook( $installed ) {
$installed['publishing_ct_content'] = array(
@gabrielmerovingi
gabrielmerovingi / mycred-ranged-leaderboard
Last active June 21, 2016 15:17
Creates a custom widget for Wordpress that generates a leaderboard based for myCRED point gains between two dates.
/**
* Custom myCRED Widget: Ranged Leaderboard
* Shows a leaderboard of users sorted by their point gains
* between two timestamps. Supports multiple point types.
* @author Gabriel S Merovingi
* @version 2.0
*/
add_action( 'widgets_init', 'mycred_register_ranged_leaderboard' );
function mycred_register_ranged_leaderboard() {
@gabrielmerovingi
gabrielmerovingi / mycred-monthly-leaderboard
Last active December 15, 2016 13:50
A quick example of how to create a custom WordPress widget that will show the current months leaderboard based on myCRED Points. Requires myCRED 1.4 or higher.
/**
* Custom myCRED Widget: This months leaderboard
* This widget will show this months 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 plugin.
* @author Gabriel S Merovingi
* @version 1.1.1
*/
add_action( 'mycred_widgets_init', 'mycred_load_this_months_leaderboard_widget' );