Skip to content

Instantly share code, notes, and snippets.


Gabriel Merovingi gabrielmerovingi

View GitHub Profile
gabrielmerovingi / mycred-publish-posttype-hook
Last active Mar 14, 2021
This custom myCRED hook allows you to award points for users publishing any post type on your website AND adds the option for you to award badges based on publishing specific post types.
View mycred-publish-posttype-hook
* Register Custom myCRED Hooks
* @since 1.0
* @version 1.0
add_filter( 'mycred_setup_hooks', 'mycred_pro_register_publishposttype_hook' );
function mycred_pro_register_publishposttype_hook( $installed ) {
$installed['publish_posttypes'] = array(
'title' => 'Publishing Post Types',
gabrielmerovingi / enforce-max-mycred-balance
Last active Jan 28, 2021
Example where we enforce a maximum balance of 1000 points in myCRED. If a user is about to get points that exceeds this limit, we decline the transaction. Goes into your custom plugin or child theme's functions.php file.
View enforce-max-mycred-balance
* Enforce Maximum
* Make sure users can not earn more than 1000 points.
* @version 1.0
function mycred_enforce_max_balance( $run, $request, $mycred ) {
extract( $request );
// The maximum balance a user can have
gabrielmerovingi / mycred-history-woo-my-account
Created Oct 2, 2017
myCRED history in WooCommerce "My Account" with pagination.
View mycred-history-woo-my-account
class My_Custom_My_Account_Endpoint {
* Custom endpoint name.
* @var string
public static $endpoint = 'my-custom-endpoint';
gabrielmerovingi / mycred-wpulike-per-type
Last active Nov 29, 2020
When getting points for liking a content, change the reference to identify the post type so we can create badges for each post type that gets liked instead of just one for all likes.
View mycred-wpulike-per-type
* Adjust WP ULike Reference
* When getting points for liking a content, change the reference
* to identify the post type so we can create badges for each post type
* that gets liked instead of just one for all likes.
* @version 1.0
add_filter( 'mycred_run_this', 'mycred_wpulike_per_cpt', 10, 3 );
function mycred_wpulike_per_cpt( $run_this, $mycred ) {
gabrielmerovingi / youtube-subscribe-unsubscribe
Last active Nov 7, 2020
Award points for users who subscribe or unsubscribe from your YouTube Chanel using myCRED.
View youtube-subscribe-unsubscribe
* Insert YouTube Subscription Listening Script
add_action( 'wp_head', 'mycred_insert_youtube_script' );
function mycred_insert_youtube_script() {
if ( ! is_user_logged_in() ) return;
$token = wp_create_nonce( 'mycred-youtube-sub' );
View customize-transfers-in-15
* Example 1: Transfer Messages
* Step 1 : Insert Message Field
* @version 1.0
add_action( 'mycred_transfer_form_to', 'mycred_pro_transfer_message_field' );
function mycred_pro_transfer_message_field() {
echo '<label>Message</label><input type="text" name="transfer-message" id="mycred-transfer-message" value="" placeholder="Optional message to recipient" />';
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 / mycred_max_link
Created Aug 19, 2014
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.
View mycred_max_link
gabrielmerovingi / mycred-link-if-user-has-badge
Last active Sep 10, 2020
This custom shortcode can be used to display myCRED Links which grants points to a user only if the current user has a particular badge. Requires the badge_id="" attribute to be used and contain the Badge ID to check for.
View mycred-link-if-user-has-badge
gabrielmerovingi / mycred-take-shortcode
Last active Sep 10, 2020
Use this custom WordPress shortcode to deduct points from your users when they press a button.
View mycred-take-shortcode
* Shortcode: Take Points
* This custom shortcode allows you to take points from your users when they
* click on the button this shortcode generates. Supports optional confirmation message.
* @version 1.0.2
add_shortcode( 'mycred_take', 'mycred_pro_render_take_shortcode' );
function mycred_pro_render_take_shortcode( $atts, $label = 'Give Away' ) {
extract( shortcode_atts( array(