III. Admin
saveExtraAdminOptions( $options )
public function saveExtraAdminOptions( $options ) {
if ( ! empty( $options['wpjobster_sample_withdrawal_enable'] ) ) {
if ( $options['wpjobster_sample_withdrawal_enable'] == 'both' ) {
update_option( 'wpjobster_sample_automatic_enable_withdraw', 'yes' );
update_option( 'wpjobster_sample_enable_withdraw', 'yes' );
} elseif ( $options['wpjobster_sample_withdrawal_enable'] == 'automatic' ) {
update_option( 'wpjobster_sample_automatic_enable_withdraw', 'yes' );
update_option( 'wpjobster_sample_enable_withdraw', 'no' );
} elseif ( $options['wpjobster_sample_withdrawal_enable'] == 'manual' ) {
update_option( 'wpjobster_sample_automatic_enable_withdraw', 'no' );
update_option( 'wpjobster_sample_enable_withdraw', 'yes' );
} else {
update_option( 'wpjobster_sample_automatic_enable_withdraw', 'no' );
update_option( 'wpjobster_sample_enable_withdraw', 'no' );
}
}
}
This function saves the options for manual and automatic withdrawal, set in the administrator panel.
displayAdminAutomaticWithdrawalButton( $default, $row )
public function displayAdminAutomaticWithdrawalButton( $default, $row ) {
if ( strtolower( $row->methods ) == 'sample' ) {
if ( wpj_get_option( 'wpjobster_sample_client_id' ) && wpj_get_option( 'wpjobster_sample_secret_key' ) )
return wpj_get_option( 'wpjobster_sample_automatic_enable_withdraw' ) == 'yes' ? true : false;
else
return false;
}
return $default;
}
This function allows displaying the double checkmarks icon for automatically marking the order as complete.
displayProcessPaymentRequestButton( $payment_type )
public function displayProcessPaymentRequestButton( $payment_type ) {
if ( $payment_type == 'withdrawal' && WPJ_Form::get( 'status' ) == 'pending' && wpj_get_option( 'wpjobster_sample_automatic_enable_withdraw' ) == 'yes' ) { ?>
<input class="button-secondary" type="submit" value="<?php echo __( 'Process Sample Requests', 'wpjobster-sample' ); ?>" name="processSamplePayRequest" id="processSamplePayRequest" />
<?php }
}
This function allows displaying the button for automatically marking multiple orders as complete.
processPaymentRequest
public function processPaymentRequest() {
if ( ! empty( $_POST['processSamplePayRequest'] ) ) {
$wpjobster_sample_client_id = wpj_get_option( 'wpjobster_sample_client_id' );
$wpjobster_sample_secret_key = wpj_get_option( 'wpjobster_sample_secret_key' );
if ( $wpjobster_sample_client_id && $wpjobster_sample_secret_key ) {
global $wpdb;
$payout_info = array();
if ( isset( $_POST['requests'] ) ) {
foreach ( $_POST['requests'] as $id ) {
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}job_withdraw WHERE id = %d AND methods LIKE '%Sample%'", $id ) );
if ( ! empty( $row ) && $row->done == 0 ) {
$sample_payee_id = wpj_user( $row->uid, 'sample_automatic_payee_id' ) ? wpj_user( $row->uid, 'sample_automatic_payee_id' ) : $row->payeremail;
$payout_info[$id]['payee_id'] = $sample_payee_id;
$payout_info[$id]['amount'] = $row->amount;
$payout_info[$id]['userid'] = $row->uid;
$payout_info[$id]['uniqueid'] = $id;
}
}
}
if ( $payout_info ) {
// Process the payment
foreach ( $payout_info as $key => $info ) {
}
} else {
echo '
<div class="notice notice-error is-dismissible">
<p>' . __( 'No Sample order selected!', 'wpjobster-sample' ) . '</p>
</div>
';
}
} else {
echo '
<div class="notice notice-error is-dismissible">
<p>' . __( 'Please fill Client ID and Secret Key fields!', 'wpjobster-sample' ) . '</p>
</div>
';
}
}
}
This function processes the payout request, and when everything is ready, it marks the order as complete.