Plugin Directory

Changeset 2817109


Ignore:
Timestamp:
11/12/2022 10:07:36 PM (3 years ago)
Author:
wp2pgpmail
Message:

Adding the new filter gform_notification_settings_fields introduced with Gravity Forms v2.5

Location:
gf-pushover-add-on/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gf-pushover-add-on/trunk/class-gf-pushover.php

    r1869241 r2817109  
    2727        parent::init();
    2828        add_filter( 'gform_notification_services', array( $this, 'add_pushover_notification_service' ) );
    29         add_filter( 'gform_pre_send_email', array( $this, 'maybe_send_pushover_notification' ), 19, 3 );
     29        add_filter( 'gform_pre_send_email', array( $this, 'maybe_send_pushover_notification' ), 10, 4 );
    3030        add_action( 'admin_enqueue_scripts', array( $this, 'gform_pushover_ui_injector' ), 998 );
    31         add_filter( 'gform_notification_ui_settings', array( $this, 'gform_pushover_notification_setting'), 10, 3 );
    32         add_filter( 'gform_notification_validation', array( $this, 'gform_pushover_notification_validation'), 10, 3 );
     31        add_filter( 'gform_notification_settings_fields', array( $this, 'gform_pushover_notification_settings_fields'), 10, 3 );
    3332        add_filter( 'gform_pre_notification_save', array( $this, 'gform_pushover_notification_setting_save'), 10, 2 );
    3433    }
     
    5049   
    5150    public function maybe_send_pushover_notification( $email, $message_format, $notification ) {
    52         if ( rgar( $notification, 'service' ) !== 'pushover' || ! $this->initialize_api() ) {
     51        if ( rgar( $notification, 'service' ) !== 'pushover' || !$this->initialize_api() ) {
    5352            return $email;
    5453        }
     
    102101    }
    103102   
    104     public function gform_pushover_notification_setting( $ui_settings, $notification, $form ) {
    105         $ui_settings['gform_pushover_user_token'] = '
    106             <tr>
    107                 <th>
    108                     <label for="gform_pushover_user_token">Pushover User Key<span class="gfield_required">*</span> <a href="#" onclick="return false;" onkeypress="return false;" class="gf_tooltip tooltip tooltip_notification_autoformat" title="<h6>Pushover User Key</h6>Get your Pushover User Key from <a href=\'https://pushover.net/\' target=\'_blank\'>https://pushover.net/</a>"><i class="fa fa-question-circle"></i></a></label>
    109                 </th>
    110                 <td>
    111                     <input value="' . rgar( $notification, 'gform_pushover_user_token' ) . '" name="gform_pushover_user_token" id="gform_pushover_user_token" class="fieldwidth-2">
    112                 </td>
    113             </tr>
    114             <!-- / pushover user token -->';
    115         return $ui_settings;
     103    public function gform_pushover_notification_settings_fields( $fields, $notification, $form ) {
     104        $fields[0]['fields'][] = array(
     105            'type'              => 'text',
     106            'name'              => 'gform_pushover_user_token',
     107            'label'             => 'Pushover User Key',
     108            'required'          => true,
     109            'tooltip'           => 'Get your Pushover User Key from <a href=\'https://pushover.net/\' target=\'_blank\'>https://pushover.net/</a>',
     110            'feedback_callback' => array( $this, 'gform_pushover_notification_validation' ),
     111        );
     112        return $fields;
    116113    }
    117114   
    118     public function gform_pushover_notification_validation( $is_valid, $notification, $form ) {
    119         if ( rgar( $notification, 'service' ) !== 'pushover' ) {
     115    public function gform_pushover_notification_validation( $value ) {
     116        if ( empty( $value ) ) {
     117            $is_valid = true;
     118        } elseif ( preg_match('/^\w{30}$/', $value ) ) {
    120119            $is_valid = true;
    121120        } else {
    122             if ( rgempty( 'gform_pushover_user_token', $notification ) ) {
    123                 $is_valid = false;
    124                 GFCommon::add_error_message( esc_html( 'Please enter the Pushover User Key.' ) );
    125             } elseif ( preg_match('/^\w{30}$/', rgpost( 'gform_pushover_user_token' )) ) {
    126                 $is_valid = true;
    127             } else {
    128                 $is_valid = false;
    129                 GFCommon::add_error_message( esc_html( 'Please enter a valid Pushover User Key.' ) );
    130             }
     121            $is_valid = false;
     122            GFCommon::add_error_message( esc_html( 'Please enter a valid Pushover User Key.' ) );
    131123        }
    132124        return $is_valid;
     
    134126   
    135127    public function gform_pushover_notification_setting_save( $notification, $form ) {
    136         $notification['gform_pushover_user_token'] = rgpost( 'gform_pushover_user_token' );
     128        $notification['gform_pushover_user_token'] = rgpost( '_gform_setting_gform_pushover_user_token' );
    137129        return $notification;
    138130    }
  • gf-pushover-add-on/trunk/gf-pushover-add-on.js

    r1869241 r2817109  
    11jQuery(document).ready(function ($) {
    2     if ( $("#tab_notification").length > 0 && $("#gform-notification-service-pushover").length > 0 ) {
    3         if ( $("#gform_notification_service_pushover").is(":checked") ) {
    4             $( "#gform_notification_to_type_email" ).attr('checked', 'checked');
    5             $( "#gform_notification_to_type_email" ).parent().parent().hide();
    6             $( "#gform_notification_to_email" ).val('{admin_email}');
    7             $( "#gform_notification_to_email_container" ).hide();
    8             $( "#gform_pushover_user_token" ).parent().parent().insertBefore( $( "#gform_notification_to_type_email" ).parent().parent() );
    9             $( "#gform_notification_from_name" ).parent().parent().hide();
    10             $( "#gform_notification_from" ).parent().parent().hide();
    11             $( "#gform_notification_reply_to" ).parent().parent().hide();
    12             $( "#gform_notification_bcc" ).parent().parent().hide();
     2    if ( $("#tab_notification").length > 0 && $("input[name=_gform_setting_service]").length > 0 ) {
     3        console.log( $("input[name=_gform_setting_service]").val() );
     4        if ( $("input[name=_gform_setting_service][value=pushover]").is(":checked") ) {
     5            console.log('test 3');
     6            $( "#_gform_setting_toType" ).val('email');
     7            $( "#gform_setting_toType" ).hide();
     8            $( "#_gform_setting_toEmail" ).val('{admin_email}');
     9            $( "#gform_setting_toEmail" ).hide();
     10            $( "#gform_setting_gform_pushover_user_token" ).insertBefore( $( "#gform_setting_toEmail" ) );
     11            $( "#gform_setting_fromName" ).hide();
     12            $( "#gform_setting_from" ).hide();
     13            $( "#gform_setting_replyTo" ).hide();
     14            $( "#gform_setting_bcc" ).hide();
    1315        } else {
    14             $( "#gform_pushover_user_token" ).parent().parent().hide();
     16            $( "#gform_setting_gform_pushover_user_token" ).hide();
    1517        }
    1618    }
  • gf-pushover-add-on/trunk/gf-pushover-add-on.php

    r2183110 r2817109  
    44Plugin URI: https://wp2pgpmail.com/gravity-pushover/
    55Description: Get Gravity Forms submissions as instant push notifications on your phone or tablet with Pushover.
    6 Version: 1.03
     6Version: 1.04
    77Author: wp2pgpmail
    88Author URI: https://wp2pgpmail.com
     
    1010*/
    1111
    12 define( 'GF_PUSHOVER_VERSION', '1.03' );
     12define( 'GF_PUSHOVER_VERSION', '1.04' );
    1313
    1414if ( is_plugin_active('gravityforms/gravityforms.php') ) {
  • gf-pushover-add-on/trunk/readme.txt

    r2809857 r2817109  
    66Tested up to: 6.1
    77Requires PHP: 5.6
    8 Stable tag: 1.03
     8Stable tag: 1.04
    99License: GPLv2
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7878== Changelog ==
    7979
     80= 1.04 =
     81* Adding the new filter gform_notification_settings_fields introduced with Gravity Forms v2.5
     82
    8083= 1.03 =
    8184* Testing WordPress 5.3
Note: See TracChangeset for help on using the changeset viewer.