Making WordPress.org

Changeset 7399


Ignore:
Timestamp:
07/10/2018 04:29:18 PM (8 years ago)
Author:
coreymckrill
Message:

WordCamp Tickets: Update sandbox detection

Previously the sandbox detection function was checking the sandbox option for
every payment method, even if it wasn't currently enabled. Now, it only searches
through the options of enabled payment methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php

    r7398 r7399  
    4949 * If they open ticket sales while in sandbox mode, then attendees will be confused, etc.
    5050 *
    51  * @todo This should probably be moved to CampTix itself, except for the check for the 'wordcamp-sandbox' account,
    52  * which can stay here.
     51 * @todo This should probably be moved to CampTix itself.
    5352 */
    5453function show_sandbox_mode_warning() {
    … …  
    6968
    7069        if ( $camptix_post_type || $camptix_shortcode_page ) {
    71                 $sandbox = false;
    72 
    73                 // If any payment addons are in sandbox mode
    74                 foreach ( $camptix_options as $option_key => $option_value ) {
    75                         if ( 'payment_options_' === substr( $option_key, 0, 16 ) ) {
    76                                 if ( isset( $option_value['sandbox'] ) && true === $option_value['sandbox'] ) {
    77                                         $sandbox = true;
    78                                 }
    79                         }
    80                 }
    81 
    82                 // If the WordCamp sandbox is picked from the predefs
    83                 if ( ! empty( $camptix_options['payment_options_paypal']['api_predef'] ) ) {
    84                         if ( 'wordcamp-sandbox' == $camptix_options['payment_options_paypal']['api_predef'] ) {
    85                                 $sandbox = true;
    86                         }
    87                 }
    88 
    89                 if ( ! empty( $camptix_options['payment_options_stripe']['api_predef'] ) ) {
    90                         if ( 'wpcs-sandbox' == $camptix_options['payment_options_stripe']['api_predef'] ) {
    91                                 $sandbox = true;
    92                         }
    93                 }
     70                $sandboxed = is_sandboxed();
    9471
    9572                // And the event is not archived
    96                 if ( $sandbox && ! $camptix_options['archived'] ) {
     73                if ( $sandboxed && ! $camptix_options['archived'] ) {
    9774                        require_once( __DIR__ . '/views/notice-sandbox-mode.php' );
    9875                }
    9976        }
     77}
     78
     79/**
     80 * Returns true if CampTix is running in sandbox mode.
     81 *
     82 * @todo This should probably be moved to CampTix itself, except for the check for the 'wordcamp-sandbox' account.
     83 *
     84 * @return bool
     85 */
     86function is_sandboxed() {
     87        /** @var $camptix CampTix_Plugin */
     88        global $camptix;
     89        static $is_sandboxed = null;
     90
     91        if ( ! is_null( $is_sandboxed ) ) {
     92                return $is_sandboxed;
     93        }
     94
     95        $options      = $camptix->get_options();
     96        $is_sandboxed = false;
     97
     98        $enabled_payment_methods = array_keys( $camptix->get_enabled_payment_methods() );
     99
     100        foreach ( $enabled_payment_methods as $method_id ) {
     101                switch ( $method_id ) {
     102                        case 'stripe':
     103                                $sandbox_predef = 'wpcs-sandbox';
     104                                break;
     105                        case 'paypal':
     106                                $sandbox_predef = 'wordcamp-sandbox';
     107                                break;
     108                        default:
     109                                $sandbox_predef = false;
     110                                break;
     111                }
     112
     113                if ( $sandbox_predef && isset( $options[ 'payment_options_' . $method_id ]['api_predef'] ) && $sandbox_predef === $options[ 'payment_options_' . $method_id ]['api_predef'] ) {
     114                        $is_sandboxed = true;
     115                        break;
     116                }
     117
     118                $not_predef = ! isset( $options[ 'payment_options_' . $method_id ]['api_predef'] ) || ! $options[ 'payment_options_' . $method_id ]['api_predef'];
     119
     120                if ( $not_predef && isset( $options[ 'payment_options_' . $method_id ]['sandbox'] ) && true === $options[ 'payment_options_' . $method_id ]['sandbox'] ) {
     121                        $is_sandboxed = true;
     122                        break;
     123                }
     124        }
     125
     126        return $is_sandboxed;
    100127}
    101128
    … …  
    344371
    345372/**
    346  * Returns true if CampTix is running in sandbox mode.
    347  *
    348  * @return bool
    349  */
    350 function is_sandboxed() {
    351         /** @var $camptix CampTix_Plugin */
    352         global $camptix;
    353         static $is_sandboxed = null;
    354 
    355         if ( ! is_null( $is_sandboxed ) ) {
    356                 return $is_sandboxed;
    357         }
    358 
    359         $options      = $camptix->get_options();
    360         $is_sandboxed = false;
    361 
    362         // If the PayPal sandbox checkbox is set to true in manual settings
    363         if ( isset( $options['payment_options_paypal']['sandbox'] ) && $options['payment_options_paypal']['sandbox'] ) {
    364                 $is_sandboxed = true;
    365         }
    366         if ( isset( $options['payment_options_stripe']['sandbox'] ) && $options['payment_options_stripe']['sandbox'] ) {
    367                 $is_sandboxed = true;
    368         }
    369 
    370         // If the WordCamp sandbox is picked from the predefs
    371         if ( ! empty( $options['payment_options_paypal']['api_predef'] ) && 'wordcamp-sandbox' == $options['payment_options_paypal']['api_predef'] ) {
    372                 $is_sandboxed = true;
    373         }
    374         if ( ! empty( $options['payment_options_stripe']['api_predef'] ) && 'wpcs-sandbox' == $options['payment_options_stripe']['api_predef'] ) {
    375                 $is_sandboxed = true;
    376         }
    377 
    378         return $is_sandboxed;
    379 }
    380 
    381 /**
    382373 * Assign the template with no sidebar to the Attendees page
    383374 *
Note: See TracChangeset for help on using the changeset viewer.