Plugin Directory

Changeset 1497327


Ignore:
Timestamp:
09/17/2016 05:07:38 AM (10 years ago)
Author:
rossdev
Message:

Added conditional logic to form settings

Location:
wpf-gravityforms/trunk
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • wpf-gravityforms/trunk/README.txt

    r1404179 r1497327  
    44Donate link: https://wpfortify.com
    55Requires at least: 3.9
    6 Tested up to: 4.5
    7 Stable tag: 2.2.0
     6Tested up to: 4.6
     7Stable tag: 2.3.0
    88License: GPLv2+
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8181
    8282== Changelog ==
     83= 2.3.0 =
     84* Added conditional logic to form settings.
     85
    8386= 2.2.0 =
    8487* Added notification delays.
  • wpf-gravityforms/trunk/wpf-gravityforms.php

    r1212346 r1497327  
    44Plugin URI: http://wordpress.org/plugins/wpf-gravityforms/
    55Description: wpFortify provides a hosted SSL checkout page for Stripe payments. A free wpFortify account is required for this plugin to work.
    6 Version: 2.2.0
     6Version: 2.3.0
    77Author: wpFortify
    88Author URI: https://wpfortify.com
     9Text Domain: wpf-gravityforms
     10Domain Path: /languages
    911License: GPLv2+
    1012License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2224    class WPF_GF extends GFAddOn {
    2325
    24         protected $_version = '2.2.0';
     26        protected $_version = '2.3.0';
    2527        protected $_min_gravityforms_version = '1.8.9';
    2628        protected $_slug = 'wpf-gravityforms';
     
    7476
    7577            return array(
    76 
    7778                array(
    7879                    'title'  => __( 'wpFortify', 'wpf-gravityforms' ),
     
    9495                            'required' => true
    9596                        )
    96 
    9797                    ),
    98 
    9998                )
    100 
    10199            );
    102100
     
    109107
    110108            return array(
    111 
    112109                array(
    113110                    'title' => 'General Settings',
     
    136133                    )
    137134                ),
    138 
    139135                array(
    140136                    'title' => 'Basic',
     
    161157                    )
    162158                ),
    163 
    164159                array(
    165160                    'title' => 'Checkout Settings',
     
    202197                            'tooltip' => '<h6>' . __( 'Notifications', 'wpf-gravityforms' ) . '</h6>' . __( "Enable this option if you would like to only send out this form's notifications after payment has been received. Leaving this option disabled will send notifications immediately after the form is submitted.", 'wpf-gravityforms' )
    203198                        ),
     199                        array(
     200                            'name'  => 'conditional_logic',
     201                            'label' => __( 'Conditional Logic', 'wpf-gravityforms'),
     202                            'type'  => 'conditional_logic',
     203                        ),
    204204                    )
    205205                ),
    206 
    207206                array(
    208207                    'title' => 'Optional Settings',
     
    263262                    )
    264263                )
    265 
    266264            );
    267265
     
    274272
    275273            $order = $this->get_form_settings( $form );
    276 
    277             if ( $order['enable'] ){
    278 
    279                 $testmode    = $order['testmode'] === '1' ? true : false;
     274            $conditional_logic = $this->is_conditional_logic_met( $form, $lead );
     275
     276            if ( $order['enable'] && $conditional_logic ){
     277
    280278                $site_url    = get_bloginfo( 'url' );
    281                 $return_url  = $order['return_url'];
    282                 $cancel_url  = $order['cancel_url'];
    283                 $site_title  = get_bloginfo();
    284279                $description = sprintf( '%s %s ($%s)', __( 'Order #', 'wpf-gravityforms' ), $lead['id'], $lead[$order['paymentAmount']] );
    285280                $button      = __( 'Pay with Card', 'wpf-gravityforms' );
    286 
    287                 if ( !$return_url ){
    288 
    289                     $return_url = $site_url;
    290 
    291                 }
    292 
    293                 if ( !$cancel_url ){
    294 
    295                     $cancel_url = $site_url;
    296 
    297                 }
    298 
    299                 if ( $order['site_title'] ) {
    300 
    301                     $site_title = $order['site_title'];
    302 
    303                 }
    304281
    305282                if ( $order['description'] ) {
     
    321298                        'version'      => $this->_version,
    322299                        'action'       => 'charge_card',
    323                         'site_title'   => $site_title,
     300                        'site_title'   => $order['site_title'] ?: get_bloginfo(),
    324301                        'site_url'     => $site_url,
    325302                        'listen_url'   => $site_url . '/?wpf-gravityforms=callback',
    326                         'return_url'   => $return_url,
    327                         'cancel_url'   => $cancel_url,
     303                        'return_url'   => $order['return_url'] ?: $site_url,
     304                        'cancel_url'   => $order['cancel_url'] ?: $site_url,
    328305                        'image_url'    => $order['image_url'],
    329306                        'customer_id'  => '',
     
    334311                        'button'       => $button,
    335312                        'currency'     => $order['currency'],
    336                         'testmode'     => $testmode,
     313                        'testmode'     => $order['testmode'] === '1' ? true : false,
    337314                        'capture'      => true,
    338315                        'metadata'     => array(
     
    353330
    354331                    GFAPI::update_entry_property( $lead['id'], 'payment_status', 'Pending' );
    355                     $url = $order['custom_checkout'];
    356 
    357                     if ( !$url ){
    358 
    359                         $url = 'https://checkout.wpfortify.com/';
    360 
    361                     }
    362 
     332                    $url = $order['custom_checkout'] ?: 'https://checkout.wpfortify.com/';
    363333                    $check_out = sprintf( '%s/token/%s/', untrailingslashit( $url ), $response->token );
    364334
     
    458428
    459429            return $html;
     430
    460431        }
    461432
     
    468439
    469440            return isset( $form[ 'wpf-gravityforms' ]['delayNotification'] ) && in_array( $notification['id'], $selected_notifications ) ? true : $is_disabled;
    470         }
     441
     442        }
     443
     444        /**
     445         * Conditional Logic settings for form
     446         */
     447        public function settings_conditional_logic( $field, $echo = true ) {
     448
     449            $name = 'conditional_logic';
     450
     451            $checkbox_field = array(
     452                'name'    => $name,
     453                'type'    => 'checkbox',
     454                'choices' => array(
     455                    array(
     456                        'label' => __( 'Enable Conditional Logic.', 'wpf-gravityforms' ),
     457                        'name'  => $name . '_enabled',
     458                    ),
     459                ),
     460                'onclick' => "if(this.checked){jQuery('#{$name}_condition_container').slideDown();} else{jQuery('#{$name}_condition_container').slideUp();}",
     461            );
     462
     463            $is_enabled      = $this->get_setting( $name . '_enabled' ) == '1';
     464            $container_style = ! $is_enabled ? "style='display:none;'" : '';
     465
     466            $str = sprintf( "%s<div id='%s_condition_container' %s><br>%s<br>%s</div>",
     467                $this->settings_checkbox( $checkbox_field, false ),
     468                $name,
     469                $container_style,
     470                __( 'Submit form to wpFortify if the following match:', 'wpf-gravityforms' ),
     471                $this->simple_condition( $name )
     472            );
     473
     474            echo $str;
     475
     476        }
     477
     478        /**
     479         * Get conditional logic fields
     480         */
     481        public function get_conditional_logic_fields() {
     482
     483            $form   = $this->get_current_form();
     484            $fields = array();
     485            foreach ( $form['fields'] as $field ) {
     486                if ( $field->is_conditional_logic_supported() ) {
     487                    $inputs = $field->get_entry_inputs();
     488
     489                    if ( $inputs ) {
     490                        $choices = array();
     491
     492                        foreach ( $inputs as $input ) {
     493                            if ( rgar( $input, 'isHidden' ) ) {
     494                                continue;
     495                            }
     496                            $choices[] = array(
     497                                'value' => $input['id'],
     498                                'label' => GFCommon::get_label( $field, $input['id'], true )
     499                            );
     500                        }
     501
     502                        if ( ! empty( $choices ) ) {
     503                            $fields[] = array( 'choices' => $choices, 'label' => GFCommon::get_label( $field ) );
     504                        }
     505
     506                    } else {
     507                        $fields[] = array( 'value' => $field->id, 'label' => GFCommon::get_label( $field ) );
     508                    }
     509
     510                }
     511            }
     512
     513            return $fields;
     514
     515        }
     516
     517        /**
     518         * Check if conditional logic fields match
     519         */
     520        public function is_conditional_logic_met( $form, $lead ) {
     521
     522            $settings = $this->get_form_settings( $form );
     523
     524            $name       = 'conditional_logic';
     525            $is_enabled = rgar( $settings, $name . '_enabled' );
     526
     527            if ( ! $is_enabled ) {
     528                // The setting is not enabled so we handle it as if the rules are met.
     529
     530                return true;
     531            }
     532
     533            // Build the logic array to be used by Gravity Forms when evaluating the rules.
     534            $logic = array(
     535                'logicType' => 'all',
     536                'rules'     => array(
     537                    array(
     538                        'fieldId'  => rgar( $settings, $name . '_field_id' ),
     539                        'operator' => rgar( $settings, $name . '_operator' ),
     540                        'value'    => rgar( $settings, $name . '_value' ),
     541                    ),
     542                )
     543            );
     544
     545            return GFCommon::evaluate_conditional_logic( $logic, $form, $lead );
     546
     547        }
     548
    471549
    472550        /**
Note: See TracChangeset for help on using the changeset viewer.