Created
March 13, 2014 14:45
-
-
Save gabrielmerovingi/9529817 to your computer and use it in GitHub Desktop.
This is a simple example where we unpublish a users posts if their account goes minus 20 points.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
// Get users current balance | |
$current_balance = $mycred->get_users_cred( $request['user_id'], $request['type'] ); | |
// Max negative balance | |
$max = -20; | |
// Check balance | |
if ( $current_balance <= $max ) { | |
// User has reached the max, unpublish all their posts | |
global $wpdb; | |
// Change ALL posts to pending for this user. | |
$wpdb->query( $wpdb->prepare( " | |
UPDATE {$wpdb->posts} | |
SET post_status = %s | |
WHERE post_author = %d | |
AND post_status = %s;". 'pending', $request['user_id'], 'publish' ) ); | |
} | |
// Always return a reply | |
return $reply; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment