affiliates-admin-user-registration.php
9.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
/**
* affiliates-admin-user-registration.php
*
* Copyright (c) 2010 - 2014 "kento" Karim Rahimpur www.itthinx.com
*
* This code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This header and all notices must be kept intact.
*
* @author Karim Rahimpur
* @package affiliates
* @since 2.7.0
*/
if ( !defined( 'ABSPATH' ) ) {
exit;
}
require_once AFFILIATES_CORE_LIB . '/class-affiliates-user-registration.php';
function affiliates_admin_user_registration() {
if ( !current_user_can( AFFILIATES_ADMINISTER_OPTIONS ) ) {
wp_die( __( 'Access denied.', AFFILIATES_PLUGIN_DOMAIN ) );
}
echo '<h1>';
echo __( 'User Registration', AFFILIATES_PLUGIN_DOMAIN );
echo '</h1>';
echo '<p class="description">';
echo __( 'Here you can enable the built-in User Registration integration which allows to grant commissions to affiliates when they refer new users.', AFFILIATES_PLUGIN_DOMAIN );
echo '</p>';
// save
if ( isset( $_POST['action'] ) && $_POST['action'] == 'save' ) {
if ( isset( $_POST['affiliates-user-registraton-admin'] ) && wp_verify_nonce( $_POST['affiliates-user-registraton-admin'], 'save' ) ) {
delete_option( 'aff_user_registration_enabled' );
if ( !empty( $_POST['enabled'] ) ) {
add_option( 'aff_user_registration_enabled', 'yes', '', 'no' );
}
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
delete_option( 'aff_customer_registration_enabled' );
if ( !empty( $_POST['enabled'] ) ) {
add_option( 'aff_customer_registration_enabled', 'yes', '', 'no' );
}
}
if ( AFFILIATES_PLUGIN_NAME != 'affiliates' ) {
delete_option( 'aff_user_registration_base_amount' );
if ( !empty( $_POST['base_amount'] ) ) {
$base_amount = floatval( $_POST['base_amount'] );
if ( $base_amount < 0 ) {
$base_amount = 0;
}
add_option( 'aff_user_registration_base_amount', $base_amount, '', 'no' );
}
}
delete_option( 'aff_user_registration_amount' );
if ( !empty( $_POST['amount'] ) ) {
$amount = floatval( $_POST['amount'] );
if ( $amount < 0 ) {
$amount = 0;
}
add_option( 'aff_user_registration_amount', $amount, '', 'no' );
}
delete_option( 'aff_user_registration_currency' );
if ( !empty( $_POST['currency'] ) ) {
add_option( 'aff_user_registration_currency', $_POST['currency'], '', 'no' );
}
delete_option( 'aff_user_registration_referral_status' );
if ( !empty( $_POST['status'] ) ) {
add_option( 'aff_user_registration_referral_status', $_POST['status'], '', 'no' );
}
}
}
$user_registration_enabled = get_option( 'aff_user_registration_enabled', 'no' );
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
$customer_registration_enabled = get_option( 'aff_customer_registration_enabled', 'no' );
}
if ( AFFILIATES_PLUGIN_NAME != 'affiliates' ) {
$user_registration_base_amount = get_option( 'aff_user_registration_base_amount', '' );
}
$user_registration_amount = get_option( 'aff_user_registration_amount', '0' );
$user_registration_currency = get_option( 'aff_user_registration_currency', Affiliates::DEFAULT_CURRENCY );
$user_registration_referral_status = get_option(
'aff_user_registration_referral_status',
get_option( 'aff_default_referral_status', AFFILIATES_REFERRAL_STATUS_ACCEPTED )
);
echo '<style type="text/css">';
echo 'div.field { padding: 0 1em 1em 0; }';
echo 'div.field.user-registration-base-amount input { width: 5em; text-align: right;}';
echo 'div.field.user-registration-amount input { width: 5em; text-align: right;}';
echo 'div.field span.label { display: inline-block; width: 20%; }';
echo 'div.field span.description { display: block; }';
echo 'div.buttons { padding-top: 1em; }';
echo '</style>';
echo '<form action="" name="user_registration" method="post">';
echo '<div>';
// enable
echo '<div class="field user-registration-enabled">';
echo '<label>';
printf( '<input type="checkbox" name="enabled" value="1" %s />', $user_registration_enabled == 'yes' ? ' checked="checked" ' : '' );
echo ' ';
echo __( 'Enable the user registration integration', AFFILIATES_PLUGIN_DOMAIN );
echo '</label>';
echo '</div>';
// enable customer
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
echo '<div class="field customer-registration-enabled">';
echo '<label>';
printf( '<input type="checkbox" name="enabled" value="1" %s />', $customer_registration_enabled == 'yes' ? ' checked="checked" ' : '' );
echo ' ';
echo __( 'Enable the WooCommerce customer registration integration', AFFILIATES_PLUGIN_DOMAIN );
echo '</label>';
echo ' ';
echo '<span class="description">';
echo __( 'If the user registration integration should create referrals for new customers that register at checkout, this option should be enabled.', AFFILIATES_PLUGIN_DOMAIN );
echo '</span>';
echo '</div>';
}
// base amount
if ( AFFILIATES_PLUGIN_NAME != 'affiliates' ) {
echo '<div class="field user-registration-base-amount">';
echo '<label>';
echo '<span class="label">';
echo __( 'Base Amount', AFFILIATES_PLUGIN_DOMAIN );
echo '</span>';
echo ' ';
printf( '<input type="text" name="base_amount" value="%s"/>', esc_attr( $user_registration_base_amount ) );
echo '</label>';
echo '<span class="description">';
echo __( 'When an affiliate refers a new user, a referral is recorded, granting the affiliate an amount in the chosen currency. The amount is calculated taking this base amount into account. For example, if a general referral rate is set, the referral amount equals this base amount multipied by the referral rate.', AFFILIATES_PLUGIN_DOMAIN );
echo ' ';
echo __( 'If set, this <strong>Base Amount</strong> takes precedence over the <strong>Amount</strong>.', AFFILIATES_PLUGIN_DOMAIN );
if ( AFFILIATES_PLUGIN_NAME == 'affiliates-enterprise' ) {
echo ' ';
echo __( 'If multi-tiered referrals are enabled and level rates are not relative, this <strong>Base Amount</strong> must be used instead of the <strong>Amount</strong>.', AFFILIATES_PLUGIN_DOMAIN );
}
echo '</span>';
echo '</div>';
}
// amount
echo '<div class="field user-registration-amount">';
echo '<label>';
echo '<span class="label">';
echo __( 'Amount', AFFILIATES_PLUGIN_DOMAIN );
echo '</span>';
echo ' ';
printf( '<input type="text" name="amount" value="%s"/>', esc_attr( $user_registration_amount ) );
echo '</label>';
echo '<span class="description">';
echo __( 'When an affiliate refers a new user, a referral is recorded, granting the affiliate this amount in the chosen currency.', AFFILIATES_PLUGIN_DOMAIN );
echo '</span>';
echo '</div>';
// currency
$currency_select = '<select name="currency">';
foreach( apply_filters( 'affiliates_supported_currencies', Affiliates::$supported_currencies ) as $cid ) {
$selected = ( $user_registration_currency == $cid ) ? ' selected="selected" ' : '';
$currency_select .= '<option ' . $selected . ' value="' .esc_attr( $cid ).'">' . $cid . '</option>';
}
$currency_select .= '</select>';
echo '<div class="field user-registration-currency">';
echo '<label>';
echo '<span class="label">';
echo __( 'Currency', AFFILIATES_PLUGIN_DOMAIN );
echo '</span>';
echo ' ';
echo $currency_select;
echo '</label>';
echo '</div>';
$status_descriptions = array(
AFFILIATES_REFERRAL_STATUS_ACCEPTED => __( 'Accepted', AFFILIATES_PLUGIN_DOMAIN ),
AFFILIATES_REFERRAL_STATUS_CLOSED => __( 'Closed', AFFILIATES_PLUGIN_DOMAIN ),
AFFILIATES_REFERRAL_STATUS_PENDING => __( 'Pending', AFFILIATES_PLUGIN_DOMAIN ),
AFFILIATES_REFERRAL_STATUS_REJECTED => __( 'Rejected', AFFILIATES_PLUGIN_DOMAIN ),
);
$status_select = "<select name='status'>";
foreach ( $status_descriptions as $status_key => $status_value ) {
if ( $status_key == $user_registration_referral_status ) {
$selected = "selected='selected'";
} else {
$selected = "";
}
$status_select .= "<option value='$status_key' $selected>$status_value</option>";
}
$status_select .= "</select>";
echo '<div class="field user-registration-referral-status">';
echo '<label>';
echo '<span class="label">';
echo __( 'Referral Status', AFFILIATES_PLUGIN_DOMAIN );
echo '</span>';
echo ' ';
echo $status_select;
echo '</label>';
echo '<p class="description">';
echo __( 'The status for referrals that record commissions when affiliates refer new users.', AFFILIATES_PLUGIN_DOMAIN );
echo '</p>';
echo '</div>';
echo '<p>';
echo __( 'Recommended choices for the referral status are <em>Accepted</em> and <em>Pending</em>.', AFFILIATES_PLUGIN_DOMAIN );
echo '</p>';
echo '<ul>';
echo '<li>';
echo __( '<strong>Accepted</strong> if these referrals should grant payable commissions to affiliates without the need for further review.', AFFILIATES_PLUGIN_DOMAIN );
echo '</li>';
echo '<li>';
echo __( '<strong>Pending</strong> if these referrals are to be reviewed before the commissions should be taken into account for affiliate payouts.', AFFILIATES_PLUGIN_DOMAIN );
echo '</li>';
echo '</ul>';
echo '<div class="buttons">';
wp_nonce_field( 'save', 'affiliates-user-registraton-admin', true, true );
echo '<input class="button button-primary" type="submit" name="submit" value="' . __( 'Save', AFFILIATES_PLUGIN_DOMAIN ) . '"/>';
echo '<input type="hidden" name="action" value="save"/>';
echo '</div>';
echo '</div>';
echo '</form>';
affiliates_footer();
}