Skip to content

Instantly share code, notes, and snippets.

/**
* 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 August 29, 2015 13:55
Simple WordPress shortcode that allows users to convert their myCRED Points into MarketPress Coupons. Version 1.1 requires myCRED 1.4 or higher.
/**
* 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 January 30, 2014 20:14
This custom hook allows you to award or deduct points from your users who checkin or create new places using the BP Checkin plugin.
/**
* 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 August 29, 2015 13:56
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.
/**
* 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 February 14, 2014 12:40
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!
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 August 29, 2015 13:56
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.
/**
* 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 March 13, 2014 14:45
This is a simple example where we unpublish a users posts if their account goes minus 20 points.
/**
* 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 / bbPress Forum Awards
Created March 18, 2014 09:22
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.
/**
* 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 March 28, 2014 14:27
Example of adding custom details 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';
add_filter( 'mycred_add', 'enforce_mycred_form_limit', 10, 3 );
function enforce_mycred_form_limit( $reply, $request, $mycred ) {
// First we only want to target form submissions
if ( $request['ref'] != 'contact_form_submission' ) )
return $reply;
// If already declined by someone, horour it
if ( $reply !== true ) return $reply;
// Limit