Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
gabrielmerovingi / award-content-author-for-share
Created August 22, 2014 14:59
Awards the content author the same amount of points as the user who shares their content using the ShareThis plugin with myCRED.
add_filter( 'mycred_add', 'mycred_award_post_author_for_share', 90, 3 );
function mycred_award_post_author_for_share( $reply, $request, $mycred ) {
// Only applicable if points are being awarded for sharing
if ( $reply === false || $request['ref'] != 'share' ) return $reply;
// Prep
$user_id = absint( $request['user_id'] );
$post_id = absint( $request['ref_id'] );
$post = get_post( $post_id );
@gabrielmerovingi
gabrielmerovingi / set-for-sale-mycred
Last active August 29, 2015 14:07
This custom shortcode allows you to set any post type for sale in myCRED. Make sure you use this shortcode on a page that only you can access, select the post type to set for sale and if you want to use a custom setup instead of your Sell Content default setup, enter these details. Any field that is left empty will be populated by your default s…
add_shortcode( 'sell_all_posts', 'mycred_pro_sell_all_posts' );
function mycred_pro_sell_all_posts() {
if ( ! is_user_logged_in() || ! current_user_can( 'edit_users' ) )
return 'This shortcode is only available for admins.';
ob_start();
// Run
if ( isset( $_POST['token'] ) && wp_verify_nonce( $_POST['token'], 'mycred-sell-content-run' ) ) {
@gabrielmerovingi
gabrielmerovingi / set-for-sale-posts-per-cat
Created October 4, 2014 10:24
Set all posts for sale in myCRED based on category. If no category is selected, all posts will be set for sale. Note, this code only works with posts and no other point type.
add_shortcode( 'sell_posts_of_category', 'mycred_pro_sell_all_posts' );
function mycred_pro_sell_all_posts() {
if ( ! is_user_logged_in() || ! current_user_can( 'edit_users' ) )
return 'This shortcode is only available for admins.';
ob_start();
// Run
if ( isset( $_POST['token'] ) && wp_verify_nonce( $_POST['token'], 'mycred-sell-content-run' ) ) {
@gabrielmerovingi
gabrielmerovingi / monthly-mycred-payout
Created October 21, 2014 11:58
Award myCRED Points for all users of a specific role on the first of each month.
/**
* Monthly payouts
* On the first page load on the first day of each month
* award 10 points to all users with the role "Subscriber".
* @version 1.0
*/
add_action( 'mycred_init', 'mycred_pro_monthly_payouts' );
function mycred_pro_monthly_payouts() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return;
@gabrielmerovingi
gabrielmerovingi / mycred-balance-wp-super-cache
Created November 10, 2014 13:06
Show users myCRED balance with WP Super Cache. Based of the example given in the dynamic-cache-test.php given by the plugin. The example uses %mycredbalance% to indicate where the balance should be shown. If using the myCRED Balance widget, set this tag in the balance format template.
define( 'DYNAMIC_OUTPUT_BUFFER_TAG', '%mycredbalance%' ); // Change this to a secret placeholder tag
if ( DYNAMIC_OUTPUT_BUFFER_TAG != '' ) {
function dynamic_output_buffer_test( &$cachedata = 0 ) {
if ( defined( 'DYNAMIC_OB_TEXT' ) )
return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
if ( is_user_logged_in() ) {
ob_start();
@gabrielmerovingi
gabrielmerovingi / exclude-subscribers-from-mycred
Created November 26, 2014 15:40
Excludes any user that does not have the "edit_post" capability from using myCRED.
/**
* Exclude Subscribers
* Excludes any user that does not have the "edit_posts" capability.
* On a default WordPress installation this will exclude all users with the
* "Subscriber" role.
* For more information on roles and capabilities please consult the
* WordPress codex: http://codex.wordpress.org/Roles_and_Capabilities
* @version 1.0
*/
add_filter( 'mycred_exclude_user', 'exclude_subscriber_from_mycred', 10, 2 );
@gabrielmerovingi
gabrielmerovingi / transfer-minimum-requirement
Created December 1, 2014 11:12
Enforces a minimum 50 point transfer requirement when using the mycred_transfer shortcode.
/**
* Minimum Transfer Requirement
* Force users to transfer a minimum amount of points
* when using the mycred_transfer shortcode.
* @version 1.0
*/
add_action( 'mycred_transfer_ready', 'mycred_min_transfer_req', 10, 2 );
function mycred_min_transfer_req( $transaction_id, $post ) {
// Get amount
@gabrielmerovingi
gabrielmerovingi / generate-qr-code-link
Created December 3, 2014 14:23
Generates a QR code image using the "QR Code Generator" API for a given URL. Optional vendor ID can be appended under the "vendor" variable. The variable key can be changed via by passing the "ref_key" variable in $args.
@gabrielmerovingi
gabrielmerovingi / change-post-author-on-purchase
Created February 11, 2015 14:39
Transfers ownership of a post that has been purchased via the myCRED Sell Content add-on to the buyer.
/**
* Change Post Ownership
* Changes the post author to the user who purchased the post using
* the myCRED Sell Content add-on.
* @requires myCRED 1.6 or higher!
* @version 1.0
*/
add_filter( 'mycred_add_finished', 'mycred_pro_change_post_author_on_sale', 10, 3 );
function mycred_pro_change_post_author_on_sale( $reply, $request, $mycred ) {
@gabrielmerovingi
gabrielmerovingi / limit-bp-group-creation
Created February 11, 2015 16:33
Will only allow users with more then 5000 myCRED points to create groups in BuddyPress.
/**
* Limit BP Group Creation
* Only users with x amount of points can create groups.
* @version 1.0
*/
add_filter( 'bp_user_can_create_groups', 'mycred_pro_limit_bp_group_creation' );
function mycred_pro_limit_bp_group_creation( $can ) {
if ( ! function_exists( 'mycred' ) ) return $can;