Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author myCred

    (@designbymerovingi)

    Right now myCRED does not delete points for posts that gets deleted but you can add this though your themes functions.php file:

    add_action( 'transition_post_status', 'remove_points_for_deleted_items', 10, 3 );
    function remove_points_for_deleted_items( $new_status, $old_status, $post )
    {
    	// Load myCRED
    	$mycred = mycred_get_settings();
    
    	// Make sure we only deduct points if the user has been awarded points
    	if ( $mycred->has_entry( 'publishing_content', $post->ID, $post->post_author ) ) {
    		// User has received points so we deduct
    		$mycred->add_creds(
    			'deleted_post', // reference id
    			$post->post_author, // the user id
    			0-1, // amount, negative value means deduction
    			'Point deduction for deleted post' // Log entry
    		);
    	}
    }
    Thread Starter Víctor

    (@njusted)

    It works! Thank you ^^

    Thread Starter Víctor

    (@njusted)

    Sorry for reply the post, but now, when I edit a post, also remove points (the same points when delete post).

    Plugin Author myCred

    (@designbymerovingi)

    Sorry I see I forgot to include the delete check:

    add_action( 'transition_post_status', 'remove_points_for_deleted_items', 10, 3 );
    function remove_points_for_deleted_items( $new_status, $old_status, $post )
    {
    	// Make sure we only do this when a posts new status is 'trash' (moved to trash)
    	if ( $new_status != 'trash' ) return;
    	// Load myCRED
    	$mycred = mycred_get_settings();
    
    	// Make sure we only deduct points if the user has been awarded points
    	if ( $mycred->has_entry( 'publishing_content', $post->ID, $post->post_author ) ) {
    		// User has received points so we deduct
    		$mycred->add_creds(
    			'deleted_post', // reference id
    			$post->post_author, // the user id
    			0-1, // amount, negative value means deduction
    			'Point deduction for deleted post' // Log entry
    		);
    	}
    }
    Thread Starter Víctor

    (@njusted)

    Awesome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove points when entry is deleted’ is closed to new replies.