Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'mycred_init', 'mycred_pro_monthly_payouts' );
- function mycred_pro_monthly_payouts() {
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return;
- $this_week = date( 'W' );
- if ( get_option( 'mycred_weekly_payout', 0 ) != $this_week ) {
- // Grab all users for the set role
- $users = get_users( array(
- 'role' => 'subscriber', // The role
- 'fields' => array( 'ID' )
- ) );
- // If users were found
- if ( $users ) {
- $type = 'mycred_default';
- $mycred = mycred( $type );
- // Loop though users
- foreach ( $users as $user ) {
- // Make sure user is not excluded
- if ( $mycred->exclude_user( $user->ID ) ) continue;
- // Make sure users only get this once per month
- if ( $mycred->has_entry( 'weekly_payout', $this_week, $user->ID, '', $type ) ) continue;
- // Payout
- $mycred->add_creds(
- 'weekly_payout',
- $user->ID,
- 10,
- 'Weekly %_plural% payout',
- $this_week,
- '',
- $type
- );
- }
- }
- // Grab all users for the set role
- $users = get_users( array(
- 'role' => 'author', // The role
- 'fields' => array( 'ID' )
- ) );
- // If users were found
- if ( $users ) {
- $type = 'mycred_default';
- $mycred = mycred( $type );
- // Loop though users
- foreach ( $users as $user ) {
- // Make sure user is not excluded
- if ( $mycred->exclude_user( $user->ID ) ) continue;
- // Make sure users only get this once per month
- if ( $mycred->has_entry( 'weekly_payout', $this_week, $user->ID, '', $type ) ) continue;
- // Payout
- $mycred->add_creds(
- 'weekly_payout',
- $user->ID,
- 20,
- 'Weekly %_plural% payout',
- $this_week,
- '',
- $type
- );
- }
- }
- update_option( 'mycred_weekly_payout', $this_week );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement