/**
  * Create class object. A private constructor, so this is used in a singleton context. 
  * 
  * @return 	void
  * @access 	private
  * @since	1.0.0
  */
 private function __construct()
 {
     /* Retrieve the notices from the session */
     $this->notices = charitable_get_session()->get('notices');
     /* Reset the session back to empty */
     charitable_get_session()->set('notices', array('error' => array(), 'warning' => array(), 'success' => array(), 'info' => array()));
 }
 /**
  * Send the password reset email.
  *
  * @return  bool|WP_Error True: when finish. WP_Error on error
  * @access  public
  * @static
  * @since   1.4.0
  */
 public static function retrieve_password()
 {
     $form = new Charitable_Forgot_Password_Form();
     if (!$form->validate_nonce()) {
         return;
     }
     if (empty($_POST['user_login'])) {
         charitable_get_notices()->add_error(__('<strong>ERROR</strong>: Enter a username or email address.', 'charitable'));
         return;
     } elseif (strpos($_POST['user_login'], '@')) {
         $user = get_user_by('email', trim($_POST['user_login']));
     } else {
         $login = trim($_POST['user_login']);
         $user = get_user_by('login', $login);
     }
     do_action('lostpassword_post');
     /* If we are missing user data, proceed no further. */
     if (!$user) {
         charitable_get_notices()->add_error(__('<strong>ERROR</strong>: Invalid username or email.', 'charitable'));
         return;
     }
     /* Prepare the email. */
     $email = new Charitable_Email_Password_Reset(array('user' => $user));
     $reset_link = $email->get_reset_link();
     /* Make sure that the reset link was generated correctly. */
     if (is_wp_error($reset_link)) {
         charitable_get_notices()->add_errors_from_wp_error($reset_link);
         return;
     }
     $sent = $email->send();
     if (!$sent) {
         charitable_get_notices()->add_error(__('We were unable to send your password reset email.', 'charitable'));
         return;
     }
     charitable_get_notices()->add_success(__('Your password reset request has been received. Please check your email for a link to reset your password.', 'charitable'));
     charitable_get_session()->add_notices();
     $redirect_url = esc_url_raw(charitable_get_permalink('login_page'));
     wp_safe_redirect($redirect_url);
     exit;
 }
 function test_charitable_get_session()
 {
     $this->assertInstanceOf('Charitable_Session', charitable_get_session());
 }
 /**
  * Checks whether the donation is from the current user.
  *
  * @return  boolean
  * @access  public
  * @since   1.4.0
  */
 public function is_from_current_user()
 {
     /* If the donation key is stored in the session, the user can access this receipt */
     if (charitable_get_session()->has_donation_key($this->get_donation_key())) {
         return true;
     }
     if (!is_user_logged_in()) {
         return false;
     }
     /* Retrieve the donor and current logged in user */
     $donor = $this->get_donor();
     $user = wp_get_current_user();
     /* Make sure they match */
     if ($donor->ID) {
         return $donor->ID == $user->ID;
     }
     return $donor->get_email() == $user->user_email;
 }
 /**
  * Save the submitted donation.
  *
  * @return  int|false   If successful, this returns the donation ID. If unsuccessful, returns false.
  * @access  public
  * @since   1.0.0
  */
 public function save_donation()
 {
     $campaign_id = charitable_get_current_campaign_id();
     if (!$campaign_id) {
         return 0;
     }
     if (!$this->validate_nonce()) {
         return 0;
     }
     /* Set the donation amount */
     $campaign_id = $this->get_campaign()->ID;
     $amount = parent::get_donation_amount();
     if (0 == $amount && !apply_filters('charitable_permit_empty_donations', false)) {
         charitable_get_notices()->add_error(__('No donation amount was set.', 'charitable'));
         return false;
     }
     /* Create or update the donation object in the session, with the current campaign ID. */
     charitable_get_session()->add_donation($campaign_id, $amount);
     do_action('charitable_donation_amount_form_submit', $campaign_id, $amount);
     return true;
 }
 /**
  * Returns the current campaign ID. If there is no current campaign, return 0. 
  *
  * @return 	int
  * @access  public
  * @since 	1.0.0
  */
 public function get_current_campaign_id()
 {
     if (isset($this->campaign) && $this->campaign) {
         $this->campaign_id = $this->campaign->ID;
     } else {
         $this->campaign_id = 0;
         if (get_post_type() == Charitable::CAMPAIGN_POST_TYPE) {
             $this->campaign_id = get_the_ID();
         } elseif (get_query_var('donate', false)) {
             $session_donation = charitable_get_session()->get('donation');
             if (false !== $session_donation) {
                 $this->campaign_id = $session_donation->get('campaign_id');
             }
         }
     }
     if (!$this->campaign_id) {
         $this->campaign_id = $this->get_campaign_id_from_submission();
     }
     return $this->campaign_id;
 }
 /**
  * Redirect back to the donation form, sending the donation ID back.
  *
  * @param   int $donation_id
  * @return  void
  * @access  private
  * @since   1.0.0
  */
 private function redirect_to_donation_form($donation_id)
 {
     charitable_get_session()->add_notices();
     $redirect_url = esc_url(add_query_arg(array('donation_id' => $donation_id), wp_get_referer()));
     wp_safe_redirect($redirect_url);
     die;
 }
 /**
  * Returns the amount to be donated to the campaign as it is currently set in the session.
  *
  * @return  int
  * @access  public
  * @since   1.0.0
  */
 public function get_donation_amount_in_session()
 {
     $donation = charitable_get_session()->get_donation_by_campaign($this->ID);
     $amount = is_array($donation) ? $donation['amount'] : 0;
     return apply_filters('charitable_session_donation_amount', $amount, $this);
 }
 /**
  * Clear out all existing notices.
  *
  * @return  void
  * @access  public
  * @since   1.4.0
  */
 public function clear()
 {
     $clear = array('error' => array(), 'warning' => array(), 'success' => array(), 'info' => array());
     $this->notices = $clear;
     charitable_get_session()->set('notices', $clear);
 }
 /**
  * Inserts a new donation.
  *
  * This method is designed to be completely form agnostic. 
  *
  * We use this when integrating third-party systems like Easy Digital Downloads and 
  * WooCommerce. 
  *
  * @param   mixed[] $values
  * @return  int $donation_id    Returns 0 in case of failure. Positive donation ID otherwise.
  * @access  public
  * @since   1.0.0
  */
 public function save_donation(array $values)
 {
     /**
      * @hook charitable_donation_values
      */
     $this->donation_data = apply_filters('charitable_donation_values', $values);
     if (!$this->get_campaign_donations_data()) {
         _doing_it_wrong(__METHOD__, 'A donation cannot be inserted without an array of campaigns being donated to.', '1.0.0');
         return 0;
     }
     if (!$this->is_valid_user_data()) {
         _doing_it_wrong(__METHOD__, 'A donation cannot be inserted without valid user data.', '1.0.0');
         return 0;
     }
     /**
      * @hook charitable_before_save_donation
      */
     do_action('charitable_before_save_donation', $this);
     $donation_id = wp_insert_post($this->parse_donation_data());
     $this->set_donation_key();
     if (is_wp_error($donation_id)) {
         charitable_get_notices()->add_errors_from_wp_error($donation_id);
         return 0;
     }
     if (0 == $donation_id) {
         charitable_get_notices()->add_error(__('We were unable to save the donation. Please try again.', 'charitable'));
         return 0;
     }
     $this->save_campaign_donations($donation_id);
     $this->save_donation_meta($donation_id);
     $this->update_donation_log($donation_id, __('Donation created.', 'charitable'));
     if (!is_admin()) {
         charitable_get_session()->add_donation_key($this->get_donation_data_value('donation_key'));
     }
     /**
      * @hook charitable_after_save_donation
      */
     do_action('charitable_after_save_donation', $donation_id, $this);
     return $donation_id;
 }
 /**
  * Check if a failed user login attempt originated from Charitable login form. 
  *
  * If so redirect user to Charitable login page.
  *
  * @param 	WP_User|WP_Error $user_or_error
  * @param 	string 			 $username
  * @return  WP_User|void
  * @access  public
  * @since   1.4.0
  */
 public function maybe_redirect_at_authenticate($user_or_error, $username)
 {
     if ('POST' != $_SERVER['REQUEST_METHOD']) {
         return $user_or_error;
     }
     if (!is_wp_error($user_or_error)) {
         return $user_or_error;
     }
     if (!isset($_POST['charitable']) || !$_POST['charitable']) {
         return $user_or_error;
     }
     foreach ($user_or_error->errors as $code => $error) {
         /* Make sure the error messages link to our forgot password page, not WordPress' */
         switch ($code) {
             case 'invalid_email':
                 $error = __('<strong>ERROR</strong>: Invalid email address.', 'charitable') . ' <a href="' . esc_url(charitable_get_permalink('forgot_password_page')) . '">' . __('Lost your password?') . '</a>';
                 break;
             case 'incorrect_password':
                 $error = sprintf(__('<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.'), '<strong>' . $email . '</strong>') . ' <a href="' . esc_url(charitable_get_permalink('forgot_password_page')) . '">' . __('Lost your password?') . '</a>';
                 break;
             default:
                 $error = $error[0];
         }
         charitable_get_notices()->add_error($error);
     }
     charitable_get_session()->add_notices();
     $redirect_url = charitable_get_permalink('login_page');
     if (strlen($username)) {
         $redirect_url = add_query_arg('username', $username, $redirect_url);
     }
     wp_safe_redirect(esc_url_raw($redirect_url));
     exit;
 }
 /**
  * Reset the password.
  *
  * @return  bool|WP_Error True: when finish. WP_Error on error
  * @access  public
  * @static
  * @since   1.4.0
  */
 public static function reset_password()
 {
     $form = new Charitable_Reset_Password_Form();
     if (!$form->validate_nonce() || !$form->validate_honeypot()) {
         charitable_get_notices()->add_error(__('There was an error with processing your form submission. Please reload the page and try again.', 'charitable'));
         return;
     }
     /* The key and login must be set. */
     if (!isset($_POST['key']) || !isset($_POST['login'])) {
         charitable_get_notices()->add_error('<strong>ERROR:</strong> Invalid reset key.', 'charitable');
         return;
     }
     $user = check_password_reset_key($_POST['key'], $_POST['login']);
     if (is_wp_error($user)) {
         charitable_get_notices()->add_errors_from_wp_error($user);
         return;
     }
     /* One of the passwords was not set. */
     if (!isset($_POST['pass1']) || !isset($_POST['pass2'])) {
         charitable_get_notices()->add_error('<strong>ERROR:</strong> You must enter both passwords.', 'charitable');
         return;
     }
     /* The passwords do not match. */
     if ($_POST['pass1'] != $_POST['pass2']) {
         charitable_get_notices()->add_error(__('<strong>ERROR:</strong> The two passwords you entered don\'t match.', 'charitable'));
         return;
     }
     /* Parameter checks OK, reset password */
     reset_password($user, $_POST['pass1']);
     charitable_get_notices()->add_success(__('Your password was successfully changed.', 'charitable'));
     charitable_get_session()->add_notices();
     wp_safe_redirect(charitable_get_permalink('login_page'));
     exit;
 }
/**
 * Checks if this is happening right after a donation.
 *
 * This method is called on the init hook.
 *
 * @return  boolean
 * @access  public
 * @since   1.4.0
 */
function charitable_is_after_donation()
{
    $processor = get_transient('charitable_donation_' . charitable_get_session()->get_session_id());
    if (!$processor) {
        return;
    }
    do_action('charitable_after_donation', $processor);
    foreach ($processor->get_campaign_donations_data() as $campaign_donation) {
        charitable_get_session()->remove_donation($campaign_donation['campaign_id']);
    }
    delete_transient('charitable_donation_' . charitable_get_session()->get_session_id());
}
 /**
  * Redirect the user after the gateway has processed the donation.
  *
  * @uses    Charitable_Donation_Processor::get_redirection_after_gateway_processing()
  *
  * @param   mixed $gateway_processing
  * @return  void
  * @access  private
  * @since   1.3.0
  */
 private function redirect_after_gateway_processing($gateway_processing)
 {
     $redirect_url = $this->get_redirection_after_gateway_processing($gateway_processing);
     /* If the gateway processing failed, add the error notices to the session. */
     if (false == $gateway_processing) {
         /* Log the failed payment. */
         $this->update_donation_log($this->donation_id, sprintf(__('Payment failed with errors: %s', 'charitable'), PHP_EOL . implode(PHP_EOL, charitable_get_notices()->get_errors())));
         charitable_get_session()->add_notices();
     }
     /* Set the redirect status to use. */
     $status = isset($gateway_processing['status']) ? $gateway_processing['status'] : 302;
     /**
      * If the gateway processing returned an array with a directive to NOT
      * use wp_safe_redirect, use wp_redirect instead.
      */
     if (isset($gateway_processing['safe']) && false == $gateway_processing['safe']) {
         wp_redirect($redirect_url, $status);
         die;
     }
     wp_safe_redirect($redirect_url, $status);
     die;
 }
Beispiel #15
0
<?php

/**
 * Displays the donate button to be displayed on campaign pages. 
 *
 * @author 	Studio 164a
 * @since 	1.0.0
 */
$campaign = $view_args['campaign'];
?>
<form class="campaign-donation" method="post">
	<?php 
wp_nonce_field('charitable-donate-' . charitable_get_session()->get_session_id(), 'charitable-donate-now');
?>
	<input type="hidden" name="charitable_action" value="start_donation" />
	<input type="hidden" name="campaign_id" value="<?php 
echo $campaign->ID;
?>
" />
	<input type="submit" name="charitable_submit" value="<?php 
esc_attr_e('Donate', 'charitable');
?>
" class="donate-button button button-primary" />
</form>
/**
 * Checks if this is happening right after a donation.
 *
 * This method is called on the init hook.
 *
 * @return  boolean
 * @access  public
 * @since   1.4.0
 */
function charitable_is_after_donation()
{
    $processor = get_transient('charitable_donation_' . charitable_get_session()->get_session_id());
    if (!$processor) {
        return;
    }
    do_action('charitable_after_donation', $processor);
    delete_transient('charitable_donation_' . charitable_get_session()->get_session_id());
}