本文整理汇总了PHP中give_set_error函数的典型用法代码示例。如果您正苦于以下问题:PHP give_set_error函数的具体用法?PHP give_set_error怎么用?PHP give_set_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了give_set_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
give_set_error('invalid_email', 'Please enter a valid email address.');
give_set_error('invalid_user', 'The user information is invalid.');
give_set_error('username_incorrect', 'The username you entered does not exist.');
give_set_error('password_incorrect', 'The password you entered is incorrect.');
}
示例2: give_no_gateway_error
/**
* Sets an error on checkout if no gateways are enabled
*
* @since 1.0
* @return void
*/
function give_no_gateway_error()
{
$gateways = give_get_enabled_payment_gateways();
if (empty($gateways)) {
give_set_error('no_gateways', __('You must enable a payment gateway to use Give', 'give'));
} else {
give_unset_error('no_gateways');
}
}
示例3: give_validate_recaptcha
/**
* Validate ReCAPTCHA
*
* @param $valid_data
* @param $data
*/
function give_validate_recaptcha($valid_data, $data)
{
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_secret_key = 'MY SITE KEY HERE';
// <----- UPDATE WITH YOUR SITE KEY
$recaptcha_response = wp_remote_post($recaptcha_url . "?secret=" . $recaptcha_secret_key . "&response=" . $data['g-recaptcha-response'] . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
$recaptcha_data = wp_remote_retrieve_body($recaptcha_response);
if (isset($recaptcha_data->success) && $recaptcha_data->success == true) {
//User must have validated the reCAPTCHA to proceed with donation
if (!isset($data['g-recaptcha-response']) || empty($data['g-recaptcha-response'])) {
give_set_error('g-recaptcha-response', __('Please verify that you are not a robot.', 'give'));
}
}
}
示例4: give_donations_validate_custom_fields
/**
* Validate Custom Field
*
* @description check for errors without custom fields
*
* @param $valid_data
* @param $data
*/
function give_donations_validate_custom_fields($valid_data, $data)
{
// Only validate the form with the IDs "754" and "586";
// Remove "If" statement to display on all forms
// For a single form, use this instead:
// if ( $form_id == 754) {
$forms = array(754, 586);
if (in_array($data['give-form-id'], $forms)) {
return;
}
//Check for message data
if (empty($data['give_message'])) {
give_set_error('give_message', __('Please tell us what you would like inscribed on the plaque.', 'give'));
}
}
示例5: give_donations_validate_donation_amount
/**
* Validation donation amount. Note: Give handles validation minimum amount out-of-the-box.
*
* Check that a donation is above or below a maximum amount.
*
* @param $valid_data
* @param $data
*/
function give_donations_validate_donation_amount($valid_data, $data)
{
// Only validate the form with the IDs "754" and "586";
// Remove "If" statement to validation for all forms
// For a single form, use this instead:
// $forms = array( 1425 );
// if ( ! in_array( $data['give-form-id'], $forms ) ) {
// return;
// }
$sanitized_amount = (int) give_sanitize_amount($data['give-amount']);
$max_amount = 1000;
//Check for message data
if ($sanitized_amount >= $max_amount) {
give_set_error('give_message', sprintf(__('Sorry, we can\'t accept donations more than %s.', 'give'), give_currency_filter(give_format_amount($max_amount))));
}
}
示例6: give_process_profile_editor_updates
/**
* Process Profile Updater Form.
*
* Processes the profile updater form by updating the necessary fields.
*
* @since 1.0
*
* @param array $data Data sent from the profile editor.
*
* @return bool
*/
function give_process_profile_editor_updates($data)
{
// Profile field change request
if (empty($_POST['give_profile_editor_submit']) && !is_user_logged_in()) {
return false;
}
// Nonce security
if (!wp_verify_nonce($data['give_profile_editor_nonce'], 'give-profile-editor-nonce')) {
return false;
}
$user_id = get_current_user_id();
$old_user_data = get_userdata($user_id);
$display_name = isset($data['give_display_name']) ? sanitize_text_field($data['give_display_name']) : $old_user_data->display_name;
$first_name = isset($data['give_first_name']) ? sanitize_text_field($data['give_first_name']) : $old_user_data->first_name;
$last_name = isset($data['give_last_name']) ? sanitize_text_field($data['give_last_name']) : $old_user_data->last_name;
$email = isset($data['give_email']) ? sanitize_email($data['give_email']) : $old_user_data->user_email;
$line1 = isset($data['give_address_line1']) ? sanitize_text_field($data['give_address_line1']) : '';
$line2 = isset($data['give_address_line2']) ? sanitize_text_field($data['give_address_line2']) : '';
$city = isset($data['give_address_city']) ? sanitize_text_field($data['give_address_city']) : '';
$state = isset($data['give_address_state']) ? sanitize_text_field($data['give_address_state']) : '';
$zip = isset($data['give_address_zip']) ? sanitize_text_field($data['give_address_zip']) : '';
$country = isset($data['give_address_country']) ? sanitize_text_field($data['give_address_country']) : '';
$userdata = array('ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'user_email' => $email);
$address = array('line1' => $line1, 'line2' => $line2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country);
/**
* Fires before updating user profile.
*
* @since 1.0
*
* @param int $user_id The ID of the user.
* @param array $userdata User info, including ID, first name, last name, display name and email.
*/
do_action('give_pre_update_user_profile', $user_id, $userdata);
// New password
if (!empty($data['give_new_user_pass1'])) {
if ($data['give_new_user_pass1'] !== $data['give_new_user_pass2']) {
give_set_error('password_mismatch', esc_html__('The passwords you entered do not match. Please try again.', 'give'));
} else {
$userdata['user_pass'] = $data['give_new_user_pass1'];
}
}
if (empty($email)) {
// Make sure email should not be empty.
give_set_error('email_empty', esc_html__('The email you entered is empty.', 'give'));
} else {
if (!is_email($email)) {
// Make sure email should be valid.
give_set_error('email_not_valid', esc_html__('The email you entered is not valid. Please use another', 'give'));
} else {
if ($email != $old_user_data->user_email) {
// Make sure the new email doesn't belong to another user
if (email_exists($email)) {
give_set_error('email_exists', esc_html__('The email you entered belongs to another user. Please use another.', 'give'));
}
}
}
}
// Check for errors
$errors = give_get_errors();
if ($errors) {
// Send back to the profile editor if there are errors
wp_redirect($data['give_redirect']);
give_die();
}
// Update the user
$meta = update_user_meta($user_id, '_give_user_address', $address);
$updated = wp_update_user($userdata);
if ($updated) {
/**
* Fires after updating user profile.
*
* @since 1.0
*
* @param int $user_id The ID of the user.
* @param array $userdata User info, including ID, first name, last name, display name and email.
*/
do_action('give_user_profile_updated', $user_id, $userdata);
wp_redirect(add_query_arg('updated', 'true', $data['give_redirect']));
give_die();
}
return false;
}
示例7: give_set_error
give_set_error('give_recaptcha_connection_issue', apply_filters('give_recaptcha_connection_issue_message', __('Unable to connect to reCAPTCHA server', 'give')));
}
} else {
give_set_error('give_recaptcha_failed', apply_filters('give_recaptcha_failed_message', __('Sorry, it looks like the reCAPTCHA test has failed', 'give')));
}
}
//If no errors or only expired token key error - then send email
if (!give_get_errors()) {
$customer = Give()->customers->get_customer_by('email', $email);
if (isset($customer->id)) {
if (Give()->email_access->can_send_email($customer->id)) {
Give()->email_access->send_email($customer->id, $email);
$show_form = false;
}
} else {
give_set_error('give_no_donor_email_exists', apply_filters('give_no_donor_email_exists_message', __('Sorry, it looks like that donor email address does not exist', 'give')));
}
}
}
//Print any messages & errors
give_print_errors(0);
//Show the email login form?
if ($show_form) {
?>
<div class="give-form">
<?php
if (!give_get_errors()) {
give_output_error(__('Please enter the email address you used for your donation. A verification email containing an access link will be sent to you.', 'give'), true);
}
示例8: give_purchase_form_validate_cc
/**
* Validates the credit card info
*
* @access private
* @since 1.0
* @return array
*/
function give_purchase_form_validate_cc()
{
$card_data = give_get_purchase_cc_info();
// Validate the card zip
if (!empty($card_data['card_zip'])) {
if (!give_purchase_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) {
give_set_error('invalid_cc_zip', esc_html__('The zip / postal code you entered for your billing address is invalid.', 'give'));
}
}
//Ensure no spaces
if (!empty($card_data['card_number'])) {
$card_data['card_number'] = str_replace('+', '', $card_data['card_number']);
//no "+" signs
$card_data['card_number'] = str_replace(' ', '', $card_data['card_number']);
// No spaces
}
// This should validate card numbers at some point too
return $card_data;
}
示例9: give_check_purchase_email
/**
* Check the purchase to ensure a banned email is not allowed through
*
* @since 1.0
* @return void
*/
function give_check_purchase_email($valid_data, $posted)
{
$is_banned = false;
$banned = give_get_banned_emails();
if (empty($banned)) {
return;
}
if (is_user_logged_in()) {
// The user is logged in, check that their account email is not banned
$user_data = get_userdata(get_current_user_id());
if (give_is_email_banned($user_data->user_email)) {
$is_banned = true;
}
if (give_is_email_banned($posted['give_email'])) {
$is_banned = true;
}
} elseif (isset($posted['give-purchase-var']) && $posted['give-purchase-var'] == 'needs-to-login') {
// The user is logging in, check that their email is not banned
$user_data = get_user_by('login', $posted['give_user_login']);
if ($user_data && give_is_email_banned($user_data->user_email)) {
$is_banned = true;
}
} else {
// Guest purchase, check that the email is not banned
if (give_is_email_banned($posted['give_email'])) {
$is_banned = true;
}
}
if ($is_banned) {
// Set an error and give the donor a general error (don't alert them that they were banned)
give_set_error('email_banned', __('An internal error has occurred, please try again or contact support.', 'give'));
}
}
示例10: is_valid_token
/**
* Is this a valid token?
*
* @since 1.0
* @access public
*
* @param $token The token.
*
* @return bool
*/
public function is_valid_token($token)
{
global $wpdb;
// Make sure token isn't expired
$expires = date('Y-m-d H:i:s', time() - $this->token_expiration);
$email = $wpdb->get_var($wpdb->prepare("SELECT email FROM {$wpdb->prefix}give_customers WHERE token = %s AND verify_throttle >= %s LIMIT 1", $token, $expires));
if (!empty($email)) {
$this->token_email = $email;
$this->token = $token;
return true;
}
//Set error only if email access form isn't being submitted
if (!isset($_POST['give_email']) && !isset($_POST['_wpnonce'])) {
give_set_error('give_email_token_expired', apply_filters('give_email_token_expired_message', 'Sorry, your access token has expired. Please request a new one below:', 'give'));
}
return false;
}
示例11: give_process_register_form
/**
* Process Register Form
*
* @since 2.0
*
* @param array $data Data sent from the register form
*
* @return void
*/
function give_process_register_form($data)
{
if (is_user_logged_in()) {
return;
}
if (empty($_POST['give_register_submit'])) {
return;
}
do_action('give_pre_process_register_form');
if (empty($data['give_user_login'])) {
give_set_error('empty_username', __('Invalid username', 'give'));
}
if (username_exists($data['give_user_login'])) {
give_set_error('username_unavailable', __('Username already taken', 'give'));
}
if (!validate_username($data['give_user_login'])) {
give_set_error('username_invalid', __('Invalid username', 'give'));
}
if (email_exists($data['give_user_email'])) {
give_set_error('email_unavailable', __('Email address already taken', 'give'));
}
if (empty($data['give_user_email']) || !is_email($data['give_user_email'])) {
give_set_error('email_invalid', __('Invalid email', 'give'));
}
if (!empty($data['give_payment_email']) && $data['give_payment_email'] != $data['give_user_email'] && !is_email($data['give_payment_email'])) {
give_set_error('payment_email_invalid', __('Invalid payment email', 'give'));
}
if (empty($_POST['give_user_pass'])) {
give_set_error('empty_password', __('Please enter a password', 'give'));
}
if (!empty($_POST['give_user_pass']) && empty($_POST['give_user_pass2']) || $_POST['give_user_pass'] !== $_POST['give_user_pass2']) {
give_set_error('password_mismatch', __('Passwords do not match', 'give'));
}
do_action('give_process_register_form');
// Check for errors and redirect if none present
$errors = give_get_errors();
if (empty($errors)) {
$redirect = apply_filters('give_register_redirect', $data['give_redirect']);
give_register_and_login_new_user(array('user_login' => $data['give_user_login'], 'user_pass' => $data['give_user_pass'], 'user_email' => $data['give_user_email'], 'user_registered' => date('Y-m-d H:i:s'), 'role' => get_option('default_role')));
wp_redirect($redirect);
give_die();
}
}
示例12: check_donation_amount
/**
* Force a different minimum donation amount and show an error if not met
*/
function check_donation_amount($valid_data, $posted)
{
if ($posted['give-amount'] < 5) {
give_set_error('donation_amount', 'The donation amount must be $5 or more. Please go back and select a specified amount or enter a larger donation amount.', 'give');
}
}
示例13: give_update_payment_details
/**
*
* Process the payment details edit
*
* @access private
*
* @param $data
*
* @since 1.0
* @return void
*
*/
function give_update_payment_details($data)
{
if (!current_user_can('edit_give_payments', $data['give_payment_id'])) {
wp_die(__('You do not have permission to edit this payment record', 'give'), __('Error', 'give'), array('response' => 403));
}
check_admin_referer('give_update_payment_details_nonce');
// Retrieve the payment ID
$payment_id = absint($data['give_payment_id']);
// Retrieve existing payment meta
$meta = give_get_payment_meta($payment_id);
$user_info = give_get_payment_meta_user_info($payment_id);
$status = $data['give-payment-status'];
$user_id = isset($data['give-payment-user-id']) ? intval($data['give-payment-user-id']) : '';
$date = sanitize_text_field($data['give-payment-date']);
$hour = sanitize_text_field($data['give-payment-time-hour']);
$form_id = give_get_payment_form_id($payment_id);
// Restrict to our high and low
if ($hour > 23) {
$hour = 23;
} elseif ($hour < 0) {
$hour = 00;
}
$minute = sanitize_text_field($data['give-payment-time-min']);
// Restrict to our high and low
if ($minute > 59) {
$minute = 59;
} elseif ($minute < 0) {
$minute = 00;
}
$address = array_map('trim', $data['give-payment-address'][0]);
$date = date('Y-m-d', strtotime($date)) . ' ' . $hour . ':' . $minute . ':00';
$curr_total = give_sanitize_amount(give_get_payment_amount($payment_id));
$new_total = give_sanitize_amount($_POST['give-payment-total']);
$curr_customer_id = sanitize_text_field($data['give-current-customer']);
$new_customer_id = sanitize_text_field($data['customer-id']);
do_action('give_update_edited_purchase', $payment_id);
// Update main payment record
$updated = wp_update_post(array('ID' => $payment_id, 'edit_date' => true, 'post_date' => $date));
if (0 === $updated) {
wp_die(esc_attr__('Error Updating Payment', 'give'), esc_attr__('Error', 'give'), array('response' => 400));
}
$customer_changed = false;
if (isset($data['give-new-customer']) && $data['give-new-customer'] == '1') {
$email = isset($data['give-new-customer-email']) ? sanitize_text_field($data['give-new-customer-email']) : '';
$names = isset($data['give-new-customer-name']) ? sanitize_text_field($data['give-new-customer-name']) : '';
if (empty($email) || empty($names)) {
wp_die(esc_attr__('New Customers require a name and email address', 'give'));
}
$customer = new Give_Customer($email);
if (empty($customer->id)) {
$customer_data = array('name' => $names, 'email' => $email);
$user_id = email_exists($email);
if (false !== $user_id) {
$customer_data['user_id'] = $user_id;
}
if (!$customer->create($customer_data)) {
// Failed to crete the new customer, assume the previous customer
$customer_changed = false;
$customer = new Give_Customer($curr_customer_id);
give_set_error('give-payment-new-customer-fail', __('Error creating new customer', 'give'));
}
}
$new_customer_id = $customer->id;
$previous_customer = new Give_Customer($curr_customer_id);
$customer_changed = true;
} elseif ($curr_customer_id !== $new_customer_id) {
$customer = new Give_Customer($new_customer_id);
$email = $customer->email;
$names = $customer->name;
$previous_customer = new Give_Customer($curr_customer_id);
$customer_changed = true;
} else {
$customer = new Give_Customer($curr_customer_id);
$email = $customer->email;
$names = $customer->name;
}
// Setup first and last name from input values
$names = explode(' ', $names);
$first_name = !empty($names[0]) ? $names[0] : '';
$last_name = '';
if (!empty($names[1])) {
unset($names[0]);
$last_name = implode(' ', $names);
}
if ($customer_changed) {
// Remove the stats and payment from the previous customer and attach it to the new customer
$previous_customer->remove_payment($payment_id, false);
$customer->attach_payment($payment_id, false);
//.........这里部分代码省略.........
示例14: give_process_authorize_net_payment
/**
* Authorize.net Payments
*
* @param $purchase_data
*/
public function give_process_authorize_net_payment($purchase_data)
{
if (!isset($_POST['card_number']) || $_POST['card_number'] == '') {
give_set_error('empty_card', __('You must enter a card number', 'give'));
}
if (!isset($_POST['card_name']) || $_POST['card_name'] == '') {
give_set_error('empty_card_name', __('You must enter the name on your card', 'give'));
}
if (!isset($_POST['card_exp_month']) || $_POST['card_exp_month'] == '') {
give_set_error('empty_month', __('You must enter an expiration month', 'give'));
}
if (!isset($_POST['card_exp_year']) || $_POST['card_exp_year'] == '') {
give_set_error('empty_year', __('You must enter an expiration year', 'give'));
}
if (!isset($_POST['card_cvc']) || $_POST['card_cvc'] == '' || strlen($_POST['card_cvc']) < 3) {
give_set_error('empty_cvc', __('You must enter a valid CVC', 'give'));
}
$errors = give_get_errors();
//No errors: Continue with payment processing
if (!$errors) {
//Include Authorize SDK
require_once GIVE_AUTHORIZE_PLUGIN_DIR . '/includes/anet_php_sdk/AuthorizeNet.php';
if (!give_is_test_mode()) {
//LIVE:
$authorize_api_login = give_get_option('give_api_login');
$authorize_trans_key = give_get_option('give_transaction_key');
} else {
//SANDBOX
$authorize_api_login = give_get_option('give_authorize_sandbox_api_login');
$authorize_trans_key = give_get_option('give_authorize_sandbox_transaction_key');
}
//Check for credentials entered
if (empty($authorize_api_login) || empty($authorize_trans_key)) {
give_set_error('error_id_here', __('Error: Missing API Login or Transaction key. Please enter them in the plugin settings.', 'give-authorize'));
return;
}
//Proceed with Authorize AIM
$transaction = new AuthorizeNetAIM($authorize_api_login, $authorize_trans_key);
$transaction->VERIFY_PEER = false;
//Sandbox or not?
if (give_is_test_mode()) {
$transaction->setSandbox(true);
} else {
$transaction->setSandbox(false);
}
$card_info = $purchase_data['card_info'];
$card_names = explode(' ', $card_info['card_name']);
$first_name = isset($card_names[0]) ? $card_names[0] : $purchase_data['user_info']['first_name'];
if (!empty($card_names[1])) {
unset($card_names[0]);
$last_name = implode(' ', $card_names);
} else {
$last_name = $purchase_data['user_info']['last_name'];
}
$transaction->amount = $purchase_data['price'];
$transaction->card_num = strip_tags(trim($card_info['card_number']));
$transaction->card_code = strip_tags(trim($card_info['card_cvc']));
$transaction->exp_date = strip_tags(trim($card_info['card_exp_month'])) . '/' . strip_tags(trim($card_info['card_exp_year']));
$transaction->description = give_get_purchase_summary($purchase_data);
$transaction->first_name = $first_name;
$transaction->last_name = $last_name;
$transaction->address = $card_info['card_address'] . ' ' . $card_info['card_address_2'];
$transaction->city = $card_info['card_city'];
$transaction->country = $card_info['card_country'];
$transaction->state = $card_info['card_state'];
$transaction->zip = $card_info['card_zip'];
$transaction->customer_ip = give_get_ip();
$transaction->email = $purchase_data['user_email'];
$transaction->invoice_num = $purchase_data['purchase_key'];
try {
$response = $transaction->authorizeAndCapture();
if ($response->approved) {
$payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), 'price_id' => isset($purchase_data['post_data']['give-price-id']) ? intval($purchase_data['post_data']['give-price-id']) : '', 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => give_get_currency(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'authorizenet');
$payment = give_insert_payment($payment_data);
if ($payment) {
give_update_payment_status($payment, 'publish');
give_send_to_success_page();
} else {
give_set_error('authorize_error', __('Error: your payment could not be recorded. Please try again', 'give'));
give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
}
} else {
if (isset($response->response_reason_text)) {
$error = $response->response_reason_text;
} elseif (isset($response->error_message)) {
$error = $response->error_message;
} else {
$error = '';
}
if (strpos(strtolower($error), 'the credit card number is invalid') !== false) {
give_set_error('invalid_card', __('Your card number is invalid', 'give'));
} elseif (strpos(strtolower($error), 'this transaction has been declined') !== false) {
give_set_error('invalid_card', __('Your card has been declined', 'give'));
} elseif (isset($response->response_reason_text)) {
give_set_error('api_error', $response->response_reason_text);
//.........这里部分代码省略.........
示例15: give_disconnect_customer_user_id
/**
* Disconnect a user ID from a donor
*
* @since 1.0
*
* @param array $args Array of arguements
*
* @return bool If the disconnect was sucessful
*/
function give_disconnect_customer_user_id($args)
{
$customer_edit_role = apply_filters('give_edit_customers_role', 'edit_give_payments');
if (!is_admin() || !current_user_can($customer_edit_role)) {
wp_die(__('You do not have permission to edit this donor.', 'give'));
}
if (empty($args)) {
return;
}
$customer_id = (int) $args['customer_id'];
$nonce = $args['_wpnonce'];
if (!wp_verify_nonce($nonce, 'edit-customer')) {
wp_die(__('Cheatin\' eh?!', 'give'));
}
$customer = new Give_Customer($customer_id);
if (empty($customer->id)) {
return false;
}
do_action('give_pre_customer_disconnect_user_id', $customer_id, $customer->user_id);
$customer_args = array('user_id' => 0);
if ($customer->update($customer_args)) {
global $wpdb;
if (!empty($customer->payment_ids)) {
$wpdb->query("UPDATE {$wpdb->postmeta} SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( {$customer->payment_ids} )");
}
$output['success'] = true;
} else {
$output['success'] = false;
give_set_error('give-disconnect-user-fail', __('Failed to disconnect user from donor', 'give'));
}
do_action('give_post_customer_disconnect_user_id', $customer_id);
if (defined('DOING_AJAX') && DOING_AJAX) {
header('Content-Type: application/json');
echo json_encode($output);
wp_die();
}
return $output;
}