Advertisement
designbymerovingi

weekly payout per role

Mar 13th, 2015
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. add_action( 'mycred_init', 'mycred_pro_monthly_payouts' );
  2. function mycred_pro_monthly_payouts() {
  3.  
  4.     if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return;
  5.  
  6.     $this_week = date( 'W' );
  7.     if ( get_option( 'mycred_weekly_payout', 0 ) != $this_week ) {
  8.  
  9.         // Grab all users for the set role
  10.         $users = get_users( array(
  11.             'role'   => 'subscriber', // The role
  12.             'fields' => array( 'ID' )
  13.         ) );
  14.  
  15.         // If users were found
  16.         if ( $users ) {
  17.  
  18.             $type = 'mycred_default';
  19.             $mycred = mycred( $type );
  20.  
  21.             // Loop though users
  22.             foreach ( $users as $user ) {
  23.  
  24.                 // Make sure user is not excluded
  25.                 if ( $mycred->exclude_user( $user->ID ) ) continue;
  26.  
  27.                 // Make sure users only get this once per month
  28.                 if ( $mycred->has_entry( 'weekly_payout', $this_week, $user->ID, '', $type ) ) continue;
  29.  
  30.                 // Payout
  31.                 $mycred->add_creds(
  32.                     'weekly_payout',
  33.                     $user->ID,
  34.                     10,
  35.                     'Weekly %_plural% payout',
  36.                     $this_week,
  37.                     '',
  38.                     $type
  39.                 );
  40.             }
  41.  
  42.         }
  43.  
  44.         // Grab all users for the set role
  45.         $users = get_users( array(
  46.             'role'   => 'author', // The role
  47.             'fields' => array( 'ID' )
  48.         ) );
  49.  
  50.         // If users were found
  51.         if ( $users ) {
  52.  
  53.             $type = 'mycred_default';
  54.             $mycred = mycred( $type );
  55.  
  56.             // Loop though users
  57.             foreach ( $users as $user ) {
  58.  
  59.                 // Make sure user is not excluded
  60.                 if ( $mycred->exclude_user( $user->ID ) ) continue;
  61.  
  62.                 // Make sure users only get this once per month
  63.                 if ( $mycred->has_entry( 'weekly_payout', $this_week, $user->ID, '', $type ) ) continue;
  64.  
  65.                 // Payout
  66.                 $mycred->add_creds(
  67.                     'weekly_payout',
  68.                     $user->ID,
  69.                     20,
  70.                     'Weekly %_plural% payout',
  71.                     $this_week,
  72.                     '',
  73.                     $type
  74.                 );
  75.             }
  76.  
  77.         }
  78.  
  79.         update_option( 'mycred_weekly_payout', $this_week );
  80.  
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement