Merge pull request #9770 from woothemes/issue/9769-set-current-gateway-php-fatal

Avoid PHP errors when setting the current gateway.
This commit is contained in:
Mike Jolley 2015-12-07 10:00:44 +00:00
commit eb0a5e1d87
1 changed files with 26 additions and 3 deletions

View File

@ -158,15 +158,38 @@ class WC_Payment_Gateways {
/**
* Set the current, active gateway.
*
* @access public
* @param array $gateway Available payment gateways.
*/
public function set_current_gateway( $gateways ) {
// Be on the defensive
if ( ! is_array( $gateways ) || empty( $gateways ) ) {
return;
}
$current = WC()->session->get( 'chosen_payment_method' );
if ( isset( $gateways[ $current ] ) ) {
$gateways[ $current ]->set_current();
if ( $current && isset( $gateways[ $current ] ) ) {
$current_gateway = $gateways[ $current ];
} else {
current( $gateways )->set_current();
$current_gateway = current( $gateways );
}
// Ensure we can make a call to set_current() without triggering an error
if ( $current_gateway && is_callable( array( $current_gateway, 'set_current' ) ) ) {
$current_gateway->set_current();
}
}
/**