-
Notifications
You must be signed in to change notification settings - Fork 1
/
notifylk-ninjaforms.php
79 lines (63 loc) · 2.1 KB
/
notifylk-ninjaforms.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
<?php
/**
* Plugin Name: NotifyLK SMS for Ninja Forms
* Description: Send SMS for Ninja Form submissions with Notify.LK SMS Gateway.
* Version: 0.1
* Author: Notify.lk
* Author URI: http://notify.lk/
* License: GPLv2 or laterx
* Text Domain: notifylk
*/
include 'includes/core-import.php';
function notifyNinjaHead() {
?>
<script>var ninja_notify_plugin_url = "<?php echo plugins_url("", __FILE__); ?>";</script>
<?php
}
add_action('wp_head', 'notifyNinjaHead');
/*
*
* Format phone number to support API format
*
*/
function notifyReformatPhoneNumbers($value) {
$number = preg_replace("/[^0-9]/", "", $value);
if (strlen($number) == 9) {
$number = "94" . $number;
} elseif (strlen($number) == 10 && substr($number, 0, 1) == '0') {
$number = "94" . ltrim($number, "0");
} elseif (strlen($number) == 12 && substr($number, 0, 3) == '940') {
$number = "94" . ltrim($number, "940");
}
return $number;
}
/*
*
* Ninja Forms Custom Field
*
*/
function notifyNinjaTemplatePaths($paths) {
$paths[] = plugin_dir_path(__FILE__) . "includes/templates/";
return $paths;
}
add_filter('ninja_forms_field_template_file_paths', 'notifyNinjaTemplatePaths');
add_filter('ninja_forms_register_fields', function($fields) {
$fields['notify_ninja_phone'] = new NotifyNinjaPhoneField;
return $fields;
});
add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
function theme_enqueue_styles() {
wp_enqueue_style('intlTelInput', plugins_url('includes/css/intlTelInput.css', __FILE__));
wp_enqueue_style('notify-ninja', plugins_url('includes/css/main.css', __FILE__));
wp_enqueue_script('intlTelInput', plugins_url('includes/js/intlTelInput.min.js', __FILE__), array('jquery'), FALSE, TRUE);
wp_enqueue_script('notify-ninja', plugins_url('includes/js/main.js', __FILE__), array('jquery', 'intlTelInput', 'nf-front-end'), FALSE, TRUE);
}
/*
*
* Action Registration
*
*/
add_filter('ninja_forms_register_actions', function($actions) {
$actions['notifylk'] = new NF_Actions_Notifylk();
return $actions;
});