Skip to content

Instantly share code, notes, and snippets.

Avatar

Gabriel Merovingi gabrielmerovingi

View GitHub Profile
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 / 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
@gabrielmerovingi
gabrielmerovingi / Unpublish posts for negative balances
Created Mar 13, 2014
This is a simple example where we unpublish a users posts if their account goes minus 20 points.
View Unpublish posts for negative balances
/**
* Unpublish users Posts
* If a user reaches or exceeds the minimum balance
* we unpublish all their posts.
* @version 1.0
*/
add_filter( 'mycred_add', 'mycred_unpublish_posts_on_minus', 999, 3 );
function mycred_unpublish_posts_on_minus( $reply, $request, $mycred ) {
if ( $reply === false ) return;
@gabrielmerovingi
gabrielmerovingi / Max Lottery Entries
Last active Aug 29, 2015
A simple example of how to adjust the myCRED Lottery add-on to add an option to set a maximum lottery entries before the lottery is closed.
View Max Lottery Entries
/**
* Step 1 - Add new ticket preference
* In this example we will insert this under "Participation" section
* of the lottery edit screen.
* @version 1.0
*/
add_action( 'mycred_edit_lotto_participation', 'add_max_lottery_entries_settings' );
function add_max_lottery_entries_settings( $lottery ) {
$tickets = get_post_meta( $lottery->id, '_tickets', true ); ?>
@gabrielmerovingi
gabrielmerovingi / bbPress Forum Awards
Created Mar 18, 2014
A very basic example of using the mycred_send shortcode to allow an administrator of a bbPress forum to send points to the topic author. In this example, we send points as a thank you for helping in the support forum or points for reporting bugs.
View bbPress Forum Awards
/**
* bbPress Give Points
* Allows admins to give points to topic authors.
* @version 1.0
*/
add_action( 'bbp_theme_after_reply_content', 'mycred_pro_insert_forum_buttons' );
function mycred_pro_insert_forum_buttons() {
// Get Reply Author ID
$reply_author_id = bbp_get_reply_author_id( bbp_get_reply_id() );
@gabrielmerovingi
gabrielmerovingi / Add Marker to buyCRED Purchases
Created Mar 28, 2014
Example of adding custom details to buyCRED purchases.
View Add Marker to buyCRED Purchases
/**
* Step 1 - Create custom Shortcode
* Creates a custom buyCRED shortcode that includes
* the marker attribute that is passed on to the gateway.
* @version 1.0
*/
add_shortcode( 'mycred_custom_buy', 'mycred_render_custom_buy_shortcode' );
function mycred_render_custom_buy_shortcode( $atts, $title = 'Buy Points' ) {
if ( ! function_exists( 'mycred' ) ) return 'myCRED is not installed';