-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpforms-epfl-payonline.php
139 lines (125 loc) · 5.58 KB
/
wpforms-epfl-payonline.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Plugin Name: WPForms EPFL Payonline (saferpay)
* Plugin URI: https://github.com/epfl-si/wpforms-epfl-payonline
* Description: EPFL Payonline integration with WPForms.
* Author: EPFL ISAS-FSD
* Author URI: https://go.epfl.ch/idev-fsd
* Contributor: Nicolas Borboën <[email protected]>
* Version: 2.1.3
* Text Domain: wpforms-epfl-payonline
* Domain Path: languages
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* WPForms EPFL Payonline is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* WPForms EPFL Payonline is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WPForms EPFL Payonline.
* If not, see <http://www.gnu.org/licenses/>.
*
* @package WPFormsEPFLPayonline
* @license GPL-2.0+
* @copyright Copyright (c) 2019, EPFL
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Plugin version.
define( 'WPFORMS_EPFL_PAYONLINE_VERSION', '2.1.3' );
// Plugin name.
define( 'WPFORMS_EPFL_PAYONLINE_NAME', 'WPForms EPFL Payonline (saferpay)' );
// Latest WP version tested with this plugin.
define( 'WP_LATEST_VERSION_WPFORMS_EPFL_PAYONLINE', '6.3' );
// Minimal WP version required for this plugin.
define( 'WP_MIN_VERSION_WPFORMS_EPFL_PAYONLINE', '6.0.0' );
// Plugin Folder Path.
if ( ! defined( 'WPFORMS_EPFL_PAYONLINE_PLUGIN_DIR' ) ) {
define( 'WPFORMS_EPFL_PAYONLINE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'WPFORMS_EPFL_PAYONLINE_PLUGIN_URL' ) ) {
define( 'WPFORMS_EPFL_PAYONLINE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
/**
* Load the payment class.
*/
function wpforms_epfl_payonline() {
// WPForms Pro is required.
if ( ! class_exists( 'WPForms_Pro' ) ) {
return;
}
load_plugin_textdomain( 'wpforms-epfl-payonline', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
require_once plugin_dir_path( __FILE__ ) . 'class-wpforms-epfl-payonline.php';
require_once plugin_dir_path( __FILE__ ) . 'class-wpforms-saferpay.php';
require_once plugin_dir_path( __FILE__ ) . 'templates/class-epfl-conference-form-template.php';
require_once plugin_dir_path( __FILE__ ) . 'templates/class-epfl-donation-form-template.php';
}
add_action( 'wpforms_loaded', 'wpforms_epfl_payonline' );
/* Load JS */
function load_epflpayonline_js() {
wp_enqueue_script(
'wpforms-epfl-payonline',
WPFORMS_EPFL_PAYONLINE_PLUGIN_URL . 'assets/js/wpforms-epfl-payonline.js',
array( 'wpforms-builder' ),
WPFORMS_EPFL_PAYONLINE_VERSION,
true
);
}
add_action( 'admin_enqueue_scripts', 'load_epflpayonline_js' );
// WPForms requires WP_Filesystem() to be of ->method === "direct".
// For some reason (likely pertaining to our symlink scheme),
// WordPress' autodetection fails. This is equivalent to setting the
// `FS_METHOD` constant in `wp-confing.php`.
add_filter(
'filesystem_method',
function () {
return 'direct';
},
10,
3
);
/**
* Limit number range allowed for a Numbers field
* Apply the class "wpf-num-limit" to the field to enable.
*
* @link https://wpforms.com/developers/how-to-limit-range-allowed-in-numbers-field/
*/
function max_donation_limit() {
?>
<script type="text/javascript">
jQuery(function(){
// Limit the maximum amount (maximum (4999) amount for the number field
jQuery( '.limit-donation-4999-en input' ).attr({ 'min': 0, 'max': 4999 } );
// Message to be displayed if the min and or max is not met
jQuery('.limit-donation-4999-en input').on('change', function() {
jQuery.extend(jQuery.validator.messages, {
max: jQuery.validator.format("For any gift starting CHF 5,000, we kindly ask you to contact the Philanthropy team (<a href='mailto:[email protected]'>[email protected]</a>) who will be happy to assist you in formalizing your donation."),
min: jQuery.validator.format("For any gift starting CHF 5,000, we kindly ask you to contact the Philanthropy team (<a href='mailto:[email protected]'>[email protected]</a>) who will be happy to assist you in formalizing your donation.")
});
});
});
jQuery(function(){
// Limit the maximum amount (maximum (4999) amount for the number field
jQuery( '.limit-donation-4999-fr input' ).attr({ 'min': 0, 'max': 4999 } );
// Message to be displayed if the min and or max is not met
jQuery('.limit-donation-4999-fr input').on('change', function() {
jQuery.extend(jQuery.validator.messages, {
max: jQuery.validator.format("Pour toute donation dès CHF 5'000.- nous vous invitons à contacter la Philanthropie (<a href='mailto:[email protected]'>[email protected]</a>) qui vous accompagnera avec plaisir pour formaliser votre contribution."),
min: jQuery.validator.format("Pour toute donation dès CHF 5'000.- nous vous invitons à contacter la Philanthropie (<a href='mailto:[email protected]'>[email protected]</a>) qui vous accompagnera avec plaisir pour formaliser votre contribution.")
});
});
});
</script>
<?php
}
add_action( 'wpforms_wp_footer_end', 'max_donation_limit', 30 );