Version Description
Bug fixes release.
Download this release
Release Info
Developer | wpexpertsio |
Plugin | myCRED |
Version | 2.0.1 |
Comparing to | |
See all releases |
Code changes from version 2.0 to 2.0.1
- addons/banking/assets/js/manage-schedules.js +0 -180
- addons/banking/services/mycred-bank-service-interest.php +0 -344
- addons/banking/services/mycred-bank-service-payouts.php +0 -308
- addons/banking/services/mycred-service-interest.php +0 -691
- addons/banking/services/mycred-service-payouts.php +0 -1002
- mycred.php +6 -6
- readme.txt +7 -1
addons/banking/assets/js/manage-schedules.js
DELETED
@@ -1,180 +0,0 @@
|
|
1 |
-
jQuery(function($) {
|
2 |
-
|
3 |
-
var RecurringSchedule = $( '#manage-recurring-schedule' );
|
4 |
-
var currentBankService = '';
|
5 |
-
var wWidth = $(window).width();
|
6 |
-
var dWidth = wWidth * 0.75;
|
7 |
-
|
8 |
-
function check_form_for_empty_fields() {
|
9 |
-
|
10 |
-
var emptyfields = 0;
|
11 |
-
|
12 |
-
$( '#manage-recurring-schedule-form input.cant-be-empty' ).each(function(index){
|
13 |
-
|
14 |
-
var fieldvalue = $(this).val();
|
15 |
-
if ( fieldvalue.length == 0 ) {
|
16 |
-
$(this).parent().addClass( 'has-error' );
|
17 |
-
emptyfields++;
|
18 |
-
}
|
19 |
-
else
|
20 |
-
$(this).parent().removeClass( 'has-error' );
|
21 |
-
|
22 |
-
});
|
23 |
-
|
24 |
-
if ( emptyfields > 0 )
|
25 |
-
return false;
|
26 |
-
|
27 |
-
else return true;
|
28 |
-
|
29 |
-
};
|
30 |
-
|
31 |
-
$(document).ready(function(){
|
32 |
-
|
33 |
-
if ( dWidth < 250 )
|
34 |
-
dWidth = wWidth;
|
35 |
-
|
36 |
-
if ( dWidth > 960 )
|
37 |
-
dWidth = 960;
|
38 |
-
|
39 |
-
/**
|
40 |
-
* Setup Schedule Modal
|
41 |
-
*/
|
42 |
-
RecurringSchedule.dialog({
|
43 |
-
dialogClass : 'mycred-update-balance mycred-metabox',
|
44 |
-
draggable : true,
|
45 |
-
autoOpen : false,
|
46 |
-
title : Banking.new,
|
47 |
-
closeText : Banking.close,
|
48 |
-
modal : true,
|
49 |
-
width : dWidth,
|
50 |
-
height : 'auto',
|
51 |
-
resizable : false,
|
52 |
-
position : { my: "center", at: "top+25%", of: window },
|
53 |
-
show : {
|
54 |
-
effect : 'fadeIn',
|
55 |
-
duration : 250
|
56 |
-
},
|
57 |
-
hide : {
|
58 |
-
effect : 'fadeOut',
|
59 |
-
duration : 250
|
60 |
-
}
|
61 |
-
});
|
62 |
-
|
63 |
-
RecurringSchedule.on( "dialogclose", function( event, ui ) {
|
64 |
-
|
65 |
-
$( '#manage-recurring-schedule-form' ).empty();
|
66 |
-
$( '#mycred-processing' ).show();
|
67 |
-
|
68 |
-
} );
|
69 |
-
|
70 |
-
// Schedule
|
71 |
-
$( '#add-new-schedule' ).click(function(e){
|
72 |
-
|
73 |
-
e.preventDefault();
|
74 |
-
|
75 |
-
$(this).blur();
|
76 |
-
|
77 |
-
RecurringSchedule.dialog({ title : Banking.new });
|
78 |
-
RecurringSchedule.dialog( 'open' );
|
79 |
-
$( '#manage-recurring-schedule-form' ).submit();
|
80 |
-
|
81 |
-
});
|
82 |
-
|
83 |
-
// Form submissions
|
84 |
-
$( '#manage-recurring-schedule-form' ).on( 'submit', function(e){
|
85 |
-
|
86 |
-
e.preventDefault();
|
87 |
-
|
88 |
-
if ( check_form_for_empty_fields() === false ) {
|
89 |
-
alert( Banking.emptyfields );
|
90 |
-
return false;
|
91 |
-
}
|
92 |
-
|
93 |
-
$( '#mycred-processing' ).show();
|
94 |
-
|
95 |
-
var thisform = $(this);
|
96 |
-
|
97 |
-
$.ajax({
|
98 |
-
type : 'POST',
|
99 |
-
data : {
|
100 |
-
action : 'run-mycred-bank-service',
|
101 |
-
_token : Banking.token,
|
102 |
-
service : 'payouts',
|
103 |
-
form : thisform.serialize()
|
104 |
-
},
|
105 |
-
dataType : 'JSON',
|
106 |
-
url : Banking.ajaxurl,
|
107 |
-
beforeSend : function(){
|
108 |
-
thisform.slideUp();
|
109 |
-
},
|
110 |
-
success : function( response ) {
|
111 |
-
|
112 |
-
if ( response.success === undefined ) {
|
113 |
-
location.reload();
|
114 |
-
return false;
|
115 |
-
}
|
116 |
-
|
117 |
-
$( '#mycred-processing' ).hide();
|
118 |
-
|
119 |
-
thisform.empty().append( response.data.form ).slideDown();
|
120 |
-
|
121 |
-
if ( response.data.table !== false ) {
|
122 |
-
|
123 |
-
var scheduletable = $( '#recurring-schedule-body tr' );
|
124 |
-
if ( scheduletable.length == 1 )
|
125 |
-
$( '#no-banking-schedules' ).hide();
|
126 |
-
|
127 |
-
$( '#recurring-schedule-body #no-banking-schedules' ).before( response.data.table );
|
128 |
-
|
129 |
-
}
|
130 |
-
else {
|
131 |
-
var scheduletable = $( '#recurring-schedule-body tr' );
|
132 |
-
if ( scheduletable.length == 1 )
|
133 |
-
$( '#no-banking-schedules' ).show();
|
134 |
-
}
|
135 |
-
|
136 |
-
}
|
137 |
-
});
|
138 |
-
|
139 |
-
});
|
140 |
-
|
141 |
-
// View Schedule
|
142 |
-
$( '#recurring-schedule-body' ).on( 'click', 'a.view-recurring-schedule', function(e){
|
143 |
-
|
144 |
-
e.preventDefault();
|
145 |
-
|
146 |
-
$(this).blur();
|
147 |
-
|
148 |
-
var scheduleid = $(this).data( 'id' );
|
149 |
-
$( '#manage-recurring-schedule-form' ).append( '<input type="hidden" name="schedule_id" value="' + scheduleid + '" />' );
|
150 |
-
|
151 |
-
RecurringSchedule.dialog({ title : $(this).data( 'title' ) });
|
152 |
-
RecurringSchedule.dialog( 'open' );
|
153 |
-
$( '#manage-recurring-schedule-form' ).submit();
|
154 |
-
|
155 |
-
});
|
156 |
-
|
157 |
-
// Delete Schedule
|
158 |
-
$( '#recurring-schedule-body' ).on( 'click', 'a.delete-recurring-schedule', function(e){
|
159 |
-
|
160 |
-
e.preventDefault();
|
161 |
-
|
162 |
-
$(this).blur();
|
163 |
-
|
164 |
-
var scheduleid = $(this).data( 'id' );
|
165 |
-
$( '#manage-recurring-schedule-form' ).append( '<input type="hidden" name="remove_token" value="' + scheduleid + '" />' );
|
166 |
-
|
167 |
-
if ( confirm( Banking.confirmremoval ) ) {
|
168 |
-
RecurringSchedule.dialog({ title : $(this).data( 'title' ) });
|
169 |
-
RecurringSchedule.dialog( 'open' );
|
170 |
-
$( '#manage-recurring-schedule-form' ).submit();
|
171 |
-
}
|
172 |
-
else {
|
173 |
-
$( '#manage-recurring-schedule-form' ).empty();
|
174 |
-
}
|
175 |
-
|
176 |
-
});
|
177 |
-
|
178 |
-
});
|
179 |
-
|
180 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addons/banking/services/mycred-bank-service-interest.php
DELETED
@@ -1,344 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* myCRED Bank Service - Interest
|
4 |
-
* @since 1.2
|
5 |
-
* @version 1.1
|
6 |
-
*/
|
7 |
-
if ( ! defined( 'myCRED_VERSION' ) ) exit;
|
8 |
-
|
9 |
-
if ( ! class_exists( 'myCRED_Banking_Service_Interest' ) ) {
|
10 |
-
class myCRED_Banking_Service_Interest extends myCRED_Service {
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Construct
|
14 |
-
*/
|
15 |
-
function __construct( $service_prefs ) {
|
16 |
-
parent::__construct( array(
|
17 |
-
'id' => 'interest',
|
18 |
-
'defaults' => array(
|
19 |
-
'rate' => array(
|
20 |
-
'amount' => 2,
|
21 |
-
'period' => 1,
|
22 |
-
'pay_out' => 'monthly'
|
23 |
-
),
|
24 |
-
'last_payout' => '',
|
25 |
-
'log' => __( '%plural% interest rate payment', 'mycred' ),
|
26 |
-
'min_balance' => 1,
|
27 |
-
'run_time' => 60
|
28 |
-
)
|
29 |
-
), $service_prefs );
|
30 |
-
}
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Run
|
34 |
-
* @since 1.2
|
35 |
-
* @version 1.0
|
36 |
-
*/
|
37 |
-
public function run() {
|
38 |
-
add_action( 'wp_loaded', array( $this, 'process' ) );
|
39 |
-
add_action( 'mycred_banking_interest_compound', array( $this, 'do_compound' ) );
|
40 |
-
add_action( 'mycred_banking_do_compound_batch', array( $this, 'do_compound_batch' ) );
|
41 |
-
|
42 |
-
add_action( 'mycred_banking_interest_payout', array( $this, 'do_payouts' ) );
|
43 |
-
add_action( 'mycred_banking_interest_do_batch', array( $this, 'do_interest_batch' ) );
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Deactivation
|
48 |
-
* @since 1.2
|
49 |
-
* @version 1.0
|
50 |
-
*/
|
51 |
-
public function deactivate() {
|
52 |
-
// Unschedule compounding
|
53 |
-
$timestamp = wp_next_scheduled( 'mycred_banking_interest_compound' );
|
54 |
-
if ( $timestamp !== false )
|
55 |
-
wp_clear_scheduled_hook( $timestamp, 'mycred_banking_interest_compound' );
|
56 |
-
|
57 |
-
// Unschedule payouts
|
58 |
-
$timestamp = wp_next_scheduled( 'mycred_banking_interest_payout' );
|
59 |
-
if ( $timestamp !== false )
|
60 |
-
wp_clear_scheduled_hook( $timestamp, 'mycred_banking_interest_payout' );
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Process
|
65 |
-
* Determines if we should run a payout or not and schedule the daily
|
66 |
-
* compounding.
|
67 |
-
* @since 1.2
|
68 |
-
* @version 1.0
|
69 |
-
*/
|
70 |
-
public function process() {
|
71 |
-
// Unschedule if amount is set to zero
|
72 |
-
if ( $this->prefs['rate']['amount'] == $this->core->zero() ) {
|
73 |
-
$timestamp = wp_next_scheduled( 'mycred_banking_interest_compound' );
|
74 |
-
if ( $timestamp !== false )
|
75 |
-
wp_clear_scheduled_hook( $timestamp, 'mycred_banking_interest_compound' );
|
76 |
-
}
|
77 |
-
|
78 |
-
// Schedule if none exist
|
79 |
-
if ( ! wp_next_scheduled( 'mycred_banking_interest_compound' ) ) {
|
80 |
-
wp_schedule_event( time(), 'daily', 'mycred_banking_interest_compound' );
|
81 |
-
}
|
82 |
-
|
83 |
-
$unow = date_i18n( 'U' );
|
84 |
-
// Cant pay interest on zero
|
85 |
-
if ( $this->prefs['rate']['amount'] == $this->core->zero() ) return;
|
86 |
-
|
87 |
-
// Should we payout
|
88 |
-
$payout_now = $this->get_now( $this->prefs['rate']['pay_out'] );
|
89 |
-
if ( empty( $this->prefs['last_payout'] ) || $this->prefs['last_payout'] === NULL ) {
|
90 |
-
$last_payout = $this->get_last_run( $unow, $this->prefs['rate']['pay_out'] );
|
91 |
-
$this->save( 'last_payout', $unow );
|
92 |
-
}
|
93 |
-
else {
|
94 |
-
$last_payout = $this->get_last_run( $this->prefs['last_payout'], $this->prefs['rate']['pay_out'] );
|
95 |
-
}
|
96 |
-
if ( $payout_now === false || $last_payout === false ) return;
|
97 |
-
|
98 |
-
// Time to run?
|
99 |
-
if ( $this->time_to_run( $this->prefs['rate']['pay_out'], $last_payout ) ) {
|
100 |
-
// Save
|
101 |
-
$this->save( 'last_payout', $unow );
|
102 |
-
|
103 |
-
// Schedule Payouts
|
104 |
-
if ( wp_next_scheduled( 'mycred_banking_interest_payout' ) === false )
|
105 |
-
wp_schedule_single_event( time(), 'mycred_banking_interest_payout' );
|
106 |
-
}
|
107 |
-
}
|
108 |
-
|
109 |
-
/**
|
110 |
-
* Do Compound
|
111 |
-
* Either runs compounding on every single user in one go, or split the users
|
112 |
-
* up into groups of 2000 IDs and do them in batches.
|
113 |
-
* @since 1.2
|
114 |
-
* @version 1.0
|
115 |
-
*/
|
116 |
-
public function do_compound() {
|
117 |
-
if ( $this->prefs['rate']['amount'] == $this->core->zero() ) return;
|
118 |
-
// Get users
|
119 |
-
$users = $this->get_users();
|
120 |
-
$total = count( $users );
|
121 |
-
$threshold = (int) apply_filters( 'mycred_do_banking_limit', 2000 );
|
122 |
-
|
123 |
-
if ( (int) $total > $threshold ) {
|
124 |
-
$batches = array_chunk( $users, $threshold );
|
125 |
-
$time = time();
|
126 |
-
|
127 |
-
$set = 0;
|
128 |
-
foreach ( $batches as $batch_id => $batch ) {
|
129 |
-
$set = $set+1;
|
130 |
-
$run_time = ( $time + ( 60*$set ) );
|
131 |
-
if ( wp_next_scheduled( $run_time, 'mycred_banking_do_compound_batch', array( $batch ) ) === false )
|
132 |
-
wp_schedule_single_event( $run_time, 'mycred_banking_do_compound_batch', array( $batch ) );
|
133 |
-
}
|
134 |
-
}
|
135 |
-
else {
|
136 |
-
$this->do_compound_batch( $users );
|
137 |
-
}
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* Do Compound Batch
|
142 |
-
* Compounds interest for each user ID given in batch.
|
143 |
-
* @since 1.2
|
144 |
-
* @version 1.2.1
|
145 |
-
*/
|
146 |
-
public function do_compound_batch( $batch ) {
|
147 |
-
if ( !empty( $batch ) && is_array( $batch ) ) {
|
148 |
-
|
149 |
-
set_time_limit( $this->prefs['run_time'] );
|
150 |
-
|
151 |
-
foreach ( $batch as $user_id ) {
|
152 |
-
$user_id = intval( $user_id );
|
153 |
-
|
154 |
-
// Current balance
|
155 |
-
$balance = $this->core->get_users_cred( $user_id );
|
156 |
-
if ( $balance == 0 ) continue;
|
157 |
-
|
158 |
-
// Get past interest
|
159 |
-
$past_interest = mycred_get_user_meta( $user_id, $this->core->get_cred_id() . '_comp', '', true );
|
160 |
-
if ( empty( $past_interest ) ) $past_interest = 0;
|
161 |
-
|
162 |
-
// Min Balance Limit
|
163 |
-
if ( $balance < $this->core->number( $this->prefs['min_balance'] ) ) continue;
|
164 |
-
|
165 |
-
// Convert rate
|
166 |
-
$rate = $this->prefs['rate']['amount']/100;
|
167 |
-
|
168 |
-
// Period
|
169 |
-
$period = $this->prefs['rate']['period']/$this->get_days_in_year();
|
170 |
-
|
171 |
-
// Compound
|
172 |
-
$interest = ( $balance + $past_interest ) * $rate * $period;
|
173 |
-
$interest = round( $interest, 2 );
|
174 |
-
|
175 |
-
// Save interest
|
176 |
-
mycred_update_user_meta( $user_id, $this->core->get_cred_id() . '_comp', '', $interest );
|
177 |
-
}
|
178 |
-
}
|
179 |
-
}
|
180 |
-
|
181 |
-
/**
|
182 |
-
* Payout
|
183 |
-
* Will either payout to all users in one go or if there is more then
|
184 |
-
* 2000 members, do them in batches of 2000 at a time.
|
185 |
-
* @since 1.2
|
186 |
-
* @version 1.1
|
187 |
-
*/
|
188 |
-
public function do_payouts() {
|
189 |
-
// Make sure to clear any stray schedules to prevent duplicates
|
190 |
-
wp_clear_scheduled_hook( 'mycred_banking_interest_payout' );
|
191 |
-
|
192 |
-
// Query
|
193 |
-
$users = $this->get_users();
|
194 |
-
$total = count( $users );
|
195 |
-
$threshold = (int) apply_filters( 'mycred_do_banking_limit', 2000 );
|
196 |
-
|
197 |
-
if ( (int) $total > $threshold ) {
|
198 |
-
$batches = array_chunk( $users, $threshold );
|
199 |
-
$time = time();
|
200 |
-
|
201 |
-
$set = 0;
|
202 |
-
foreach ( $batches as $batch_id => $batch ) {
|
203 |
-
$set = $set+1;
|
204 |
-
$run_time = ( $time + ( 60*$set ) );
|
205 |
-
if ( wp_next_scheduled( $run_time, 'mycred_banking_interest_do_batch', array( $batch ) ) === false )
|
206 |
-
wp_schedule_single_event( $run_time, 'mycred_banking_interest_do_batch', array( $batch ) );
|
207 |
-
}
|
208 |
-
}
|
209 |
-
else {
|
210 |
-
$this->do_interest_batch( $users );
|
211 |
-
}
|
212 |
-
}
|
213 |
-
|
214 |
-
/**
|
215 |
-
* Do Payout
|
216 |
-
* Runs though all user compounded interest and pays.
|
217 |
-
* @since 1.2
|
218 |
-
* @version 1.2.1
|
219 |
-
*/
|
220 |
-
public function do_interest_batch( $batch ) {
|
221 |
-
if ( !empty( $batch ) && is_array( $batch ) ) {
|
222 |
-
|
223 |
-
set_time_limit( $this->prefs['run_time'] );
|
224 |
-
|
225 |
-
foreach ( $batch as $user_id ) {
|
226 |
-
$user_id = intval( $user_id );
|
227 |
-
|
228 |
-
// Get past interest
|
229 |
-
$past_interest = mycred_get_user_meta( $user_id, $this->core->get_cred_id() . '_comp', '', true );
|
230 |
-
if ( empty( $past_interest ) || $past_interest == 0 ) continue;
|
231 |
-
|
232 |
-
// Pay / Charge
|
233 |
-
$this->core->add_creds(
|
234 |
-
'payout',
|
235 |
-
$user_id,
|
236 |
-
$past_interest,
|
237 |
-
$this->prefs['log']
|
238 |
-
);
|
239 |
-
|
240 |
-
// Reset past interest
|
241 |
-
mycred_update_user_meta( $user_id, $this->core->get_cred_id() . '_comp', '', 0 );
|
242 |
-
}
|
243 |
-
}
|
244 |
-
}
|
245 |
-
|
246 |
-
/**
|
247 |
-
* Save
|
248 |
-
* Saves the given preference id for rates.
|
249 |
-
* from the active list.
|
250 |
-
* @since 1.2
|
251 |
-
* @version 1.1
|
252 |
-
*/
|
253 |
-
public function save( $id, $now ) {
|
254 |
-
if ( !isset( $this->prefs[ $id ] ) ) return;
|
255 |
-
$this->prefs[ $id ] = $now;
|
256 |
-
|
257 |
-
// Get Bank settings
|
258 |
-
$bank = mycred_get_option( 'mycred_pref_bank' );
|
259 |
-
|
260 |
-
// Update settings
|
261 |
-
$bank['service_prefs'][$this->id] = $this->prefs;
|
262 |
-
|
263 |
-
// Save new settings
|
264 |
-
mycred_update_option( 'mycred_pref_bank', $bank );
|
265 |
-
}
|
266 |
-
|
267 |
-
/**
|
268 |
-
* Preference for Savings
|
269 |
-
* @since 1.2
|
270 |
-
* @version 1.2
|
271 |
-
*/
|
272 |
-
public function preferences() {
|
273 |
-
$prefs = $this->prefs; ?>
|
274 |
-
|
275 |
-
<label class="subheader"><?php _e( 'Interest Rate', 'mycred' ); ?></label>
|
276 |
-
<ol class="inline">
|
277 |
-
<li>
|
278 |
-
<label> </label>
|
279 |
-
<div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'rate' => 'amount' ) ); ?>" id="<?php echo $this->field_id( array( 'rate' => 'amount' ) ); ?>" value="<?php echo $this->core->format_number( $prefs['rate']['amount'] ); ?>" size="4" /> %</div>
|
280 |
-
</li>
|
281 |
-
<li>
|
282 |
-
<label for="<?php echo $this->field_id( array( 'rate' => 'pay_out' ) ); ?>"><?php _e( 'Payed / Charged', 'mycred' ); ?></label><br />
|
283 |
-
<?php $this->timeframe_dropdown( array( 'rate' => 'pay_out' ), false, false ); ?>
|
284 |
-
|
285 |
-
</li>
|
286 |
-
<li class="block">
|
287 |
-
<input type="hidden" name="<?php echo $this->field_name( 'last_payout' ); ?>" value="<?php echo $prefs['last_payout']; ?>" />
|
288 |
-
<span class="description"><?php _e( 'The interest rate can be either positive or negative and is compounded daily.', 'mycred' ); ?></span>
|
289 |
-
</li>
|
290 |
-
</ol>
|
291 |
-
<label class="subheader"><?php _e( 'Minimum Balance', 'mycred' ); ?></label>
|
292 |
-
<ol>
|
293 |
-
<li>
|
294 |
-
<div class="h2"><?php if ( $this->core->before != '' ) echo $this->core->before . ' '; ?><input type="text" name="<?php echo $this->field_name( 'min_balance' ); ?>" id="<?php echo $this->field_id( 'min_balance' ); ?>" value="<?php echo $this->core->format_number( $prefs['min_balance'] ); ?>" size="8" /><?php if ( $this->core->after != '' ) echo ' ' . $this->core->after; ?></div>
|
295 |
-
<span class="description"><?php _e( 'The minimum requires balance for interest to apply.', 'mycred' ); ?></span>
|
296 |
-
</li>
|
297 |
-
</ol>
|
298 |
-
<label class="subheader"><?php _e( 'Log Template', 'mycred' ); ?></label>
|
299 |
-
<ol>
|
300 |
-
<li>
|
301 |
-
<div class="h2"><input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" value="<?php echo $prefs['log']; ?>" style="width: 65%;" /></div>
|
302 |
-
<span class="description"><?php echo $this->core->available_template_tags( array( 'general' ), '%timeframe%, %rate%, %base%' ); ?></span>
|
303 |
-
</li>
|
304 |
-
</ol>
|
305 |
-
<label class="subheader" for="<?php echo $this->field_id( 'run_time' ); ?>"><?php _e( 'Run Time', 'mycred' ); ?></label>
|
306 |
-
<ol>
|
307 |
-
<li>
|
308 |
-
<div class="h2"><input type="text" name="<?php echo $this->field_name( 'run_time' ); ?>" id="<?php echo $this->field_id( 'run_time' ); ?>" value="<?php echo $prefs['run_time']; ?>" size="4" /></div>
|
309 |
-
<span class="description"><?php _e( 'For large websites, if you are running into time out issues during payouts, you can set the number of seconds a process can run. Use zero for unlimited, but be careful especially if you are on a shared server.', 'mycred' ); ?></span>
|
310 |
-
</li>
|
311 |
-
</ol>
|
312 |
-
<?php do_action( 'mycred_banking_compound_interest', $this->prefs ); ?>
|
313 |
-
<?php
|
314 |
-
}
|
315 |
-
|
316 |
-
/**
|
317 |
-
* Sanitise Preferences
|
318 |
-
* @since 1.2
|
319 |
-
* @version 1.2
|
320 |
-
*/
|
321 |
-
function sanitise_preferences( $post ) {
|
322 |
-
$new_settings = $post;
|
323 |
-
|
324 |
-
$new_settings['rate']['amount'] = str_replace( ',', '.', trim( $post['rate']['amount'] ) );
|
325 |
-
|
326 |
-
$new_settings['rate']['period'] = $this->get_days_in_year();
|
327 |
-
|
328 |
-
$new_settings['rate']['pay_out'] = sanitize_text_field( $post['rate']['pay_out'] );
|
329 |
-
|
330 |
-
$new_settings['min_balance'] = str_replace( ',', '.', trim( $post['min_balance'] ) );
|
331 |
-
|
332 |
-
$new_settings['last_payout'] = trim( $post['last_payout'] );
|
333 |
-
|
334 |
-
$new_settings['log'] = trim( $post['log'] );
|
335 |
-
|
336 |
-
$post['run_time'] = abs( $post['run_time'] );
|
337 |
-
$new_settings['run_time'] = sanitize_text_field( $post['run_time'] );
|
338 |
-
|
339 |
-
return apply_filters( 'mycred_banking_save_interest', $new_settings, $this->prefs );
|
340 |
-
}
|
341 |
-
}
|
342 |
-
}
|
343 |
-
|
344 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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9 |
-
if ( !class_exists( 'myCRED_Banking_Service_Payouts' ) ) {
|
10 |
-
class myCRED_Banking_Service_Payouts extends myCRED_Service {
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Construct
|
14 |
-
*/
|
15 |
-
function __construct( $service_prefs ) {
|
16 |
-
parent::__construct( array(
|
17 |
-
'id' => 'payouts',
|
18 |
-
'defaults' => array(
|
19 |
-
'amount' => 10,
|
20 |
-
'rate' => 'daily',
|
21 |
-
'log' => __( 'Daily %_plural%', 'mycred' ),
|
22 |
-
'excludes' => '',
|
23 |
-
'cycles' => 0,
|
24 |
-
'last_run' => '',
|
25 |
-
'run_time' => 60
|
26 |
-
)
|
27 |
-
), $service_prefs );
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Run
|
32 |
-
* @since 1.2
|
33 |
-
* @version 1.0
|
34 |
-
*/
|
35 |
-
public function run() {
|
36 |
-
add_action( 'wp_loaded', array( $this, 'process' ) );
|
37 |
-
add_action( 'mycred_banking_recurring_payout', array( $this, 'do_payouts' ) );
|
38 |
-
add_action( 'mycred_banking_do_batch', array( $this, 'do_payout_batch' ), 10, 3 );
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Deactivation
|
43 |
-
* @since 1.2
|
44 |
-
* @version 1.0
|
45 |
-
*/
|
46 |
-
public function deactivate() {
|
47 |
-
// Unschedule payouts
|
48 |
-
wp_clear_scheduled_hook( 'mycred_banking_recurring_payout' );
|
49 |
-
}
|
50 |
-
|
51 |
-
/**
|
52 |
-
* Process
|
53 |
-
* Determines if we should run a payout or not.
|
54 |
-
* @since 1.2
|
55 |
-
* @version 1.1
|
56 |
-
*/
|
57 |
-
public function process() {
|
58 |
-
// Get cycles
|
59 |
-
$cycles = (int) $this->prefs['cycles'];
|
60 |
-
// Zero cycles left, bail
|
61 |
-
if ( $cycles == 0 ) return;
|
62 |
-
|
63 |
-
// No amount = no payout
|
64 |
-
if ( !isset( $this->prefs['amount'] ) || $this->prefs['amount'] == 0 ) return;
|
65 |
-
|
66 |
-
$unow = date_i18n( 'U' );
|
67 |
-
$now = $this->get_now( $this->prefs['rate'] );
|
68 |
-
// No last run, save now as last run
|
69 |
-
if ( empty( $this->prefs['last_run'] ) || $this->prefs['last_run'] === NULL ) {
|
70 |
-
$last_run = $this->get_last_run( $unow, $this->prefs['rate'] );
|
71 |
-
$this->save( $unow, $cycles );
|
72 |
-
}
|
73 |
-
// Last run
|
74 |
-
else {
|
75 |
-
$last_run = $this->get_last_run( $this->prefs['last_run'], $this->prefs['rate'] );
|
76 |
-
}
|
77 |
-
// If now or last run returns false bail
|
78 |
-
if ( $now === false || $last_run === false ) return;
|
79 |
-
|
80 |
-
// Is it time to run?
|
81 |
-
if ( $this->time_to_run( $this->prefs['rate'], $last_run ) ) {
|
82 |
-
// Cycles (-1 means no limit)
|
83 |
-
if ( $cycles > 0-1 ) {
|
84 |
-
$cycles = $cycles-1;
|
85 |
-
}
|
86 |
-
// Save
|
87 |
-
$this->save( $unow, $cycles );
|
88 |
-
|
89 |
-
// Schedule payouts
|
90 |
-
if ( wp_next_scheduled( 'mycred_banking_recurring_payout', array( $cycles ) ) === false )
|
91 |
-
wp_schedule_single_event( time(), 'mycred_banking_recurring_payout', array( $cycles ) );
|
92 |
-
}
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Payout
|
97 |
-
* In this first step, we start by gathering all user ID's.
|
98 |
-
* If the amount is higher then our threshold, we split up the ID's
|
99 |
-
* into batches and schedule then seperate. This is due to the maximum
|
100 |
-
* execution limit which will not be enough to handle a lot of users in one go.
|
101 |
-
* @since 1.2
|
102 |
-
* @version 1.1
|
103 |
-
*/
|
104 |
-
public function do_payouts( $cycle = NULL ) {
|
105 |
-
// Make sure to clear any stray schedules to prevent duplicates
|
106 |
-
wp_clear_scheduled_hook( 'mycred_banking_recurring_payout' );
|
107 |
-
|
108 |
-
// Query
|
109 |
-
$users = $this->get_users();
|
110 |
-
$total = count( $users );
|
111 |
-
$threshold = (int) apply_filters( 'mycred_do_banking_limit', 2000 );
|
112 |
-
|
113 |
-
// If we are over the threshold we need to batch
|
114 |
-
if ( (int) $total > $threshold ) {
|
115 |
-
$batches = array_chunk( $users, $threshold );
|
116 |
-
$time = time();
|
117 |
-
|
118 |
-
$set = 0;
|
119 |
-
foreach ( $batches as $batch_id => $batch ) {
|
120 |
-
$set = $set+1;
|
121 |
-
// Run time = current time + 60 seconds for each set
|
122 |
-
$run_time = ( $time + ( 60*$set ) );
|
123 |
-
if ( wp_next_scheduled( $run_time, 'mycred_banking_do_batch', array( $batch, $set, $cycle ) ) === false )
|
124 |
-
wp_schedule_single_event( $run_time, 'mycred_banking_do_batch', array( $batch, $set, $cycle ) );
|
125 |
-
}
|
126 |
-
set_transient( 'mycred_banking_num_payout_batches', $set, HOUR_IN_SECONDS );
|
127 |
-
}
|
128 |
-
// Run single batch now
|
129 |
-
else {
|
130 |
-
$this->do_payout_batch( $users, NULL, $cycle );
|
131 |
-
}
|
132 |
-
}
|
133 |
-
|
134 |
-
/**
|
135 |
-
* Do Batch
|
136 |
-
* Applies points to a batch of user ID's. This is also where we check for exclusions.
|
137 |
-
* @since 1.2
|
138 |
-
* @version 1.2.1
|
139 |
-
*/
|
140 |
-
public function do_payout_batch( $batch, $set = NULL, $cycle = NULL ) {
|
141 |
-
if ( !empty( $batch ) && is_array( $batch ) ) {
|
142 |
-
|
143 |
-
set_time_limit( $this->prefs['run_time'] );
|
144 |
-
|
145 |
-
foreach ( $batch as $user_id ) {
|
146 |
-
$user_id = intval( $user_id );
|
147 |
-
|
148 |
-
// Add / Deduct points
|
149 |
-
$this->core->update_users_balance( $user_id, $this->prefs['amount'] );
|
150 |
-
$this->core->add_to_log(
|
151 |
-
'payout',
|
152 |
-
$user_id,
|
153 |
-
$this->prefs['amount'],
|
154 |
-
$this->prefs['log']
|
155 |
-
);
|
156 |
-
}
|
157 |
-
// If multiple sets, check if this is the last one to deactivate
|
158 |
-
if ( $set !== NULL ) {
|
159 |
-
$total = get_transient( 'mycred_banking_num_payout_batches' );
|
160 |
-
if ( $total !== false && $set == $total ) {
|
161 |
-
delete_transient( 'mycred_banking_num_payout_batches' );
|
162 |
-
|
163 |
-
if ( $cycle == 0 )
|
164 |
-
$this->save( date_i18n( 'U' ), 0, true );
|
165 |
-
}
|
166 |
-
}
|
167 |
-
// Single set, check if cycle is zero to deactivate
|
168 |
-
elseif ( $set === NULL && $cycle == 0 )
|
169 |
-
$this->save( date_i18n( 'U' ), 0, true );
|
170 |
-
}
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Save
|
175 |
-
* Saves the last run and the number of cycles run.
|
176 |
-
* @since 1.2
|
177 |
-
* @version 1.1.1
|
178 |
-
*/
|
179 |
-
public function save( $now = 0, $cycles = 0, $deactivate = false ) {
|
180 |
-
// Update last run
|
181 |
-
$this->prefs['last_run'] = $now;
|
182 |
-
// Update cycles count
|
183 |
-
$this->prefs['cycles'] = $cycles;
|
184 |
-
|
185 |
-
// Get Bank settings
|
186 |
-
$bank = get_option( 'mycred_pref_bank' );
|
187 |
-
|
188 |
-
// Update settings
|
189 |
-
$bank['service_prefs'][ $this->id ] = $this->prefs;
|
190 |
-
|
191 |
-
// Deactivate this service if this is the last run
|
192 |
-
if ( $cycles == 0 && $deactivate ) {
|
193 |
-
// Should return the service id as a key for us to unset
|
194 |
-
if ( ( $key = array_search( $this->id, $bank['active'] ) ) !== false ) {
|
195 |
-
unset( $bank['active'][ $key ] );
|
196 |
-
}
|
197 |
-
}
|
198 |
-
|
199 |
-
// Save new settings
|
200 |
-
update_option( 'mycred_pref_bank', $bank );
|
201 |
-
}
|
202 |
-
|
203 |
-
/**
|
204 |
-
* Preference for Savings
|
205 |
-
* @since 1.2
|
206 |
-
* @version 1.1
|
207 |
-
*/
|
208 |
-
public function preferences() {
|
209 |
-
$prefs = $this->prefs;
|
210 |
-
|
211 |
-
// Last run
|
212 |
-
$last_run = $prefs['last_run'];
|
213 |
-
if ( empty( $last_run ) )
|
214 |
-
$last_run = __( 'Not yet run', 'mycred' );
|
215 |
-
else
|
216 |
-
$last_run = date_i18n( get_option( 'date_format' ) . ' : ' . get_option( 'time_format' ), $last_run ); ?>
|
217 |
-
|
218 |
-
|
219 |
-
<label class="subheader"><?php _e( 'Pay Users', 'mycred' ); ?></label>
|
220 |
-
<ol class="inline">
|
221 |
-
<li>
|
222 |
-
<label><?php _e( 'Amount', 'mycred' ); ?></label>
|
223 |
-
<div class="h2"><?php if ( !empty( $this->core->before ) ) echo $this->core->before . ' '; ?><input type="text" name="<?php echo $this->field_name( 'amount' ); ?>" id="<?php echo $this->field_id( 'amount' ); ?>" value="<?php echo $this->core->format_number( $prefs['amount'] ); ?>" size="8" /><?php if ( !empty( $this->core->after ) ) echo ' ' . $this->core->after; ?></div>
|
224 |
-
<span class="description"><?php _e( 'Can not be zero.', 'mycred' ); ?></span>
|
225 |
-
<input type="hidden" name="<?php echo $this->field_name( 'last_run' ); ?>" value="<?php echo $prefs['last_run']; ?>" />
|
226 |
-
</li>
|
227 |
-
<li>
|
228 |
-
<label for="<?php echo $this->field_id( 'rate' ); ?>"><?php _e( 'Interval', 'mycred' ); ?></label><br />
|
229 |
-
<?php $this->timeframe_dropdown( 'rate', false ); ?>
|
230 |
-
|
231 |
-
</li>
|
232 |
-
<li>
|
233 |
-
<label><?php _e( 'Cycles', 'mycred' ); ?></label>
|
234 |
-
<div class="h2"><input type="text" name="<?php echo $this->field_name( 'cycles' ); ?>" id="<?php echo $this->field_id( 'cycles' ); ?>" value="<?php echo $prefs['cycles']; ?>" size="8" /></div>
|
235 |
-
<span class="description"><?php _e( 'Set to -1 for unlimited', 'mycred' ); ?></span>
|
236 |
-
</li>
|
237 |
-
<li>
|
238 |
-
<label><?php _e( 'Last Run / Activated', 'mycred' ); ?></label><br />
|
239 |
-
<div class="h2"><?php echo $last_run; ?></div>
|
240 |
-
</li>
|
241 |
-
<li class="block"><strong><?php _e( 'Interval', 'mycred' ); ?></strong><br /><?php echo $this->core->template_tags_general( __( 'Select how often you want to award %_plural%. Note that when this service is enabled, the first payout will be in the beginning of the next period. So with a "Daily" interval, the first payout will occur first thing in the morning.', 'mycred' ) ); ?></li>
|
242 |
-
<li class="block"><strong><?php _e( 'Cycles', 'mycred' ); ?></strong><br /><?php _e( 'Cycles let you choose how many intervals this service should run. Each time a cycle runs, the value will decrease until it hits zero, in which case this service will deactivate itself. Use -1 to run unlimited times.', 'mycred' ); ?></li>
|
243 |
-
<li class="block"><strong><?php _e( 'Important', 'mycred' ); ?></strong><br /><?php _e( 'You can always stop payouts by deactivating this service. Just remember that if you deactivate while there are cycles left, this service will continue on when it gets re-activated. Set cycles to zero to reset.', 'mycred' ); ?></li>
|
244 |
-
</ol>
|
245 |
-
<label class="subheader" for="<?php echo $this->field_id( 'excludes' ); ?>"><?php _e( 'Excludes', 'mycred' ); ?></label>
|
246 |
-
<ol>
|
247 |
-
<li>
|
248 |
-
<div class="h2"><input type="text" name="<?php echo $this->field_name( 'excludes' ); ?>" id="<?php echo $this->field_id( 'excludes' ); ?>" value="<?php echo $prefs['excludes']; ?>" style="width: 65%;" /></div>
|
249 |
-
<span class="description"><?php _e( 'Comma separated list of user IDs to exclude from this service. No spaces allowed!', 'mycred' ); ?></span>
|
250 |
-
</li>
|
251 |
-
</ol>
|
252 |
-
<label class="subheader" for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
|
253 |
-
<ol>
|
254 |
-
<li>
|
255 |
-
<div class="h2"><input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" value="<?php echo $prefs['log']; ?>" style="width: 65%;" /></div>
|
256 |
-
<span class="description"><?php echo $this->core->available_template_tags( array( 'general' ) ); ?></span>
|
257 |
-
</li>
|
258 |
-
</ol>
|
259 |
-
<label class="subheader" for="<?php echo $this->field_id( 'run_time' ); ?>"><?php _e( 'Run Time', 'mycred' ); ?></label>
|
260 |
-
<ol>
|
261 |
-
<li>
|
262 |
-
<div class="h2"><input type="text" name="<?php echo $this->field_name( 'run_time' ); ?>" id="<?php echo $this->field_id( 'run_time' ); ?>" value="<?php echo $prefs['run_time']; ?>" size="4" /></div>
|
263 |
-
<span class="description"><?php _e( 'For large websites, if you are running into time out issues during payouts, you can set the number of seconds a process can run. Use zero for unlimited, but be careful especially if you are on a shared server.', 'mycred' ); ?></span>
|
264 |
-
</li>
|
265 |
-
</ol>
|
266 |
-
<?php do_action( 'mycred_banking_recurring_payouts', $this->prefs ); ?>
|
267 |
-
<?php
|
268 |
-
}
|
269 |
-
|
270 |
-
/**
|
271 |
-
* Sanitise Preferences
|
272 |
-
* @since 1.2
|
273 |
-
* @version 1.1
|
274 |
-
*/
|
275 |
-
function sanitise_preferences( $post ) {
|
276 |
-
// Amount
|
277 |
-
$new_settings['amount'] = trim( $post['amount'] );
|
278 |
-
|
279 |
-
// Rate
|
280 |
-
$new_settings['rate'] = sanitize_text_field( $post['rate'] );
|
281 |
-
|
282 |
-
// Cycles
|
283 |
-
$new_settings['cycles'] = sanitize_text_field( $post['cycles'] );
|
284 |
-
|
285 |
-
// Last Run
|
286 |
-
$new_settings['last_run'] = $post['last_run'];
|
287 |
-
$current_cycles = $this->prefs['cycles'];
|
288 |
-
// Moving from -1 or 0 to any higher number indicates a new start. In these cases, we will
|
289 |
-
// reset the last run timestamp to prevent this service from running right away.
|
290 |
-
if ( ( $current_cycles == 0 || $current_cycles == 0-1 ) && $new_settings['cycles'] > 0 )
|
291 |
-
$new_settings['last_run'] = '';
|
292 |
-
|
293 |
-
// Excludes
|
294 |
-
$excludes = str_replace( ' ', '', $post['excludes'] );
|
295 |
-
$new_settings['excludes'] = sanitize_text_field( $excludes );
|
296 |
-
|
297 |
-
// Log
|
298 |
-
$new_settings['log'] = trim( $post['log'] );
|
299 |
-
|
300 |
-
// Run Time
|
301 |
-
$post['run_time'] = abs( $post['run_time'] );
|
302 |
-
$new_settings['run_time'] = sanitize_text_field( $post['run_time'] );
|
303 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addons/banking/services/mycred-service-interest.php
DELETED
@@ -1,691 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'myCRED_VERSION' ) ) exit;
|
3 |
-
|
4 |
-
/**
|
5 |
-
* myCRED Bank Service - Interest
|
6 |
-
* @since 1.2
|
7 |
-
* @version 1.2
|
8 |
-
*/
|
9 |
-
if ( ! class_exists( 'myCRED_Banking_Service_Interest' ) ) :
|
10 |
-
class myCRED_Banking_Service_Interest extends myCRED_Service {
|
11 |
-
|
12 |
-
public $cron_compound_key = '';
|
13 |
-
public $cron_payout_key = '';
|
14 |
-
public $compound_meta_key = '';
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Construct
|
18 |
-
*/
|
19 |
-
function __construct( $service_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
|
20 |
-
|
21 |
-
parent::__construct( array(
|
22 |
-
'id' => 'interest',
|
23 |
-
'defaults' => array(
|
24 |
-
'rate' => array(
|
25 |
-
'amount' => 2,
|
26 |
-
'pay_out' => 'monthly'
|
27 |
-
),
|
28 |
-
'log' => __( '%plural% interest rate payment', 'mycred' ),
|
29 |
-
'min_balance' => 1,
|
30 |
-
'exclude_ids' => '',
|
31 |
-
'exclude_roles' => array()
|
32 |
-
)
|
33 |
-
), $service_prefs, $type );
|
34 |
-
|
35 |
-
$this->cron_compound_key = 'mycred_bank_interest_comp' . $type;
|
36 |
-
$this->cron_payout_key = 'mycred_bank_interest_pay' . $type;
|
37 |
-
$this->compound_meta_key = $type . '_comp';
|
38 |
-
$this->log_reference = apply_filters( 'mycred_bank_interest_reference', 'interest', $this );
|
39 |
-
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Deactivate Service
|
44 |
-
* Used if the service is no longer reach the minimum requirements or when the
|
45 |
-
* service is disabled in the admin area.
|
46 |
-
* @since 1.5.2
|
47 |
-
* @version 1.1
|
48 |
-
*/
|
49 |
-
public function deactivate() {
|
50 |
-
|
51 |
-
$timestamp = wp_next_scheduled( $this->cron_compound_key );
|
52 |
-
if ( $timestamp !== false )
|
53 |
-
wp_clear_scheduled_hook( $this->cron_compound_key );
|
54 |
-
|
55 |
-
$timestamp = wp_next_scheduled( $this->cron_payout_key );
|
56 |
-
if ( $timestamp !== false )
|
57 |
-
wp_clear_scheduled_hook( $this->cron_payout_key );
|
58 |
-
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Is Ready
|
63 |
-
* Checks to make sure the most common "bugs" users experience with this service
|
64 |
-
* are taken care of. An empty log or empty interest rate will not work.
|
65 |
-
* @since 1.7
|
66 |
-
* @version 1.0
|
67 |
-
*/
|
68 |
-
protected function is_ready() {
|
69 |
-
|
70 |
-
$rate = $this->prefs['rate']['amount'];
|
71 |
-
if ( strlen( $rate ) == 0 ) return false;
|
72 |
-
|
73 |
-
$log = $this->prefs['log'];
|
74 |
-
if ( strlen( $log ) == 0 ) return false;
|
75 |
-
|
76 |
-
return true;
|
77 |
-
|
78 |
-
}
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Run
|
82 |
-
* Actions taken during WordPress init. Hooks into the cron jobs and schedules
|
83 |
-
* the cron jobs if not scheduled. Will only run if service is enabled.
|
84 |
-
* @since 1.2
|
85 |
-
* @version 1.1
|
86 |
-
*/
|
87 |
-
public function run() {
|
88 |
-
|
89 |
-
// Make sure we can run this service
|
90 |
-
if ( ! $this->is_ready() ) {
|
91 |
-
|
92 |
-
$this->deactivate();
|
93 |
-
return;
|
94 |
-
|
95 |
-
}
|
96 |
-
|
97 |
-
add_action( 'mycred_bank_interest_comp' . $this->mycred_type, array( $this, 'do_compounding' ), 10 );
|
98 |
-
add_action( 'mycred_bank_interest_pay' . $this->mycred_type, array( $this, 'do_interest_payout' ), 10 );
|
99 |
-
|
100 |
-
$now = $this->now;
|
101 |
-
|
102 |
-
// Make sure there is a compounding scheduled
|
103 |
-
$compound = wp_next_scheduled( $this->cron_compound_key );
|
104 |
-
if ( $compound === false )
|
105 |
-
wp_schedule_single_event( $now + 600, $this->cron_compound_key );
|
106 |
-
|
107 |
-
// Make sure there is a compounding scheduled
|
108 |
-
$payout = wp_next_scheduled( $this->cron_payout_key );
|
109 |
-
if ( $payout === false ) {
|
110 |
-
|
111 |
-
$now += mycred_banking_get_next_payout( $this->prefs['rate']['pay_out'] );
|
112 |
-
wp_schedule_single_event( $now, $this->cron_payout_key );
|
113 |
-
|
114 |
-
}
|
115 |
-
|
116 |
-
add_action( 'personal_options_update', array( $this, 'save_custom_rate' ), 30 );
|
117 |
-
add_action( 'edit_user_profile_update', array( $this, 'save_custom_rate' ), 30 );
|
118 |
-
|
119 |
-
}
|
120 |
-
|
121 |
-
/**
|
122 |
-
* Do Interest Compounding
|
123 |
-
* Compounds interest on balances each day.
|
124 |
-
* @since 1.5.2
|
125 |
-
* @version 1.1
|
126 |
-
*/
|
127 |
-
public function do_compounding() {
|
128 |
-
|
129 |
-
global $wpdb;
|
130 |
-
|
131 |
-
$limit = '';
|
132 |
-
$select = "user_id, meta_value as value";
|
133 |
-
|
134 |
-
// Default number of balances we will be running through for now
|
135 |
-
$number = absint( apply_filters( 'mycred_compound_max_limit', 1500, $this ) );
|
136 |
-
|
137 |
-
// On large sites, we need to do this in batches
|
138 |
-
if ( $this->is_large_site() ) {
|
139 |
-
|
140 |
-
// Schedule our next event in 2 minutes
|
141 |
-
wp_schedule_single_event( ( $this->now + 180 ), $this->cron_compound_key );
|
142 |
-
|
143 |
-
$transient_key = 'mycred-compoun-' . $this->mycred_type;
|
144 |
-
$offset = get_transient( $transient_key );
|
145 |
-
|
146 |
-
// Apply limit and set a transient to keep track of our progress
|
147 |
-
if ( $offset === false ) {
|
148 |
-
|
149 |
-
set_transient( $transient_key, $number, HOUR_IN_SECONDS );
|
150 |
-
$limit = "LIMIT 0,{$number}";
|
151 |
-
|
152 |
-
}
|
153 |
-
|
154 |
-
// While in loop, we need to keep track of our progress
|
155 |
-
else {
|
156 |
-
|
157 |
-
delete_transient( $transient_key );
|
158 |
-
set_transient( $transient_key, $offset + $number, HOUR_IN_SECONDS );
|
159 |
-
$limit = "LIMIT {$offset},{$number}";
|
160 |
-
|
161 |
-
}
|
162 |
-
|
163 |
-
// Save total rows so we can check when we are finished
|
164 |
-
$select = "SQL_CALC_FOUND_ROWS " . $select;
|
165 |
-
|
166 |
-
// Used to store the time at which tomorrows run should be running
|
167 |
-
$original_start = mycred_get_option( 'mycred_todays_compound_started', false );
|
168 |
-
if ( $original_start === false )
|
169 |
-
update_option( 'mycred_todays_compound_started', $this->now );
|
170 |
-
|
171 |
-
}
|
172 |
-
|
173 |
-
// Should be able to run through 1500 users on most sites
|
174 |
-
else {
|
175 |
-
wp_schedule_single_event( ( $this->now + DAY_IN_SECONDS ), $this->cron_compound_key );
|
176 |
-
}
|
177 |
-
|
178 |
-
$format = '%d';
|
179 |
-
if ( $this->core->format['decimals'] > 0 )
|
180 |
-
$format = '%f';
|
181 |
-
|
182 |
-
$wheres = array();
|
183 |
-
$wheres[] = $wpdb->prepare( "meta_key = %s", $this->mycred_type );
|
184 |
-
$wheres[] = $wpdb->prepare( "meta_value != {$format}", $this->core->zero() );
|
185 |
-
|
186 |
-
// Check if we need to exclude certain users
|
187 |
-
$excluded = $this->get_excluded_user_ids();
|
188 |
-
if ( ! empty( $excluded ) )
|
189 |
-
$wheres[] = "user_id NOT IN (" . implode( ', ', $excluded ) . ")";
|
190 |
-
|
191 |
-
// Apply minimum balance requirement (if used)
|
192 |
-
$minimum = ( ( $this->prefs['min_balance'] != '' ) ? $this->core->number( $this->prefs['min_balance'] ) : 0 );
|
193 |
-
if ( $minimum > 0 )
|
194 |
-
$wheres[] = $wpdb->prepare( "meta_value >= {$format}", $minimum );
|
195 |
-
|
196 |
-
// A few items we need for calculations
|
197 |
-
$days_in_year = $this->get_days_in_year();
|
198 |
-
$period = apply_filters( 'mycred_compound_period', 1, $this );
|
199 |
-
if ( $period > 0 ) $period = ( $period / $days_in_year );
|
200 |
-
|
201 |
-
// Get the balance key
|
202 |
-
$balance_key = mycred_get_meta_key( $this->mycred_type );
|
203 |
-
|
204 |
-
// Construct the WHERE statement
|
205 |
-
$wheres = implode( ' AND ', $wheres );
|
206 |
-
|
207 |
-
// Run query
|
208 |
-
$user_balances = $wpdb->get_results( "SELECT {$select} FROM {$wpdb->usermeta} WHERE {$wheres} ORDER BY umeta_id ASC {$limit};" );
|
209 |
-
|
210 |
-
if ( ! empty( $user_balances ) ) {
|
211 |
-
|
212 |
-
// Loop through each balance
|
213 |
-
foreach ( $user_balances as $entry ) {
|
214 |
-
|
215 |
-
$balance = (float) $entry->value;
|
216 |
-
|
217 |
-
// Do not apply an interest on negative values
|
218 |
-
if ( $balance <= $this->core->zero() && apply_filters( 'mycred_compound_negative_interest', false, $this ) === false ) continue;
|
219 |
-
|
220 |
-
// Get the interest we have earned up until now
|
221 |
-
$saved_interest = mycred_get_user_meta( $entry->user_id, $this->compound_meta_key, '', true );
|
222 |
-
if ( $saved_interest == '' ) $saved_interest = 0;
|
223 |
-
|
224 |
-
// Allow customization of the calculated interest
|
225 |
-
$interest_rate = $this->get_users_interest_rate( $entry->user_id, $this->prefs['rate']['amount'] );
|
226 |
-
if ( $interest_rate > 0 ) {
|
227 |
-
|
228 |
-
// Compound interest
|
229 |
-
$interest_rate = $interest_rate / 100;
|
230 |
-
$interest = ( ( $balance + $saved_interest ) * $interest_rate ) * $period;
|
231 |
-
|
232 |
-
// Save the new interest
|
233 |
-
mycred_update_user_meta( $entry->user_id, $this->compound_meta_key, '', $interest );
|
234 |
-
|
235 |
-
}
|
236 |
-
|
237 |
-
// NEXT!
|
238 |
-
|
239 |
-
}
|
240 |
-
|
241 |
-
}
|
242 |
-
|
243 |
-
// On large sites, check if we finished.
|
244 |
-
if ( $limit != '' ) {
|
245 |
-
|
246 |
-
$offset += $number;
|
247 |
-
$total_rows = $wpdb->get_var( 'SELECT FOUND_ROWS()' );
|
248 |
-
|
249 |
-
if ( count( $user_balances ) < $number || $offset > $total_rows ) {
|
250 |
-
|
251 |
-
// Always clean up after ourselves
|
252 |
-
delete_transient( $transient_key );
|
253 |
-
|
254 |
-
// Get the time we should have started
|
255 |
-
$original_start = (int) mycred_get_option( 'mycred_todays_compound_started', $this->now );
|
256 |
-
delete_option( 'mycred_todays_compound_started' );
|
257 |
-
|
258 |
-
// Schedule tomorrows run
|
259 |
-
wp_schedule_single_event( ( $original_start + DAY_IN_SECONDS ), $this->cron_compound_key );
|
260 |
-
|
261 |
-
}
|
262 |
-
|
263 |
-
}
|
264 |
-
|
265 |
-
}
|
266 |
-
|
267 |
-
/**
|
268 |
-
* Do Interest Payout
|
269 |
-
* Handles payouts of pending compounded interests.
|
270 |
-
* @since 1.5.2
|
271 |
-
* @version 1.2
|
272 |
-
*/
|
273 |
-
public function do_interest_payout() {
|
274 |
-
|
275 |
-
global $wpdb;
|
276 |
-
|
277 |
-
$now = $this->now;
|
278 |
-
|
279 |
-
// Default number of balances we will be running through for now
|
280 |
-
$number = absint( apply_filters( 'mycred_compound_pay_max_limit', 1500, $this ) );
|
281 |
-
$total_rows = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->usermeta} WHERE meta_key = %s;", $this->compound_meta_key ) );
|
282 |
-
|
283 |
-
// If we have more then what can handle in one go, schedule in the next run in 2 minutes time
|
284 |
-
if ( $total_rows > $number ) {
|
285 |
-
|
286 |
-
// Schedule our next event in 2 minutes
|
287 |
-
wp_schedule_single_event( ( $now + 180 ), $this->cron_payout_key );
|
288 |
-
|
289 |
-
// Used to store the time at which the next run should be running
|
290 |
-
$original_start = mycred_get_option( 'mycred_todays_compound_payout_started', false );
|
291 |
-
if ( $original_start === false )
|
292 |
-
update_option( 'mycred_todays_compound_payout_started', $now );
|
293 |
-
|
294 |
-
}
|
295 |
-
|
296 |
-
// Get pending interests
|
297 |
-
$pending_interests = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->usermeta} WHERE meta_key = %s LIMIT {$number};", $this->compound_meta_key ) );
|
298 |
-
|
299 |
-
if ( ! empty( $pending_interests ) ) {
|
300 |
-
|
301 |
-
// Loop through each
|
302 |
-
foreach ( $pending_interests as $entry ) {
|
303 |
-
|
304 |
-
// Make sure the payout is unique
|
305 |
-
if ( ! $this->core->has_entry( $this->log_reference, $entry->umeta_id, $entry->user_id, '', $this->mycred_type ) ) {
|
306 |
-
|
307 |
-
// Attempt to pay
|
308 |
-
$payout = $this->core->add_creds(
|
309 |
-
$this->log_reference,
|
310 |
-
$entry->user_id,
|
311 |
-
$entry->meta_value,
|
312 |
-
$this->prefs['log'],
|
313 |
-
$entry->umeta_id,
|
314 |
-
'',
|
315 |
-
$this->mycred_type
|
316 |
-
);
|
317 |
-
|
318 |
-
// Payout successfull
|
319 |
-
if ( $payout ) {
|
320 |
-
$total_rows--;
|
321 |
-
mycred_delete_user_meta( $entry->user_id, $this->compound_meta_key );
|
322 |
-
}
|
323 |
-
|
324 |
-
// NEXT!
|
325 |
-
|
326 |
-
}
|
327 |
-
|
328 |
-
}
|
329 |
-
|
330 |
-
}
|
331 |
-
|
332 |
-
// Nothing more to payout
|
333 |
-
if ( $total_rows <= 0 ) {
|
334 |
-
|
335 |
-
// Get the time we should have done our scheduling
|
336 |
-
$original_start = (int) mycred_get_option( 'mycred_todays_compound_payout_started', $now );
|
337 |
-
if ( $original_start != $now )
|
338 |
-
delete_option( 'mycred_todays_compound_payout_started' );
|
339 |
-
|
340 |
-
// Schedule next run
|
341 |
-
$next = $original_start + mycred_banking_get_next_payout( $this->prefs['rate']['pay_out'] );
|
342 |
-
wp_schedule_single_event( $next, $this->cron_payout_key );
|
343 |
-
|
344 |
-
}
|
345 |
-
|
346 |
-
}
|
347 |
-
|
348 |
-
/**
|
349 |
-
* Get Pending Interest
|
350 |
-
* Returns the total amount of points that have been compounded but not yet paid out.
|
351 |
-
* @since 1.7
|
352 |
-
* @version 1.0
|
353 |
-
*/
|
354 |
-
protected function get_pending_interest() {
|
355 |
-
|
356 |
-
global $wpdb;
|
357 |
-
|
358 |
-
$amount = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s;", $this->compound_meta_key ) );
|
359 |
-
if ( $amount === NULL ) $amount = 0;
|
360 |
-
|
361 |
-
return $this->core->number( $amount );
|
362 |
-
|
363 |
-
}
|
364 |
-
|
365 |
-
/**
|
366 |
-
* Get Users Interet Rate
|
367 |
-
* Takes into account any custom rates that might have been saved for the given user.
|
368 |
-
* @since 1.7
|
369 |
-
* @version 1.0
|
370 |
-
*/
|
371 |
-
public function get_users_interest_rate( $user_id = 0, $default = 0 ) {
|
372 |
-
|
373 |
-
$rate = $default;
|
374 |
-
$saved = mycred_get_user_meta( $user_id, 'mycred_banking_rate_' . $this->mycred_type, '', true );
|
375 |
-
if ( strlen( $saved ) > 0 )
|
376 |
-
$rate = $saved;
|
377 |
-
|
378 |
-
return apply_filters( 'mycred_get_users_interest_rate', $rate, $user_id, $default, $this );
|
379 |
-
|
380 |
-
}
|
381 |
-
|
382 |
-
/**
|
383 |
-
* Settings Screen
|
384 |
-
* Renders the service settings on the Banking page in the admin area.
|
385 |
-
* @since 1.2
|
386 |
-
* @version 1.3
|
387 |
-
*/
|
388 |
-
public function preferences() {
|
389 |
-
|
390 |
-
$cyear = $cmonth = $cday = $chour = $cminute = $csecond = '';
|
391 |
-
$pyear = $pmonth = $pday = $phour = $pminute = $psecond = '';
|
392 |
-
$editable_roles = array_reverse( get_editable_roles() );
|
393 |
-
|
394 |
-
// If scheduled, split the date and time of the cron timestamp
|
395 |
-
$compound = wp_next_scheduled( $this->cron_compound_key );
|
396 |
-
if ( $compound !== false ) {
|
397 |
-
|
398 |
-
$compound = $this->timestamp_to_date( $compound );
|
399 |
-
|
400 |
-
$date = date( 'Y-m-d', $compound );
|
401 |
-
list ( $cyear, $cmonth, $cday ) = explode( '-', $date );
|
402 |
-
|
403 |
-
$time = date( 'H:i:s', $compound );
|
404 |
-
list ( $chour, $cminute, $cseconds ) = explode( ':', $time );
|
405 |
-
|
406 |
-
}
|
407 |
-
|
408 |
-
// If scheduled, split the date and time of the cron timestamp
|
409 |
-
$payout = wp_next_scheduled( $this->cron_payout_key );
|
410 |
-
if ( $payout !== false ) {
|
411 |
-
|
412 |
-
$payout = $this->timestamp_to_date( $payout );
|
413 |
-
|
414 |
-
$date = date( 'Y-m-d', $payout );
|
415 |
-
list ( $pyear, $pmonth, $pday ) = explode( '-', $date );
|
416 |
-
|
417 |
-
$time = date( 'H:i:s', $payout );
|
418 |
-
list ( $phour, $pminute, $pseconds ) = explode( ':', $time );
|
419 |
-
|
420 |
-
}
|
421 |
-
|
422 |
-
?>
|
423 |
-
<div class="row">
|
424 |
-
<div class="col-sm-6">
|
425 |
-
|
426 |
-
<table class="widefat fixed striped" cellpadding="0" cellspacing="0">
|
427 |
-
<thead>
|
428 |
-
<tr>
|
429 |
-
<th style="width: 100%;" colspan="4"><?php _e( 'Daily Compound Schedule', 'mycred' ); ?></th>
|
430 |
-
</tr>
|
431 |
-
<tr>
|
432 |
-
<th style="width: 30%;"><?php _e( 'Year', 'mycred' ); ?></th>
|
433 |
-
<th style="width: 20%;"><?php _e( 'Month', 'mycred' ); ?></th>
|
434 |
-
<th style="width: 20%;"><?php _e( 'Day', 'mycred' ); ?></th>
|
435 |
-
<th style="width: 30%;"><?php _e( 'Time', 'mycred' ); ?></th>
|
436 |
-
</tr>
|
437 |
-
</thead>
|
438 |
-
<tbody>
|
439 |
-
<tr>
|
440 |
-
<td><input type="text" name="<?php echo $this->field_name( array( 'cron_compound' => 'year' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_compound' => 'year' ) ); ?>" class="form-control" placeholder="<?php echo $cyear; ?>" maxlength="4" size="6" value="" /></td>
|
441 |
-
<td><input type="text" name="<?php echo $this->field_name( array( 'cron_compound' => 'month' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_compound' => 'month' ) ); ?>" class="form-control" placeholder="<?php echo $cmonth; ?>" maxlength="2" size="4" value="" /></td>
|
442 |
-
<td><input type="text" name="<?php echo $this->field_name( array( 'cron_compound' => 'day' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_compound' => 'day' ) ); ?>" class="form-control" placeholder="<?php echo $cday; ?>" maxlength="2" size="4" value="" /></td>
|
443 |
-
<td><?php echo $this->time_select( $this->field_name( array( 'cron_compound' => 'time' ) ), $this->field_id( array( 'cron_compound' => 'time' ) ), $compound ); ?></td>
|
444 |
-
</tr>
|
445 |
-
</tbody>
|
446 |
-
</table>
|
447 |
-
|
448 |
-
</div>
|
449 |
-
<div class="col-sm-6">
|
450 |
-
|
451 |
-
<table class="widefat fixed striped" cellpadding="0" cellspacing="0">
|
452 |
-
<thead>
|
453 |
-
<tr>
|
454 |
-
<th style="width: 100%;" colspan="4"><?php _e( 'Payout Schedule', 'mycred' ); ?></th>
|
455 |
-
</tr>
|
456 |
-
<tr>
|
457 |
-
<th style="width: 30%;"><?php _e( 'Year', 'mycred' ); ?></th>
|
458 |
-
<th style="width: 20%;"><?php _e( 'Month', 'mycred' ); ?></th>
|
459 |
-
<th style="width: 20%;"><?php _e( 'Day', 'mycred' ); ?></th>
|
460 |
-
<th style="width: 30%;"><?php _e( 'Time', 'mycred' ); ?></th>
|
461 |
-
</tr>
|
462 |
-
</thead>
|
463 |
-
<tbody>
|
464 |
-
<tr>
|
465 |
-
<td><input type="text" name="<?php echo $this->field_name( array( 'cron_payout' => 'year' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_payout' => 'year' ) ); ?>" class="form-control" placeholder="<?php echo $pyear; ?>" maxlength="4" size="6" value="" /></td>
|
466 |
-
<td><input type="text" name="<?php echo $this->field_name( array( 'cron_payout' => 'month' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_payout' => 'month' ) ); ?>" class="form-control" placeholder="<?php echo $pmonth; ?>" maxlength="2" size="4" value="" /></td>
|
467 |
-
<td><input type="text" name="<?php echo $this->field_name( array( 'cron_payout' => 'day' ) ); ?>" id="<?php echo $this->field_id( array( 'cron_payout' => 'day' ) ); ?>" class="form-control" placeholder="<?php echo $pday; ?>" maxlength="2" size="4" value="" /></td>
|
468 |
-
<td><?php echo $this->time_select( $this->field_name( array( 'cron_payout' => 'time' ) ), $this->field_id( array( 'cron_payout' => 'time' ) ), $payout ); ?></td>
|
469 |
-
</tr>
|
470 |
-
</tbody>
|
471 |
-
</table>
|
472 |
-
|
473 |
-
</div>
|
474 |
-
</div>
|
475 |
-
<div class="row">
|
476 |
-
<div class="col-sm-6">
|
477 |
-
<h3><?php _e( 'Setup', 'mycred' ); ?></h3>
|
478 |
-
<div class="row">
|
479 |
-
<div class="col-sm-3 col-xs-10">
|
480 |
-
<div class="form-group">
|
481 |
-
<label for="<?php echo $this->field_id( array( 'rate' => 'amount' ) ); ?>"><?php _e( 'Interest Rate', 'mycred' ); ?></label>
|
482 |
-
<input type="text" name="<?php echo $this->field_name( array( 'rate' => 'amount' ) ); ?>" id="<?php echo $this->field_id( array( 'rate' => 'amount' ) ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo esc_attr( $this->prefs['rate']['amount'] ); ?>" />
|
483 |
-
</div>
|
484 |
-
</div>
|
485 |
-
<div class="col-xs-1">
|
486 |
-
<div class="form-group">
|
487 |
-
<label> </label>
|
488 |
-
<p class="form-control-static">%</p>
|
489 |
-
</div>
|
490 |
-
</div>
|
491 |
-
<div class="col-sm-4 col-xs-6">
|
492 |
-
<div class="form-group">
|
493 |
-
<label for="<?php echo $this->field_id( array( 'name' => 'pay_out' ) ); ?>"><?php _e( 'Payout Frequency', 'mycred' ); ?></label>
|
494 |
-
<?php $this->timeframe_dropdown( array( 'rate' => 'pay_out' ), false, false ); ?>
|
495 |
-
</div>
|
496 |
-
</div>
|
497 |
-
<div class="col-sm-4 col-xs-6">
|
498 |
-
<div class="form-group">
|
499 |
-
<label for="<?php echo $this->field_id( 'min_balance' ); ?>"><?php _e( 'Minimum Balance', 'mycred' ); ?></label>
|
500 |
-
<input type="text" name="<?php echo $this->field_name( 'min_balance' ); ?>" id="<?php echo $this->field_id( 'min_balance' ); ?>" class="form-control" placeholder="<?php _e( 'Required', 'mycred' ); ?>" value="<?php echo $this->core->number( $this->prefs['min_balance'] ); ?>" />
|
501 |
-
</div>
|
502 |
-
</div>
|
503 |
-
</div>
|
504 |
-
</div>
|
505 |
-
<div class="col-sm-6">
|
506 |
-
<h3><?php _e( 'Payout Log Table', 'mycred' ); ?></h3>
|
507 |
-
<div class="row">
|
508 |
-
<div class="col-xs-12">
|
509 |
-
<div class="form-group">
|
510 |
-
<label for="<?php echo $this->field_id( 'log' ); ?>"><?php _e( 'Log Template', 'mycred' ); ?></label>
|
511 |
-
<input type="text" name="<?php echo $this->field_name( 'log' ); ?>" id="<?php echo $this->field_id( 'log' ); ?>" class="form-control" value="<?php echo esc_attr( $this->prefs['log'] ); ?>" />
|
512 |
-
</div>
|
513 |
-
</div>
|
514 |
-
</div>
|
515 |
-
</div>
|
516 |
-
</div>
|
517 |
-
<div class="row">
|
518 |
-
<div class="col-xs-12">
|
519 |
-
<p><span class="description"><?php _e( 'Changing the payout period once the service is enabled, will only take effect once the currently scheduled payout runs. To change this, you will also need to adjust the payout schedule above.', 'mycred' ); ?></span></p>
|
520 |
-
</div>
|
521 |
-
</div>
|
522 |
-
<div class="row">
|
523 |
-
<div class="col-sm-6">
|
524 |
-
<h3><?php _e( 'Exclude by ID', 'mycred' ); ?></h3>
|
525 |
-
<div class="row">
|
526 |
-
<div class="col-xs-12">
|
527 |
-
<div class="form-group">
|
528 |
-
<label for="<?php echo $this->field_id( 'exclude_ids' ); ?>"><?php _e( 'Comma separated list of user IDs', 'mycred' ); ?></label>
|
529 |
-
<input type="text" name="<?php echo $this->field_name( 'exclude_ids' ); ?>" id="<?php echo $this->field_id( 'exclude_ids' ); ?>" class="form-control" placeholder="<?php _e( 'Comma separated list of user IDs', 'mycred' ); ?>" value="<?php echo esc_attr( $this->prefs['exclude_ids'] ); ?>" />
|
530 |
-
</div>
|
531 |
-
</div>
|
532 |
-
</div>
|
533 |
-
</div>
|
534 |
-
<div class="col-sm-6">
|
535 |
-
<h3><?php _e( 'Exclude by Role', 'mycred' ); ?></h3>
|
536 |
-
<div class="row">
|
537 |
-
<div class="col-xs-12">
|
538 |
-
<div class="form-group">
|
539 |
-
<label for="<?php echo $this->field_id( 'exclude_roles' ); ?>"><?php _e( 'Roles to exclude', 'mycred' ); ?></label>
|
540 |
-
</div>
|
541 |
-
<div class="row">
|
542 |
-
<?php
|
543 |
-
|
544 |
-
foreach ( $editable_roles as $role => $details ) {
|
545 |
-
|
546 |
-
$name = translate_user_role( $details['name'] );
|
547 |
-
|
548 |
-
echo '<div class="col-xs-6"><div class="checkbox"><label for="' . $this->field_id( 'exclude-roles-' . $role ) . '"><input type="checkbox" name="' . $this->field_name( 'exclude_roles][' ) . '" id="' . $this->field_id( 'exclude-roles-' . $role ) . '" value="' . esc_attr( $role ) . '"';
|
549 |
-
if ( in_array( $role, (array) $this->prefs['exclude_roles'] ) ) echo ' checked="checked"';
|
550 |
-
echo ' />' . $name . '</label></div></div>';
|
551 |
-
}
|
552 |
-
|
553 |
-
?>
|
554 |
-
</div>
|
555 |
-
</div>
|
556 |
-
</div>
|
557 |
-
</div>
|
558 |
-
</div>
|
559 |
-
<?php
|
560 |
-
|
561 |
-
do_action( 'mycred_banking_compound_interest', $this );
|
562 |
-
|
563 |
-
}
|
564 |
-
|
565 |
-
/**
|
566 |
-
* Sanitise Preferences
|
567 |
-
* @since 1.2
|
568 |
-
* @version 1.4
|
569 |
-
*/
|
570 |
-
public function sanitise_preferences( $post ) {
|
571 |
-
|
572 |
-
$new_settings = array( 'rate' => array() );
|
573 |
-
$new_settings['rate']['amount'] = str_replace( ',', '.', sanitize_text_field( $post['rate']['amount'] ) );
|
574 |
-
if ( $new_settings['rate']['amount'] == '' ) $new_settings['rate']['amount'] = 0;
|
575 |
-
|
576 |
-
$new_settings['rate']['pay_out'] = sanitize_text_field( $post['rate']['pay_out'] );
|
577 |
-
|
578 |
-
$new_settings['log'] = sanitize_text_field( $post['log'] );
|
579 |
-
$new_settings['min_balance'] = $this->core->number( str_replace( ',', '.', sanitize_text_field( $post['min_balance'] ) ) );
|
580 |
-
$new_settings['exclude_ids'] = sanitize_text_field( $post['exclude_ids'] );
|
581 |
-
|
582 |
-
if ( ! isset( $post['exclude_roles'] ) )
|
583 |
-
$post['exclude_roles'] = array();
|
584 |
-
|
585 |
-
$new_settings['exclude_roles'] = $post['exclude_roles'];
|
586 |
-
|
587 |
-
$rescheduled = false;
|
588 |
-
|
589 |
-
// Re-schedule compound cron job
|
590 |
-
if ( $post['cron_compound']['year'] != '' && $post['cron_compound']['month'] != '' && $post['cron_compound']['day'] != '' && $post['cron_compound']['time'] != '' ) {
|
591 |
-
|
592 |
-
$year = absint( $post['cron_compound']['year'] );
|
593 |
-
$month = zeroise( absint( $post['cron_compound']['month'] ), 2 );
|
594 |
-
$day = zeroise( absint( $post['cron_compound']['day'] ), 2 );
|
595 |
-
|
596 |
-
$compound = $this->date_to_timestamp( $year . '-' . $month . '-' . $day . ' ' . $post['cron_compound']['time'] . ':00' );
|
597 |
-
if ( $compound !== false && $compound > $this->now ) {
|
598 |
-
|
599 |
-
$timestamp = wp_next_scheduled( $this->cron_compound_key );
|
600 |
-
if ( $timestamp !== false ) {
|
601 |
-
wp_clear_scheduled_hook( $this->cron_compound_key );
|
602 |
-
$rescheduled = true;
|
603 |
-
}
|
604 |
-
|
605 |
-
wp_schedule_single_event( $compound, $this->cron_compound_key );
|
606 |
-
|
607 |
-
}
|
608 |
-
|
609 |
-
}
|
610 |
-
|
611 |
-
// Re-schedule payout cron job
|
612 |
-
if ( $post['cron_payout']['year'] != '' && $post['cron_payout']['month'] != '' && $post['cron_payout']['day'] != '' && $post['cron_payout']['time'] != '' ) {
|
613 |
-
|
614 |
-
$year = absint( $post['cron_payout']['year'] );
|
615 |
-
$month = zeroise( absint( $post['cron_payout']['month'] ), 2 );
|
616 |
-
$day = zeroise( absint( $post['cron_payout']['day'] ), 2 );
|
617 |
-
|
618 |
-
$payout = $this->date_to_timestamp( $year . '-' . $month . '-' . $day . ' ' . $post['cron_payout']['time'] . ':00' );
|
619 |
-
if ( $payout !== false && $payout > $this->now ) {
|
620 |
-
|
621 |
-
$timestamp = wp_next_scheduled( $this->cron_payout_key );
|
622 |
-
if ( $timestamp !== false ) {
|
623 |
-
wp_clear_scheduled_hook( $this->cron_payout_key );
|
624 |
-
$rescheduled = true;
|
625 |
-
}
|
626 |
-
|
627 |
-
wp_schedule_single_event( $payout, $this->cron_payout_key );
|
628 |
-
|
629 |
-
}
|
630 |
-
|
631 |
-
}
|
632 |
-
|
633 |
-
return apply_filters( 'mycred_banking_save_interest', $new_settings, $this, $rescheduled );
|
634 |
-
|
635 |
-
}
|
636 |
-
|
637 |
-
/**
|
638 |
-
* User Screen
|
639 |
-
* @since 1.7
|
640 |
-
* @version 1.0
|
641 |
-
*/
|
642 |
-
public function user_screen( $user ) {
|
643 |
-
|
644 |
-
// Only visible to admins
|
645 |
-
if ( ! mycred_is_admin() ) return;
|
646 |
-
|
647 |
-
$users_rate = mycred_get_user_meta( $user->ID, 'mycred_banking_rate_' . $this->mycred_type, '', true );
|
648 |
-
|
649 |
-
?>
|
650 |
-
<table class="form-table">
|
651 |
-
<tr>
|
652 |
-
<th><label for="compoun-interest-rate-<?php echo $this->mycred_type; ?>"><?php _e( 'Interest Rate', 'mycred' ); echo ' (' . $this->core->plural() . ')'; ?></label></th>
|
653 |
-
<td>
|
654 |
-
<input type="text" size="8" name="mycred_interest_rate[<?php echo $this->mycred_type; ?>][rate]" id="compoun-interest-rate-<?php echo $this->mycred_type; ?>" placeholder="<?php echo esc_attr( $this->prefs['rate']['amount'] . ' %' ); ?>" value="<?php echo esc_attr( $users_rate ); ?>" /> %
|
655 |
-
<p><span class="description"><?php _e( 'Leave empty to pay the default rate.', 'mycred' ); ?></span></p>
|
656 |
-
</td>
|
657 |
-
</tr>
|
658 |
-
</table>
|
659 |
-
<?php
|
660 |
-
|
661 |
-
}
|
662 |
-
|
663 |
-
/**
|
664 |
-
* Save User Override
|
665 |
-
* @since 1.5.2
|
666 |
-
* @version 1.0.2
|
667 |
-
*/
|
668 |
-
function save_custom_rate( $user_id ) {
|
669 |
-
|
670 |
-
// Only visible to admins
|
671 |
-
if ( ! mycred_is_admin() ) return;
|
672 |
-
|
673 |
-
if ( isset( $_POST['mycred_interest_rate'] ) && array_key_exists( $this->mycred_type, $_POST['mycred_interest_rate'] ) ) {
|
674 |
-
|
675 |
-
$rate = sanitize_text_field( $_POST['mycred_interest_rate'][ $this->mycred_type ]['rate'] );
|
676 |
-
if ( strlen( $rate ) > 0 ) {
|
677 |
-
|
678 |
-
$rate = str_replace( ',', '.', $rate );
|
679 |
-
if ( $rate != $this->prefs['rate']['amount'] )
|
680 |
-
mycred_update_user_meta( $user_id, 'mycred_banking_rate_' . $this->mycred_type, '', $rate );
|
681 |
-
else
|
682 |
-
mycred_delete_user_meta( $user_id, 'mycred_banking_rate_' . $this->mycred_type );
|
683 |
-
|
684 |
-
}
|
685 |
-
|
686 |
-
}
|
687 |
-
|
688 |
-
}
|
689 |
-
|
690 |
-
}
|
691 |
-
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addons/banking/services/mycred-service-payouts.php
DELETED
@@ -1,1002 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
if ( ! defined( 'myCRED_VERSION' ) ) exit;
|
3 |
-
|
4 |
-
/**
|
5 |
-
* myCRED Bank Service - Recurring Payouts
|
6 |
-
* @since 1.2
|
7 |
-
* @version 1.2
|
8 |
-
*/
|
9 |
-
if ( ! class_exists( 'myCRED_Banking_Service_Payouts' ) ) :
|
10 |
-
class myCRED_Banking_Service_Payouts extends myCRED_Service {
|
11 |
-
|
12 |
-
public $default_schedule = array();
|
13 |
-
public $statuses = array();
|
14 |
-
public $schedules = array();
|
15 |
-
public $log_reference = '';
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Construct
|
19 |
-
*/
|
20 |
-
function __construct( $service_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) {
|
21 |
-
|
22 |
-
parent::__construct( array(
|
23 |
-
'id' => 'payouts',
|
24 |
-
'defaults' => array()
|
25 |
-
), $service_prefs, $type );
|
26 |
-
|
27 |
-
$this->default_schedule = mycred_get_recurring_payout_defaults();
|
28 |
-
|
29 |
-
$this->statuses = array(
|
30 |
-
0 => __( 'Waiting to Start', 'mycred' ),
|
31 |
-
1 => __( 'Active', 'mycred' ),
|
32 |
-
2 => __( 'Running', 'mycred' ),
|
33 |
-
3 => __( 'Finished', 'mycred' ),
|
34 |
-
4 => __( 'Stopped', 'mycred' )
|
35 |
-
);
|
36 |
-
|
37 |
-
$this->schedules = mycred_get_recurring_payout_schedules( $type );
|
38 |
-
$this->log_reference = apply_filters( 'mycred_bank_recurring_reference', 'recurring', $this );
|
39 |
-
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Activate Service
|
44 |
-
* @since 1.5.2
|
45 |
-
* @version 1.1
|
46 |
-
*/
|
47 |
-
public function activate() {
|
48 |
-
|
49 |
-
if ( ! empty( $this->schedules ) ) {
|
50 |
-
foreach ( $this->schedules as $schedule_id => $setup ) {
|
51 |
-
|
52 |
-
// Status 3 = finished and Status 4 = Stopped
|
53 |
-
if ( absint( $setup['status'] ) > 2 ) continue;
|
54 |
-
|
55 |
-
$next_run = mycred_banking_get_next_payout( $setup['frequency'], $setup['last_run'] );
|
56 |
-
$timestamp = wp_next_scheduled( 'mycred-recurring-' . $schedule_id );
|
57 |
-
|
58 |
-
if ( $timestamp !== false )
|
59 |
-
$next_run = $timestamp;
|
60 |
-
|
61 |
-
// We did not miss our schedule, lets re-schedule
|
62 |
-
if ( $next_run > $this->now )
|
63 |
-
wp_schedule_single_event( $next_run, 'mycred-recurring-' . $schedule_id, array( 'id' => $schedule_id ) );
|
64 |
-
|
65 |
-
// Upps, we missed it, clear and disable this setup
|
66 |
-
else {
|
67 |
-
|
68 |
-
$setup['status'] = 4;
|
69 |
-
mycred_update_recurring_payout( $schedule_id, $setup, $this->mycred_type );
|
70 |
-
|
71 |
-
if ( $timestamp !== false )
|
72 |
-
wp_clear_scheduled_hook( 'mycred-recurring-' . $schedule_id, array( 'id' => $schedule_id ) );
|
73 |
-
|
74 |
-
}
|
75 |
-
|
76 |
-
}
|
77 |
-
}
|
78 |
-
|
79 |
-
}
|
80 |
-
|
81 |
-
/**
|
82 |
-
* Deactivation
|
83 |
-
* @since 1.2
|
84 |
-
* @version 1.1
|
85 |
-
*/
|
86 |
-
public function deactivate() {
|
87 |
-
|
88 |
-
if ( ! empty( $this->schedules ) ) {
|
89 |
-
foreach ( $this->schedules as $schedule_id => $setup ) {
|
90 |
-
|
91 |
-
// Status 3 = finished and Status 4 = Stopped
|
92 |
-
if ( absint( $setup['status'] ) > 2 ) continue;
|
93 |
-
|
94 |
-
wp_clear_scheduled_hook( 'mycred-recurring-' . $schedule_id, array( 'id' => $schedule_id ) );
|
95 |
-
|
96 |
-
}
|
97 |
-
}
|
98 |
-
|
99 |
-
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Run
|
103 |
-
* @since 1.2
|
104 |
-
* @version 1.1
|
105 |
-
*/
|
106 |
-
public function run() {
|
107 |
-
|
108 |
-
if ( ! empty( $this->schedules ) ) {
|
109 |
-
foreach ( $this->schedules as $schedule_id => $setup ) {
|
110 |
-
|
111 |
-
// Status 3 = finished and Status 4 = Stopped
|
112 |
-
if ( absint( $setup['status'] ) > 2 ) continue;
|
113 |
-
|
114 |
-
add_action( 'mycred-recurring-' . $schedule_id, array( $this, 'run_schedule' ) );
|
115 |
-
|
116 |
-
}
|
117 |
-
}
|
118 |
-
|
119 |
-
}
|
120 |
-
|
121 |
-
/**
|
122 |
-
* Run Schedule
|
123 |
-
* @since 1.2
|
124 |
-
* @version 1.1
|
125 |
-
*/
|
126 |
-
public function run_schedule( $schedule_id = NULL ) {
|
127 |
-
|
128 |
-
if ( $schedule_id === NULL ) return;
|
129 |
-
|
130 |
-
// Get settings
|
131 |
-
$setup = mycred_get_recurring_payout( $schedule_id, $this->mycred_type );
|
132 |
-
$instance = 'mycred-recurring-' . $schedule_id;
|
133 |
-
$infinite_run = ( ( $setup['runs_remaining'] < 0 ) ? true : false );
|
134 |
-
$runs_left = absint( $setup['runs_remaining'] );
|
135 |
-
$next_run = mycred_banking_get_next_payout( $setup['frequency'], $this->now );
|
136 |
-
|
137 |
-
// Need to make sure amount is not zero
|
138 |
-
if ( $setup['payout'] == '' || $this->core->number( $setup['payout'] ) === $this->core->zero() ) return;
|
139 |
-
|
140 |
-
// No runs remaining - Move to finish
|
141 |
-
if ( ! $infinite_run && $runs_left === 0 ) {
|
142 |
-
|
143 |
-
$setup['status'] = 3;
|
144 |
-
$setup['last_run'] = $this->now;
|
145 |
-
|
146 |
-
mycred_update_recurring_payout( $schedule_id, $setup, $this->mycred_type );
|
147 |
-
wp_clear_scheduled_hook( $instance );
|
148 |
-
|
149 |
-
return;
|
150 |
-
|
151 |
-
}
|
152 |
-
|
153 |
-
// No need to run if the central bank is out of funds
|
154 |
-
$settings = mycred_get_banking_addon_settings( NULL, $this->mycred_type );
|
155 |
-
$ignore_central_bank = false;
|
156 |
-
if ( in_array( 'central', $settings['active'] ) && $setup['ignore_central'] == 1 )
|
157 |
-
$ignore_central_bank = true;
|
158 |
-
|
159 |
-
// Default number of balances we will be running through for now
|
160 |
-
$number = absint( apply_filters( 'mycred_recurring_max_limit', 1500, $this ) );
|
161 |
-
$original_start = mycred_get_option( 'mycred-recurring-next-run-' . $schedule_id, false );
|
162 |
-
|
163 |
-
$single_instance = true;
|
164 |
-
$transient_key = 'mycred-recurring-' . $schedule_id;
|
165 |
-
$offset = get_transient( $transient_key );
|
166 |
-
if ( $offset === false ) $offset = 0;
|
167 |
-
|
168 |
-
// Get eligible users
|
169 |
-
$eligeble_users = $this->get_eligible_users( $number, $offset, $setup );
|
170 |
-
|
171 |
-
// Check if we can do this in a single instance or if we need multiple
|
172 |
-
if ( ( $eligeble_users['total'] - $offset ) > $number ) {
|
173 |
-
|
174 |
-
$single_instance = false;
|
175 |
-
|
176 |
-
// Schedule our next event in 2 minutes
|
177 |
-
wp_schedule_single_event( ( $this->now + 180 ), $instance );
|
178 |
-
|
179 |
-
// Apply limit and set a transient to keep track of our progress
|
180 |
-
if ( $offset === 0 )
|
181 |
-
set_transient( $transient_key, $number, HOUR_IN_SECONDS );
|
182 |
-
|
183 |
-
// While in loop, we need to keep track of our progress
|
184 |
-
else {
|
185 |
-
|
186 |
-
delete_transient( $transient_key );
|
187 |
-
$offset += count( $eligeble_users['results'] );
|
188 |
-
set_transient( $transient_key, $offset, HOUR_IN_SECONDS );
|
189 |
-
|
190 |
-
}
|
191 |
-
|
192 |
-
if ( $original_start === false )
|
193 |
-
update_option( 'mycred-recurring-next-run-' . $schedule_id, $next_run );
|
194 |
-
|
195 |
-
}
|
196 |
-
|
197 |
-
// Single instance
|
198 |
-
else {
|
199 |
-
|
200 |
-
if ( $original_start === false )
|
201 |
-
$original_start = $next_run;
|
202 |
-
|
203 |
-
else {
|
204 |
-
delete_transient( $transient_key );
|
205 |
-
delete_option( 'mycred-recurring-next-run-' . $schedule_id );
|
206 |
-
}
|
207 |
-
|
208 |
-
wp_schedule_single_event( $original_start, $instance, array( 'id' => $schedule_id ) );
|
209 |
-
|
210 |
-
}
|
211 |
-
|
212 |
-
// Loop through users and payout
|
213 |
-
$missed = $completed = 0;
|
214 |
-
if ( ! empty( $eligeble_users['results'] ) ) {
|
215 |
-
|
216 |
-
foreach ( $eligeble_users['results'] as $user_id ) {
|
217 |
-
|
218 |
-
if ( ! $ignore_central_bank ) {
|
219 |
-
|
220 |
-
$paid = $this->core->add_creds(
|
221 |
-
$this->log_reference,
|
222 |
-
$user_id,
|
223 |
-
$setup['payout'],
|
224 |
-
$setup['log_template'],
|
225 |
-
0,
|
226 |
-
$schedule_id,
|
227 |
-
$this->mycred_type
|
228 |
-
);
|
229 |
-
|
230 |
-
}
|
231 |
-
|
232 |
-
// Ignore the central bank and just pay
|
233 |
-
// Curcumvents any custom code using the mycred_add, mycred_run_this and mycred_add_finished filters.
|
234 |
-
else {
|
235 |
-
|
236 |
-
$this->core->update_users_balance( $user_id, $setup['payout'], $this->mycred_type );
|
237 |
-
$this->core->add_to_log(
|
238 |
-
$this->log_reference,
|
239 |
-
$user_id,
|
240 |
-
$setup['payout'],
|
241 |
-
$setup['log_template'],
|
242 |
-
0,
|
243 |
-
$schedule_id,
|
244 |
-
$this->mycred_type
|
245 |
-
);
|
246 |
-
|
247 |
-
$paid = true;
|
248 |
-
|
249 |
-
}
|
250 |
-
|
251 |
-
if ( $paid )
|
252 |
-
$completed ++;
|
253 |
-
else
|
254 |
-
$missed ++;
|
255 |
-
|
256 |
-
}
|
257 |
-
|
258 |
-
}
|
259 |
-
|
260 |
-
if ( $setup['status'] == 0 )
|
261 |
-
$setup['status'] = 1;
|
262 |
-
|
263 |
-
$setup['total_completed'] = ( $setup['total_completed'] + $completed );
|
264 |
-
$setup['total_misses'] = ( $setup['total_misses'] + $missed );
|
265 |
-
|
266 |
-
mycred_update_recurring_payout( $schedule_id, $setup, $this->mycred_type );
|
267 |
-
|
268 |
-
// In case we finished, update the schedule and clear the CRON
|
269 |
-
if ( $single_instance ) {
|
270 |
-
|
271 |
-
if ( ! $infinite_run ) {
|
272 |
-
|
273 |
-
$runs_left--;
|
274 |
-
|
275 |
-
$setup['runs_remaining'] = $runs_left;
|
276 |
-
|
277 |
-
}
|
278 |
-
|
279 |
-
$setup['last_run'] = $this->now;
|
280 |
-
|
281 |
-
if ( ! $infinite_run && $runs_left == 0 )
|
282 |
-
$setup['status'] = 3;
|
283 |
-
|
284 |
-
mycred_update_recurring_payout( $schedule_id, $setup, $this->mycred_type );
|
285 |
-
|
286 |
-
if ( ! $infinite_run && $runs_left === 0 )
|
287 |
-
wp_clear_scheduled_hook( $instance );
|
288 |
-
|
289 |
-
}
|
290 |
-
|
291 |
-
}
|
292 |
-
|
293 |
-
/**
|
294 |
-
* Get Eligible Users
|
295 |
-
* @since 1.7
|
296 |
-
* @version 1.0
|
297 |
-
*/
|
298 |
-
public function get_eligible_users( $number = 0, $offset = 0, $setup ) {
|
299 |
-
|
300 |
-
global $wpdb;
|
301 |
-
|
302 |
-
$query_args = array();
|
303 |
-
$meta_query = array();
|
304 |
-
|
305 |
-
// Only interested in the user IDs.
|
306 |
-
$query_args['fields'] = 'ID';
|
307 |
-
$query_args['orderby'] = 'ID';
|
308 |
-
|
309 |
-
$query_args['number'] = $number;
|
310 |
-
|
311 |
-
if ( $offset > 0 )
|
312 |
-
$query_args['offset'] = $offset;
|
313 |
-
|
314 |
-
// Limit by minimum balance
|
315 |
-
if ( $setup['min_balance'] != 0 && $setup['max_balance'] == 0 )
|
316 |
-
$meta_query[] = array(
|
317 |
-
'key' => $this->mycred_type,
|
318 |
-
'value' => $this->core->number( $setup['min_balance'] ),
|
319 |
-
'compare' => '>=',
|
320 |
-
'type' => 'NUMERIC'
|
321 |
-
);
|
322 |
-
|
323 |
-
// Limit by maximum balance
|
324 |
-
elseif ( $setup['min_balance'] == 0 && $setup['max_balance'] != 0 )
|
325 |
-
$meta_query[] = array(
|
326 |
-
'key' => $this->mycred_type,
|
327 |
-
'value' => $this->core->number( $setup['max_balance'] ),
|
328 |
-
'compare' => '<',
|
329 |
-
'type' => 'NUMERIC'
|
330 |
-
);
|
331 |
-
|
332 |
-
// Range
|
333 |
-
elseif ( $setup['min_balance'] != 0 && $setup['max_balance'] != 0 )
|
334 |
-
$meta_query[] = array(
|
335 |
-
'key' => $this->mycred_type,
|
336 |
-
'value' => array( $this->core->number( $setup['min_balance'] ), $this->core->number( $setup['max_balance'] ) ),
|
337 |
-
'compare' => 'BETWEEN',
|
338 |
-
'type' => 'NUMERIC'
|
339 |
-
);
|
340 |
-
|
341 |
-
// Limit by id
|
342 |
-
if ( $setup['id_list'] != '' ) {
|
343 |
-
|
344 |
-
$user_id_list = array();
|
345 |
-
|
346 |
-
$list_of_ids = explode( ',', $setup['id_list'] );
|
347 |
-
foreach ( $list_of_ids as $user_id ) {
|
348 |
-
$user_id = absint( trim( $user_id ) );
|
349 |
-
if ( $user_id !== 0 && ! in_array( $user_id, $clean_ids ) )
|
350 |
-
$user_id_list[] = $user_id;
|
351 |
-
}
|
352 |
-
|
353 |
-
// Take into account users that have been excluded via the point type
|
354 |
-
if ( ! empty( $this->core->exclude['list'] ) ) {
|
355 |
-
$list_of_ids = explode( ',', $this->core->exclude['list'] );
|
356 |
-
foreach ( $list_of_ids as $user_id ) {
|
357 |
-
$user_id = absint( trim( $user_id ) );
|
358 |
-
if ( $user_id !== 0 && ! in_array( $user_id, $clean_ids ) )
|
359 |
-
$user_id_list[] = $user_id;
|
360 |
-
}
|
361 |
-
}
|
362 |
-
|
363 |
-
if ( ! empty( $user_id_list ) ) {
|
364 |
-
|
365 |
-
if ( $setup['id_exclude'] == 'exclude' )
|
366 |
-
$query_args['exclude'] = $user_id_list;
|
367 |
-
else
|
368 |
-
$query_args['include'] = $user_id_list;
|
369 |
-
|
370 |
-
}
|
371 |
-
|
372 |
-
}
|
373 |
-
|
374 |
-
// Limit by role
|
375 |
-
if ( ! empty( $setup['role_list'] ) ) {
|
376 |
-
|
377 |
-
$blog_id = 0;
|
378 |
-
if ( ! mycred_centralize_log() ) {
|
379 |
-
$blog_id = get_current_blog_id();
|
380 |
-
$query_args['blog_id'] = $blog_id;
|
381 |
-
}
|
382 |
-
|
383 |
-
$role_query = array();
|
384 |
-
|
385 |
-
// Exclude by role = role is not x AND role is not y
|
386 |
-
// Include by role = role is x OR role is y
|
387 |
-
if ( count( $setup['role_list'] ) > 1 )
|
388 |
-
$role_query['relation'] = ( ( $setup['role_exclude'] == 'exclude' ) ? 'AND' : 'OR' );
|
389 |
-
|
390 |
-
// Since the "role__in" and "role__not_in" arguments are not available until WordPress 4.4, we just use meta query for this.
|
391 |
-
foreach ( $setup['role_list'] as $role )
|
392 |
-
$role_query[] = array(
|
393 |
-
'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities',
|
394 |
-
'value' => '"' . $role . '"',
|
395 |
-
'compare' => ( ( $setup['role_exclude'] == 'exclude' ) ? 'NOT LIKE' : 'LIKE' )
|
396 |
-
);
|
397 |
-
|
398 |
-
$meta_query[] = $role_query;
|
399 |
-
|
400 |
-
}
|
401 |
-
|
402 |
-
|
403 |
-
if ( ! empty( $meta_query ) )
|
404 |
-
$query_args['meta_query'] = $meta_query;
|
405 |
-
|
406 |
-
$query = new WP_User_Query( $query_args );
|
407 |
-
|
408 |
-
return array(
|
409 |
-
'total' => $query->get_total(),
|
410 |
-
'results' => $query->get_results()
|
411 |
-
);
|
412 |
-
|
413 |
-
}
|
414 |
-
|
415 |
-
/**
|
416 |
-
* Display Schedule Table
|
417 |
-
* @since 1.7
|
418 |
-
* @version 1.0
|
419 |
-
*/
|
420 |
-
public function display_schedule_table( $schedule = NULL ) {
|
421 |
-
|
422 |
-
$content = '';
|
423 |
-
$date_format = get_option( 'date_format' );
|
424 |
-
$time_format = get_option( 'time_format' );
|
425 |
-
$timeframes = mycred_banking_get_timeframes();
|
426 |
-
|
427 |
-
$schedules = mycred_get_recurring_payout_schedules( $this->mycred_type );
|
428 |
-
|
429 |
-
// This function is also used to display just one particular table row
|
430 |
-
if ( $schedule !== NULL )
|
431 |
-
$schedules = array( $schedule['id'] => $schedule );
|
432 |
-
|
433 |
-
if ( ! empty( $schedules ) ) {
|
434 |
-
|
435 |
-
ob_start();
|
436 |
-
|
437 |
-
foreach ( $schedules as $schedule_id => $setup ) {
|
438 |
-
|
439 |
-
$setup = shortcode_atts( $this->default_schedule, $setup );
|
440 |
-
$last_run = $this->timestamp_to_date( $setup['last_run'] );
|
441 |
-
$next_run = mycred_banking_get_next_payout( $setup['frequency'], $last_run );
|
442 |
-
|
443 |
-
// Pending start
|
444 |
-
if ( $setup['status'] == 0 ) {
|
445 |
-
$next_run = date( $date_format . ' ' . $time_format, $last_run );
|
446 |
-
$last_run = __( 'Not yet started', 'mycred' );
|
447 |
-
}
|
448 |
-
|
449 |
-
// Running
|
450 |
-
elseif ( $setup['status'] == 1 ) {
|
451 |
-
$last_run = date( $date_format . ' ' . $time_format, $last_run );
|
452 |
-
$next_run = date( $date_format . ' ' . $time_format, $next_run );
|
453 |
-
}
|
454 |
-
|
455 |
-
// CRON job is running right now
|
456 |
-
elseif ( $setup['status'] == 2 ) {
|
457 |
-
$last_run = __( 'Currently Running', 'mycred' );
|
458 |
-
$next_run = '-';
|
459 |
-
}
|
460 |
-
|
461 |
-
// Finished or stopped
|
462 |
-
else {
|
463 |
-
$last_run = date( $date_format . ' ' . $time_format, $last_run );
|
464 |
-
$next_run = '-';
|
465 |
-
}
|
466 |
-
|
467 |
-
?>
|
468 |
-
<tr id="schedule-<?php echo $schedule_id; ?>">
|
469 |
-
<td class="col-job-title">
|
470 |
-
<div><?php echo esc_attr( $setup['job_title'] ); ?></div>
|
471 |
-
<div class="row-actions">
|
472 |
-
<span class="edit"><a href="javascript:void(0);" class="view-recurring-schedule" data-id="<?php echo $schedule_id; ?>" data-title="<?php _e( 'View Schedule', 'mycred' ); ?>"><?php _e( 'View', 'mycred' ); ?></a> | </span> <span class="delete"><a href="javascript:void(0);" class="delete-recurring-schedule" data-id="<?php echo $schedule_id; ?>" data-title="<?php _e( 'Delete Schedule', 'mycred' ); ?>"><?php _e( 'Delete', 'mycred' ); ?></a></span>
|
473 |
-
</div>
|
474 |
-
</td>
|
475 |
-
<td class="col-job-status">
|
476 |
-
<div><?php if ( array_key_exists( $setup['status'], $this->statuses ) ) echo $this->statuses[ $setup['status'] ]; else echo '-'; ?></div>
|
477 |
-
</td>
|
478 |
-
<td class="col-job-frequency">
|
479 |
-
<div><?php if ( array_key_exists( $setup['frequency'], $timeframes ) ) echo $timeframes[ $setup['frequency'] ]['label']; else echo '-'; ?></div>
|
480 |
-
</td>
|
481 |
-
<td class="col-job-last-ran">
|
482 |
-
<div><?php echo $last_run; ?></div>
|
483 |
-
</td>
|
484 |
-
<td class="col-job-next-run">
|
485 |
-
<div><?php echo $next_run; ?></div>
|
486 |
-
</td>
|
487 |
-
</tr>
|
488 |
-
<?php
|
489 |
-
|
490 |
-
}
|
491 |
-
|
492 |
-
$content = ob_get_contents();
|
493 |
-
ob_end_clean();
|
494 |
-
|
495 |
-
}
|
496 |
-
|
497 |
-
return $content;
|
498 |
-
|
499 |
-
}
|
500 |
-
|
501 |
-
/**
|
502 |
-
* View Schedule Form
|
503 |
-
* @since 1.7
|
504 |
-
* @version 1.0.1
|
505 |
-
*/
|
506 |
-
public function view_schedule_form( $schedule_id, $setup ) {
|
507 |
-
|
508 |
-
$limits = array();
|
509 |
-
$date_format = get_option( 'date_format' );
|
510 |
-
$time_format = get_option( 'time_format' );
|
511 |
-
$timeframes = mycred_banking_get_timeframes();
|
512 |
-
$settings = mycred_get_banking_addon_settings( NULL, $this->mycred_type );
|
513 |
-
|
514 |
-
global $wpdb, $mycred_log_table;
|
515 |
-
|
516 |
-
$total_payout = $wpdb->get_var( $wpdb->prepare( "SELECT SUM(creds) FROM {$mycred_log_table} WHERE ref = %s AND data = %s;", $this->log_reference, $schedule_id ) );
|
517 |
-
if ( $total_payout === NULL ) $total_payout = 0;
|
518 |
-
|
519 |
-
$last_run = mycred_gmt_timestamp_to_local( $setup['last_run'] );
|
520 |
-
$eligeble_users = $this->get_eligible_users( 1, 5, $setup );
|
521 |
-
|
522 |
-
if ( $setup['min_balance'] != 0 )
|
523 |
-
$limits[] = '<div class="col-xs-6"><p>' . __( 'Min. Balance', 'mycred' ) . ': ' . $this->core->format_creds( $setup['min_balance'] ) . '</p></div>';
|
524 |
-
|
525 |
-
if ( $setup['max_balance'] != 0 )
|
526 |
-
$limits[] = '<div class="col-xs-6"><p>' . __( 'Max. Balance', 'mycred' ) . ': ' . $this->core->format_creds( $setup['max_balance'] ) . '</p></div>';
|
527 |
-
|
528 |
-
if ( $setup['id_list'] != '' ) {
|
529 |
-
|
530 |
-
if ( $setup['id_exclude'] == 'exclude' )
|
531 |
-
$limits[] = '<div class="col-xs-6"><p>' . __( 'Exclude Users', 'mycred' ) . ': ' . esc_attr( $setup['id_list'] ) . '</p></div>';
|
532 |
-
else
|
533 |
-
$limits[] = '<div class="col-xs-6"><p>' . __( 'Include Users', 'mycred' ) . ': ' . esc_attr( $setup['id_list'] ) . '</p></div>';
|
534 |
-
|
535 |
-
}
|
536 |
-
|
537 |
-
if ( ! empty( $setup['role_list'] ) ) {
|
538 |
-
|
539 |
-
if ( $setup['role_exclude'] == 'exclude' )
|
540 |
-
$limits[] = '<div class="col-xs-12"><p>' . __( 'Exclude Roles', 'mycred' ) . ': <code>' . implode( '</code>, <code>', $setup['role_list'] ) . '</code></p></div>';
|
541 |
-
else
|
542 |
-
$limits[] = '<div class="col-xs-12"><p>' . __( 'Include Roles', 'mycred' ) . ': <code>' . implode( '</code>, <code>', $setup['role_list'] ) . '</code></p></div>';
|
543 |
-
|
544 |
-
}
|
545 |
-
|
546 |
-
ob_start();
|
547 |
-
|
548 |
-
?>
|
549 |
-
<div class="padded">
|
550 |
-
<div class="row">
|
551 |
-
<div class="col-xs-3">
|
552 |
-
<div class="form-group">
|
553 |
-
<label><?php _e( 'ID', 'mycred' ); ?></label>
|
554 |
-
<p class="form-control-static"><?php echo esc_attr( $schedule_id ); ?></p>
|
555 |
-
</div>
|
556 |
-
</div>
|
557 |
-
<div class="col-xs-6">
|
558 |
-
<div class="form-group">
|
559 |
-
<label><?php _e( 'Job Title', 'mycred' ); ?></label>
|
560 |
-
<p class="form-control-static"><?php echo esc_attr( $setup['job_title'] ); ?></p>
|
561 |
-
</div>
|
562 |
-
</div>
|
563 |
-
<div class="col-xs-3">
|
564 |
-
<div class="form-group">
|
565 |
-
<label><?php _e( 'Status', 'mycred' ); ?></label>
|
566 |
-
<p class="form-control-static"><?php if ( array_key_exists( $setup['status'], $this->statuses ) ) echo $this->statuses[ $setup['status'] ]; else echo '-'; ?></p>
|
567 |
-
</div>
|
568 |
-
</div>
|
569 |
-
</div>
|
570 |
-
<div class="row">
|
571 |
-
<div class="col-xs-5">
|
572 |
-
<div class="form-group">
|
573 |
-
<label><?php if ( $setup['status'] == 0 ) _e( 'Start Date', 'mycred' ); else _e( 'Last Run', 'mycred' ); ?></label>
|
574 |
-
<p class="form-control-static"><?php echo date( $date_format . ' ' . $time_format, $last_run ); ?></p>
|
575 |
-
</div>
|
576 |
-
</div>
|
577 |
-
<div class="col-xs-2">
|
578 |
-
<div class="form-group">
|
579 |
-
<label><?php _e( 'Eligible', 'mycred' ); ?></label>
|
580 |
-
<p class="form-control-static"><?php printf( _n( '1 User', '%d Users', $eligeble_users['total'], 'mycred' ), $eligeble_users['total'] ); ?></p>
|
581 |
-
</div>
|
582 |
-
</div>
|
583 |
-
<div class="col-xs-2">
|
584 |
-
<div class="form-group">
|
585 |
-
<label><?php _e( 'Runs', 'mycred' ); ?></label>
|
586 |
-
<p class="form-control-static"><?php echo esc_attr( ( ( $setup['total_runs'] < 0 ) ? __( 'Infinite', 'mycred' ) : $setup['total_runs'] ) ); ?></p>
|
587 |
-
</div>
|
588 |
-
</div>
|
589 |
-
<div class="col-xs-3">
|
590 |
-
<div class="form-group">
|
591 |
-
<label><?php _e( 'Payout', 'mycred' ); ?></label>
|
592 |
-
<p class="form-control-static"><?php printf( '%s / %s', $this->core->format_creds( $setup['payout'] ), $timeframes[ $setup['frequency'] ]['single'] ); ?></p>
|
593 |
-
</div>
|
594 |
-
</div>
|
595 |
-
</div>
|
596 |
-
<?php if ( ! empty( $limits ) ) : ?>
|
597 |
-
<div class="row">
|
598 |
-
<div class="col-xs-12">
|
599 |
-
<strong><label><?php _e( 'Limits', 'mycred' ); ?>:</label></strong>
|
600 |
-
<div class="row list">
|
601 |
-
<?php echo implode( '', $limits ); ?>
|
602 |
-
</div>
|
603 |
-
</div>
|
604 |
-
</div>
|
605 |
-
<?php endif; ?>
|
606 |
-
<div class="row">
|
607 |
-
<div class="col-xs-12">
|
608 |
-
<?php if ( $setup['ignore_central'] == 1 && in_array( 'central', $settings['active'] ) ) : ?>
|
609 |
-
<p><strong><?php _e( 'Will payout even if the central bank account has run out of funds.', 'mycred' ); ?></strong></p>
|
610 |
-
<?php endif; ?>
|
611 |
-
<table class="widefat fixed striped">
|
612 |
-
<thead>
|
613 |
-
<tr>
|
614 |
-
<th style="width: 25%;"><?php _e( 'Paid Out', 'mycred' ); ?></th>
|
615 |
-
<th style="width: 25%;"><?php _e( 'Completed', 'mycred' ); ?></th>
|
616 |
-
<th style="width: 25%;"><?php _e( 'Misses', 'mycred' ); ?> *</th>
|
617 |
-
<th style="width: 25%;"><?php _e( 'Runs Left', 'mycred' ); ?></th>
|
618 |
-
</tr>
|
619 |
-
</thead>
|
620 |
-
<tbody>
|
621 |
-
<tr>
|
622 |
-
<td>
|
623 |
-
<h1><?php echo $this->core->format_creds( $total_payout ); ?></h1>
|
624 |
-
</td>
|
625 |
-
<td>
|
626 |
-
<h1><?php echo absint( $setup['total_completed'] ); ?></h1>
|
627 |
-
</td>
|
628 |
-
<td>
|
629 |
-
<h1><?php echo absint( $setup['total_misses'] ); ?></h1>
|
630 |
-
</td>
|
631 |
-
<td>
|
632 |
-
<h1><?php echo absint( $setup['runs_remaining'] ); ?></h1>
|
633 |
-
</td>
|
634 |
-
</tr>
|
635 |
-
</tbody>
|
636 |
-
</table>
|
637 |
-
<p><span class="description">* <?php _e( 'A miss is when a payout was declined by the plugin. This can be due to custom code declining the payout or if the user is excluded.', 'mycred' ); ?></span></p>
|
638 |
-
</div>
|
639 |
-
</div>
|
640 |
-
</div>
|
641 |
-
<?php
|
642 |
-
|
643 |
-
$content = ob_get_contents();
|
644 |
-
ob_end_clean();
|
645 |
-
|
646 |
-
return $content;
|
647 |
-
|
648 |
-
}
|
649 |
-
|
650 |
-
/**
|
651 |
-
* Manage Schedule Form
|
652 |
-
* @since 1.7
|
653 |
-
* @version 1.0
|
654 |
-
*/
|
655 |
-
public function manage_schedule_form( $schedule_id, $setup ) {
|
656 |
-
|
657 |
-
$year = $month = $day = '';
|
658 |
-
$time = NULL;
|
659 |
-
|
660 |
-
$timeframes = mycred_banking_get_timeframes();
|
661 |
-
$compound = wp_next_scheduled( $setup['last_run'] );
|
662 |
-
$settings = mycred_get_banking_addon_settings( NULL, $this->mycred_type );
|
663 |
-
|
664 |
-
if ( $compound !== false ) {
|
665 |
-
|
666 |
-
$last_run = $this->timestamp_to_date( $setup['last_run'] );
|
667 |
-
|
668 |
-
$date = date( 'Y-m-d', $last_run );
|
669 |
-
list ( $year, $month, $day ) = explode( '-', $date );
|
670 |
-
|
671 |
-
$time = date( 'H:i', $last_run );
|
672 |
-
|
673 |
-
}
|
674 |
-
|
675 |
-
ob_start();
|
676 |
-
|
677 |
-
?>
|
678 |
-
<div class="padded">
|
679 |
-
<div class="row">
|
680 |
-
<div class="col-xs-6">
|
681 |
-
<div class="form-group">
|
682 |
-
<label><?php _e( 'Schedule Title', 'mycred' ); ?></label>
|
683 |
-
<input type="text" name="job_title" class="form-control cant-be-empty" value="<?php echo esc_attr( $setup['job_title'] ); ?>" />
|
684 |
-
</div>
|
685 |
-
</div>
|
686 |
-
<div class="col-xs-3">
|
687 |
-
<div class="form-group">
|
688 |
-
<label><?php echo $this->core->plural(); ?></label>
|
689 |
-
<input type="text" name="payout" class="form-control cant-be-empty" placeholder="<?php echo $this->core->zero(); ?>" value="" />
|
690 |
-
</div>
|
691 |
-
</div>
|
692 |
-
<div class="col-xs-3">
|
693 |
-
<div class="form-group">
|
694 |
-
<label><?php _e( 'Frequency', 'mycred' ); ?></label>
|
695 |
-
<select name="frequency" class="form-control">
|
696 |
-
<?php
|
697 |
-
|
698 |
-
foreach ( $timeframes as $value => $data ) {
|
699 |
-
echo '<option value="' . $value . '"';
|
700 |
-
if ( $setup['frequency'] == $value ) echo ' selected="selected"';
|
701 |
-
echo '>' . $data['label'] . '</option>';
|
702 |
-
}
|
703 |
-
|
704 |
-
?>
|
705 |
-
</select>
|
706 |
-
</div>
|
707 |
-
</div>
|
708 |
-
<div class="col-xs-12">
|
709 |
-
<div class="form-group">
|
710 |
-
<label><?php _e( 'Log Template', 'mycred' ); ?></label>
|
711 |
-
<input type="text" name="log_template" class="form-control cant-be-empty" value="<?php echo esc_attr( $setup['log_template'] ); ?>" />
|
712 |
-
</div>
|
713 |
-
<?php if ( in_array( 'central', $settings['active'] ) ) : ?>
|
714 |
-
<div class="form-group">
|
715 |
-
<div class="checkbox"><label for="new-schedule-ignore-central-bank"><input type="checkbox" name="ignore_central" id="new-schedule-ignore-central-bank"<?php checked( $setup['ignore_central'], 1 ); ?> value="1" /> <?php _e( 'Payout even if the central bank account runs out of funds.', 'mycred' ); ?></label></div>
|
716 |
-
</div>
|
717 |
-
<?php else : ?>
|
718 |
-
<input type="hidden" name="ignore_central"<?php checked( $setup['ignore_central'], 1 ); ?> value="1" />
|
719 |
-
<?php endif; ?>
|
720 |
-
</div>
|
721 |
-
</div>
|
722 |
-
<h3><?php _e( 'First Payout', 'mycred' ); ?></h3>
|
723 |
-
<div class="row">
|
724 |
-
<div class="col-xs-8">
|
725 |
-
<div class="row">
|
726 |
-
<div class="col-xs-3">
|
727 |
-
<div class="form-group">
|
728 |
-
<label><?php _e( 'Year', 'mycred' ); ?></label>
|
729 |
-
<input type="text" name="last_run[year]" class="form-control cant-be-empty" placeholder="YYYY" value="<?php echo esc_attr( $year ); ?>" />
|
730 |
-
</div>
|
731 |
-
</div>
|
732 |
-
<div class="col-xs-3">
|
733 |
-
<div class="form-group">
|
734 |
-
<label><?php _e( 'Month', 'mycred' ); ?></label>
|
735 |
-
<input type="text" name="last_run[month]" class="form-control cant-be-empty" placeholder="MM" value="<?php echo esc_attr( $month ); ?>" />
|
736 |
-
</div>
|
737 |
-
</div>
|
738 |
-
<div class="col-xs-3">
|
739 |
-
<div class="form-group">
|
740 |
-
<label><?php _e( 'Date', 'mycred' ); ?></label>
|
741 |
-
<input type="text" name="last_run[day]" class="form-control cant-be-empty" placeholder="DD" value="<?php echo esc_attr( $day ); ?>" />
|
742 |
-
</div>
|
743 |
-
</div>
|
744 |
-
<div class="col-xs-3">
|
745 |
-
<div class="form-group">
|
746 |
-
<label><?php _e( 'Time', 'mycred' ); ?></label>
|
747 |
-
<?php echo $this->time_select( 'last_run[time]', 'last-run-time', $time ); ?>
|
748 |
-
</div>
|
749 |
-
</div>
|
750 |
-
</div>
|
751 |
-
</div>
|
752 |
-
<div class="col-xs-4">
|
753 |
-
<div class="form-group">
|
754 |
-
<label><?php _e( 'Repeat', 'mycred' ); ?></label>
|
755 |
-
<input type="number" name="total_runs" class="form-control" placeholder="0" min="-1" max="256" value="<?php echo esc_attr( $setup['total_runs'] ); ?>" />
|
756 |
-
<p><span class="description"><?php _e( 'Use -1 for infinite runs.', 'mycred' ); ?></span></p>
|
757 |
-
</div>
|
758 |
-
</div>
|
759 |
-
</div>
|
760 |
-
<h3><?php _e( 'Limits', 'mycred' ); ?></h3>
|
761 |
-
<div class="row">
|
762 |
-
<div class="col-sm-4 col-xs-12">
|
763 |
-
<div class="row">
|
764 |
-
<div class="col-sm-12 col-xs-6">
|
765 |
-
<div class="form-group">
|
766 |
-
<label><?php _e( 'Min. Balance', 'mycred' ); ?></label>
|
767 |
-
<input type="number" name="min_balance" class="form-control" placeholder="0" min="0" value="<?php echo esc_attr( $setup['min_balance'] ); ?>" />
|
768 |
-
<p><span class="description"><?php _e( 'Use zero to disable.', 'mycred' ); ?></span></p>
|
769 |
-
</div>
|
770 |
-
</div>
|
771 |
-
<div class="col-sm-12 col-xs-6">
|
772 |
-
<div class="form-group">
|
773 |
-
<label><?php _e( 'Max. Balance', 'mycred' ); ?></label>
|
774 |
-
<input type="number" name="max_balance" class="form-control" placeholder="0" min="0" value="<?php echo esc_attr( $setup['max_balance'] ); ?>" />
|
775 |
-
<p><span class="description"><?php _e( 'Use zero to disable.', 'mycred' ); ?></span></p>
|
776 |
-
</div>
|
777 |
-
</div>
|
778 |
-
</div>
|
779 |
-
</div>
|
780 |
-
<div class="col-sm-8 col-xs-12">
|
781 |
-
<div class="row">
|
782 |
-
<div class="col-sm-5 col-xs-12">
|
783 |
-
<div class="form-group">
|
784 |
-
<label><?php _e( 'Limit by ID', 'mycred' ); ?></label>
|
785 |
-
<?php echo $this->include_exclude_dropdown( 'id_exclude', 'exclude-include-id', $setup['id_exclude'] ); ?>
|
786 |
-
</div>
|
787 |
-
</div>
|
788 |
-
<div class="col-sm-7 col-xs-12">
|
789 |
-
<div class="form-group">
|
790 |
-
<label class="xs-hidden"> </label>
|
791 |
-
<input type="text" name="id_list" class="form-control" placeholder="<?php _e( 'Comma separated list of user IDs', 'mycred' ); ?>" value="<?php echo esc_attr( $setup['id_list'] ); ?>" />
|
792 |
-
</div>
|
793 |
-
</div>
|
794 |
-
</div>
|
795 |
-
<div class="row">
|
796 |
-
<div class="col-sm-5 col-xs-12">
|
797 |
-
<div class="form-group">
|
798 |
-
<label><?php _e( 'Limit by Role(s)', 'mycred' ); ?></label>
|
799 |
-
<?php echo $this->include_exclude_dropdown( 'role_exclude', 'exclude-include-role', $setup['role_exclude'] ); ?>
|
800 |
-
</div>
|
801 |
-
</div>
|
802 |
-
<div class="col-sm-7 col-xs-12">
|
803 |
-
<div class="row">
|
804 |
-
<?php
|
805 |
-
|
806 |
-
$editable_roles = array_reverse( get_editable_roles() );
|
807 |
-
foreach ( $editable_roles as $role => $details ) {
|
808 |
-
|
809 |
-
$name = translate_user_role( $details['name'] );
|
810 |
-
|
811 |
-
echo '<div class="col-sm-6 col-xs-4"><label for="role-list-' . esc_attr( $role ) . '"><input type="checkbox" name="role_list[]" id="role-list-' . esc_attr( $role ) . '" value="' . esc_attr( $role ) . '"';
|
812 |
-
if ( in_array( $role, (array) $setup['role_list'] ) ) echo ' checked="checked"';
|
813 |
-
echo ' />' . $name . '</label></div>';
|
814 |
-
}
|
815 |
-
|
816 |
-
?>
|
817 |
-
</div>
|
818 |
-
</div>
|
819 |
-
</div>
|
820 |
-
</div>
|
821 |
-
</div>
|
822 |
-
<div class="row">
|
823 |
-
<div class="col-xs-12 tr">
|
824 |
-
<input type="hidden" name="new_id" value="<?php echo $schedule_id; ?>" />
|
825 |
-
<input type="submit" class="button button-primary" value="<?php _e( 'Schedule', 'mycred' ); ?>" />
|
826 |
-
</div>
|
827 |
-
</div>
|
828 |
-
</div>
|
829 |
-
<?php
|
830 |
-
|
831 |
-
$content = ob_get_contents();
|
832 |
-
ob_end_clean();
|
833 |
-
|
834 |
-
return $content;
|
835 |
-
|
836 |
-
}
|
837 |
-
|
838 |
-
/**
|
839 |
-
* Include Exclude Dropdown
|
840 |
-
* @since 1.7
|
841 |
-
* @version 1.0
|
842 |
-
*/
|
843 |
-
public function include_exclude_dropdown( $name = '', $id = '', $selected = '' ) {
|
844 |
-
|
845 |
-
$options = array(
|
846 |
-
'include' => __( 'Include:', 'mycred' ),
|
847 |
-
'exclude' => __( 'Exclude:', 'mycred' )
|
848 |
-
);
|
849 |
-
|
850 |
-
$content = '<select name="' . $name . '" id="' . $id . '" class="form-control">';
|
851 |
-
foreach ( $options as $value => $label ) {
|
852 |
-
$content .= '<option value="' . $value . '"';
|
853 |
-
if ( $selected == $value ) $content .= ' selected="selected"';
|
854 |
-
$content .= '>' . $label . '</option>';
|
855 |
-
}
|
856 |
-
$content .= '</select>';
|
857 |
-
|
858 |
-
return $content;
|
859 |
-
|
860 |
-
}
|
861 |
-
|
862 |
-
/**
|
863 |
-
* Preference for recurring payouts
|
864 |
-
* @since 1.2
|
865 |
-
* @version 1.2
|
866 |
-
*/
|
867 |
-
public function preferences() {
|
868 |
-
|
869 |
-
$schedules = mycred_get_recurring_payout_schedules( $this->mycred_type );
|
870 |
-
|
871 |
-
?>
|
872 |
-
<p><?php _e( 'As long as this service remains disabled, none of your scheduled payouts will run!', 'mycred' ); ?></p>
|
873 |
-
<div class="row">
|
874 |
-
<div class="col-xs-12">
|
875 |
-
<h3><?php _e( 'Schedules', 'mycred' ); ?></h3>
|
876 |
-
<table class="widefat fixed striped" cellpadding="0" cellspacing="0">
|
877 |
-
<thead>
|
878 |
-
<tr>
|
879 |
-
<th style="width: 25%;"><?php _e( 'Job Title', 'mycred' ); ?></th>
|
880 |
-
<th style="width: 15%;"><?php _e( 'Status', 'mycred' ); ?></th>
|
881 |
-
<th style="width: 20%;"><?php _e( 'Frequency', 'mycred' ); ?></th>
|
882 |
-
<th style="width: 20%;"><?php _e( 'Last Ran', 'mycred' ); ?></th>
|
883 |
-
<th style="width: 20%;"><?php _e( 'Next Run', 'mycred' ); ?></th>
|
884 |
-
</tr>
|
885 |
-
</thead>
|
886 |
-
<tbody id="recurring-schedule-body">
|
887 |
-
|
888 |
-
<?php echo $this->display_schedule_table(); ?>
|
889 |
-
|
890 |
-
<tr id="no-banking-schedules"<?php if ( ! empty( $schedules ) ) echo ' style="display: none;"'; ?>>
|
891 |
-
<td colspan="5"><?php _e( 'No schedules found.', 'mycred' ); ?></td>
|
892 |
-
</tr>
|
893 |
-
</tbody>
|
894 |
-
</table>
|
895 |
-
<input type="hidden" name="<?php echo $this->field_name( 'here' ); ?>" value="1" />
|
896 |
-
<p style="text-align: right;"><button type="button" id="add-new-schedule" class="button button-secondary"><?php _e( 'Add New', 'mycred' ); ?></button>
|
897 |
-
</div>
|
898 |
-
</div>
|
899 |
-
<?php
|
900 |
-
|
901 |
-
do_action( 'mycred_banking_recurring_payouts', $this );
|
902 |
-
|
903 |
-
}
|
904 |
-
|
905 |
-
/**
|
906 |
-
* Sanitise Preferences
|
907 |
-
* @since 1.2
|
908 |
-
* @version 1.1
|
909 |
-
*/
|
910 |
-
function sanitise_preferences( $post ) {
|
911 |
-
|
912 |
-
return apply_filters( 'mycred_banking_save_recurring', array(), $this );
|
913 |
-
|
914 |
-
}
|
915 |
-
|
916 |
-
/**
|
917 |
-
* Ajax Handler
|
918 |
-
* @since 1.7
|
919 |
-
* @version 1.0
|
920 |
-
*/
|
921 |
-
function ajax_handler() {
|
922 |
-
|
923 |
-
parse_str( $_POST['form'], $form );
|
924 |
-
|
925 |
-
// Add new Schedule
|
926 |
-
if ( empty( $form ) ) {
|
927 |
-
$new_id = strtolower( wp_generate_password( 6, false, false ) );
|
928 |
-
wp_send_json_success( array( 'form' => $this->manage_schedule_form( $new_id, $this->default_schedule ), 'table' => false ) );
|
929 |
-
}
|
930 |
-
|
931 |
-
// Save new Schedule
|
932 |
-
if ( array_key_exists( 'new_id', $form ) ) {
|
933 |
-
|
934 |
-
$setup = shortcode_atts( $this->default_schedule, $form );
|
935 |
-
|
936 |
-
// Prep start time and convert it into a gmt unix timestamp
|
937 |
-
$year = absint( $form['last_run']['year'] );
|
938 |
-
$month = zeroise( absint( $form['last_run']['month'] ), 2 );
|
939 |
-
$day = zeroise( absint( $form['last_run']['day'] ), 2 );
|
940 |
-
$time = sanitize_text_field( $form['last_run']['time'] );
|
941 |
-
|
942 |
-
$setup['last_run'] = $this->date_to_timestamp( $year . '-' . $month . '-' . $day . ' ' . $time . ':00' );
|
943 |
-
|
944 |
-
// Attempt to add new payout schedule
|
945 |
-
$results = mycred_add_new_recurring_payout( $form['new_id'], $setup, $this->mycred_type );
|
946 |
-
|
947 |
-
// Something went wrong
|
948 |
-
if ( is_wp_error( $results ) ) {
|
949 |
-
$content = '<div class="alert alert-warning">' . $results->get_error_message() . '</div>';
|
950 |
-
$content .= $this->manage_schedule_form( $form['new_id'], $setup );
|
951 |
-
wp_send_json_success( array( 'form' => $content, 'table' => false ) );
|
952 |
-
}
|
953 |
-
|
954 |
-
$results['id'] = $form['new_id'];
|
955 |
-
$message = '<div class="alert alert-success">' . __( 'Schedule Added', 'mycred' ) . '</div>';
|
956 |
-
|
957 |
-
$table_row = $this->display_schedule_table( $results );
|
958 |
-
$eligeble_users = $this->get_eligible_users( 5, 0, $setup );
|
959 |
-
|
960 |
-
// Warn user if no users are eligile for a payout based of their setup
|
961 |
-
if ( $eligeble_users['total'] == 0 )
|
962 |
-
$message .= '<div class="padded"><p>' . __( 'While the recurring payout has been successfully saved, based on the limits you set, right now there are no users that are eligible for a payout!', 'mycred' ) . '</p></div>';
|
963 |
-
|
964 |
-
wp_send_json_success( array( 'form' => $message, 'table' => $table_row ) );
|
965 |
-
|
966 |
-
}
|
967 |
-
|
968 |
-
// View existing schedule
|
969 |
-
elseif ( array_key_exists( 'schedule_id', $form ) ) {
|
970 |
-
|
971 |
-
$schedule_id = sanitize_key( $form['schedule_id'] );
|
972 |
-
$setup = mycred_get_recurring_payout( $schedule_id, $this->mycred_type );
|
973 |
-
if ( $setup === false ) {
|
974 |
-
$content = '<div class="alert alert-warning">' . __( 'Schedule not found. Please refresh this page and try again.', 'mycred' ) . '</div>';
|
975 |
-
wp_send_json_success( array( 'form' => $content, 'table' => false ) );
|
976 |
-
}
|
977 |
-
|
978 |
-
wp_send_json_success( array( 'form' => $this->view_schedule_form( $schedule_id, $setup ), 'table' => false ) );
|
979 |
-
|
980 |
-
}
|
981 |
-
|
982 |
-
// Delete existing schedule
|
983 |
-
elseif ( array_key_exists( 'remove_token', $form ) ) {
|
984 |
-
|
985 |
-
$schedule_id = sanitize_key( $form['remove_token'] );
|
986 |
-
$setup = mycred_get_recurring_payout( $schedule_id, $this->mycred_type );
|
987 |
-
if ( $setup === false ) {
|
988 |
-
$content = '<div class="alert alert-warning">' . __( 'Schedule not found. Please refresh this page and try again.', 'mycred' ) . '</div>';
|
989 |
-
wp_send_json_success( array( 'form' => $content, 'table' => false ) );
|
990 |
-
}
|
991 |
-
|
992 |
-
mycred_delete_recurring_payout( $schedule_id, $this->mycred_type );
|
993 |
-
$content = '<div class="alert alert-success">' . __( 'Schedule Deleted', 'mycred' ) . '</div>';
|
994 |
-
$content .= "<script type=\"text/javascript\">jQuery(function($) { $( 'tr#schedule-{$schedule_id}' ).remove(); });</script>";
|
995 |
-
wp_send_json_success( array( 'form' => $content, 'table' => false ) );
|
996 |
-
|
997 |
-
}
|
998 |
-
|
999 |
-
}
|
1000 |
-
|
1001 |
-
}
|
1002 |
-
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mycred.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: myCred
|
4 |
* Plugin URI: https://mycred.me
|
5 |
* Description: An adaptive points management system for WordPress powered websites.
|
6 |
-
* Version: 2.0
|
7 |
* Tags: point, credit, loyalty program, engagement, reward, woocommerce rewards
|
8 |
* Author: myCred
|
9 |
* Author URI: https://mycred.me
|
@@ -20,7 +20,7 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
|
|
20 |
final class myCRED_Core {
|
21 |
|
22 |
// Plugin Version
|
23 |
-
public $version = '2.0';
|
24 |
|
25 |
// Instnace
|
26 |
protected static $_instance = NULL;
|
@@ -54,14 +54,14 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
|
|
54 |
* @since 1.7
|
55 |
* @version 1.0
|
56 |
*/
|
57 |
-
public function __clone() { _doing_it_wrong( __FUNCTION__, 'Cheatin’ huh?', '2.0' ); }
|
58 |
|
59 |
/**
|
60 |
* Not allowed
|
61 |
* @since 1.7
|
62 |
* @version 1.0
|
63 |
*/
|
64 |
-
public function __wakeup() { _doing_it_wrong( __FUNCTION__, 'Cheatin’ huh?', '2.0' ); }
|
65 |
|
66 |
/**
|
67 |
* Get
|
@@ -82,7 +82,7 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
|
|
82 |
if ( ! defined( $name ) )
|
83 |
define( $name, $value );
|
84 |
elseif ( ! $definable && defined( $name ) )
|
85 |
-
_doing_it_wrong( 'myCRED_Core->define()', 'Could not define: ' . $name . ' as it is already defined somewhere else!', '2.0' );
|
86 |
}
|
87 |
|
88 |
/**
|
@@ -94,7 +94,7 @@ if ( ! class_exists( 'myCRED_Core' ) ) :
|
|
94 |
if ( file_exists( $required_file ) )
|
95 |
require_once $required_file;
|
96 |
else
|
97 |
-
_doing_it_wrong( 'myCRED_Core->file()', 'Requested file ' . $required_file . ' not found.', '2.0' );
|
98 |
}
|
99 |
|
100 |
/**
|
3 |
* Plugin Name: myCred
|
4 |
* Plugin URI: https://mycred.me
|
5 |
* Description: An adaptive points management system for WordPress powered websites.
|
6 |
+
* Version: 2.0.1
|
7 |
* Tags: point, credit, loyalty program, engagement, reward, woocommerce rewards
|
8 |
* Author: myCred
|
9 |
* Author URI: https://mycred.me
|
20 |
final class myCRED_Core {
|
21 |
|
22 |
// Plugin Version
|
23 |
+
public $version = '2.0.1';
|
24 |
|
25 |
// Instnace
|
26 |
protected static $_instance = NULL;
|
54 |
* @since 1.7
|
55 |
* @version 1.0
|
56 |
*/
|
57 |
+
public function __clone() { _doing_it_wrong( __FUNCTION__, 'Cheatin’ huh?', '2.0.1' ); }
|
58 |
|
59 |
/**
|
60 |
* Not allowed
|
61 |
* @since 1.7
|
62 |
* @version 1.0
|
63 |
*/
|
64 |
+
public function __wakeup() { _doing_it_wrong( __FUNCTION__, 'Cheatin’ huh?', '2.0.1' ); }
|
65 |
|
66 |
/**
|
67 |
* Get
|
82 |
if ( ! defined( $name ) )
|
83 |
define( $name, $value );
|
84 |
elseif ( ! $definable && defined( $name ) )
|
85 |
+
_doing_it_wrong( 'myCRED_Core->define()', 'Could not define: ' . $name . ' as it is already defined somewhere else!', '2.0.1' );
|
86 |
}
|
87 |
|
88 |
/**
|
94 |
if ( file_exists( $required_file ) )
|
95 |
require_once $required_file;
|
96 |
else
|
97 |
+
_doing_it_wrong( 'myCRED_Core->file()', 'Requested file ' . $required_file . ' not found.', '2.0.1' );
|
98 |
}
|
99 |
|
100 |
/**
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: mycred,wpexpertsio
|
|
3 |
Tags: badges, gamification, loyalty, points, rewards
|
4 |
Requires at least: 4.8
|
5 |
Tested up to: 5.6
|
6 |
-
Stable tag: 2.0
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -248,6 +248,9 @@ You can find a list of [frequently asked questions](https://mycred.me/about/faq/
|
|
248 |
|
249 |
== Upgrade Notice ==
|
250 |
|
|
|
|
|
|
|
251 |
= 2.0 =
|
252 |
The banking module have been replaced by Central deposite module, and interest related functionality has been removed. If you are using simple interest or compound interest related functionality, you will fine the respective functionalities missing after the update.
|
253 |
|
@@ -332,6 +335,9 @@ Bug fixes release.
|
|
332 |
|
333 |
== Changelog ==
|
334 |
|
|
|
|
|
|
|
335 |
= 2.0 =
|
336 |
NEW - myCred CashCred
|
337 |
NEW - Added filter 'mycred_link_click_amount'
|
3 |
Tags: badges, gamification, loyalty, points, rewards
|
4 |
Requires at least: 4.8
|
5 |
Tested up to: 5.6
|
6 |
+
Stable tag: 2.0.1
|
7 |
Requires PHP: 7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
248 |
|
249 |
== Upgrade Notice ==
|
250 |
|
251 |
+
= 2.0.1 =
|
252 |
+
Bug fixes release.
|
253 |
+
|
254 |
= 2.0 =
|
255 |
The banking module have been replaced by Central deposite module, and interest related functionality has been removed. If you are using simple interest or compound interest related functionality, you will fine the respective functionalities missing after the update.
|
256 |
|
335 |
|
336 |
== Changelog ==
|
337 |
|
338 |
+
= 2.0.1 =
|
339 |
+
FIX - myCred membership license not activating for members
|
340 |
+
|
341 |
= 2.0 =
|
342 |
NEW - myCred CashCred
|
343 |
NEW - Added filter 'mycred_link_click_amount'
|