Skip to content

Commit

Permalink
Merge pull request #436 from WordImpress/issue/434
Browse files Browse the repository at this point in the history
Issue/434
  • Loading branch information
Devin Walker committed Dec 14, 2015
2 parents 742f2ab + e515a74 commit f0821cf
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 20 deletions.
4 changes: 2 additions & 2 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: The most robust, flexible, and intuitive way to accept donations on WordPress.
* Author: WordImpress
* Author URI: http://wordimpress.com
* Version: 1.3.3
* Version: 1.3.4
* Text Domain: give
* Domain Path: /languages
*
Expand Down Expand Up @@ -202,7 +202,7 @@ private function setup_constants() {

// Plugin version
if ( ! defined( 'GIVE_VERSION' ) ) {
define( 'GIVE_VERSION', '1.3.3' );
define( 'GIVE_VERSION', '1.3.4' );
}

// Plugin Folder Path
Expand Down
69 changes: 68 additions & 1 deletion includes/admin/upgrades/upgrade-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ function give_show_upgrade_notices() {
*/

//v1.3.2 Upgrades
if ( version_compare( $give_version, '1.3.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_payment_customer_id' )) {
if ( version_compare( $give_version, '1.3.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) {
printf(
'<div class="updated"><p>' . __( 'Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id' ) )
);
}

//v1.3.4 Upgrades //ensure the user has gone through 1.3.4
if ( version_compare( $give_version, '1.3.4', '<' ) || ( ! give_has_upgrade_completed( 'upgrade_give_offline_status' ) && give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) ) {
printf(
'<div class="updated"><p>' . __( 'Give needs to upgrade the transaction database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status' ) )
);
}


// End 'Stepped' upgrade process notices

Expand Down Expand Up @@ -191,3 +199,62 @@ function give_v132_upgrade_give_payment_customer_id() {
}

add_action( 'give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id' );

/**
* Upgrades the Offline Status
*
* @description: Reverses the issue where offline donation transactions in "pending" status where inappropriately marked as abandoned
*
* @since 1.3.4
*
*/
function give_v134_upgrade_give_offline_status() {

global $wpdb;

if ( ! current_user_can( 'manage_give_settings' ) ) {
wp_die( __( 'You do not have permission to do Give upgrades', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
}

ignore_user_abort( true );

if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
@set_time_limit( 0 );
}

// Get abandoned offline payments
$select = "SELECT ID FROM $wpdb->posts p ";
$join = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id ";
$where = "WHERE p.post_type = 'give_payment' ";
$where .= "AND ( p.post_status = 'abandoned' )";
$where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )";

$sql = $select . $join . $where;
$found_payments = $wpdb->get_col( $sql );


foreach ( $found_payments as $payment ) {

//Only change ones marked abandoned since our release last week
//because the admin may have marked some abandoned themselves
$modified_time = get_post_modified_time( 'U', false, $payment );

//1450124863 = 12/10/2015 20:42:25
if ( $modified_time >= 1450124863 ) {

give_update_payment_status( $payment, 'pending' );

}

}

update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
give_set_upgrade_complete( 'upgrade_give_offline_status' );
delete_option( 'give_doing_upgrade' );
wp_redirect( admin_url() );
exit;


}

add_action( 'give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status' );
14 changes: 0 additions & 14 deletions includes/gateways/offline-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ function give_offline_register_gateway( $gateways ) {
add_filter( 'give_payment_gateways', 'give_offline_register_gateway', 1 );


/**
* Disables the automatic marking of abandoned orders
* Marking pending payments as abandoned could break manual check payments
*
* @since 1.0
* @return void
*/
function give_offline_disable_abandoned_orders() {
remove_action( 'give_weekly_scheduled_events', 'give_mark_abandoned_orders' );
}

add_action( 'plugins_loaded', 'give_offline_disable_abandoned_orders' );


/**
* Add our payment instructions to the checkout
*
Expand Down
3 changes: 2 additions & 1 deletion includes/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ function give_install() {

// When new upgrade routines are added, mark them as complete on fresh install
$upgrade_routines = array(
'upgrade_give_payment_customer_id'
'upgrade_give_payment_customer_id',
'upgrade_give_offline_status'
);

foreach ( $upgrade_routines as $upgrade ) {
Expand Down
8 changes: 7 additions & 1 deletion includes/payments/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function give_update_old_payments_with_totals( $data ) {
* @return void
*/
function give_mark_abandoned_donations() {
$args = array(
$args = array(
'status' => 'pending',
'number' => - 1,
'fields' => 'ids'
Expand All @@ -240,6 +240,12 @@ function give_mark_abandoned_donations() {

if ( $payments ) {
foreach ( $payments as $payment ) {
$gateway = give_get_payment_gateway( $payment );
//Skip offline gateway payments
if ( $gateway == 'offline' ) {
continue;
}
//Non-offline get marked as 'abandoned'
give_update_payment_status( $payment, 'abandoned' );
}
}
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: http://givewp.com/
Tags: donation, donations, donation plugin, wordpress donation plugin, wp donation, ecommerce, e-commerce, fundraising, fundraiser, crowdfunding, wordpress donations, commerce, wordpress ecommerce, giving, charity, donate, gifts, non-profit, paypal, stripe, churches, nonprofit, paypal donations, paypal donate, stripe donations, stripe donate, authorize.net, authorize.net donations
Requires at least: 4.0
Tested up to: 4.4.1
Stable tag: 1.3.3
Stable tag: 1.3.4
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -129,6 +129,9 @@ We also really like WooCommerce. It's hands-down the most robust eCommerce platf

== Changelog ==

= 1.3.4 =
* Fixed issue where pending "Offline Donations" payments were inappropriately marked as abandoned - @see: https://github.com/WordImpress/Give/issues/434

= 1.3.3 =
* Fixed security vulnerability due to WP session IDs

Expand Down

0 comments on commit f0821cf

Please sign in to comment.