-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
222 lines (207 loc) · 6.17 KB
/
functions.php
File metadata and controls
222 lines (207 loc) · 6.17 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
/**
* Plugin Name: Forms by Influactive
* Description: A plugin to create custom forms and display them anywhere on your website.
* Version: 1.5.1
* Author: Influactive
* Author URI: https://influactive.com
* Text Domain: influactive-forms
* Domain Path: /languages
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* @throws RuntimeException If the WordPress environment is not loaded.
* @package Forms by Influactive
**/
if ( ! defined( 'ABSPATH' ) ) {
throw new RuntimeException( 'WordPress environment not loaded. Exiting...' );
}
require_once plugin_dir_path( __FILE__ ) . 'back-end/post-type/definitions.php';
require_once plugin_dir_path( __FILE__ ) . 'back-end/post-type/edit.php';
require_once plugin_dir_path( __FILE__ ) . 'back-end/post-type/listing.php';
require_once plugin_dir_path( __FILE__ ) . 'back-end/settings/captchas.php';
require_once plugin_dir_path( __FILE__ ) . 'front-end/shortcode.php';
/**
* Adds a settings link to the plugin page.
*
* @param array $links An array of existing links on the plugin page.
*
* @return array An updated array of links including the new settings link.
*/
function influactive_forms_add_settings_link( array $links ): array {
$link = 'edit.php?post_type=influactive-forms&page=influactive-form-settings';
$link_text = __( 'Captchas', 'influactive-forms' );
$settings_link = '<a href="' . $link . '">' . $link_text . '</a>';
$links[] = $settings_link;
return $links;
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'influactive_forms_add_settings_link' );
/**
* Enqueues scripts and styles for editing an Influactive form.
*
* @param string $hook The current admin page hook.
*
* @return void
*/
function influactive_form_edit( string $hook ): void {
if ( 'post.php' !== $hook && 'post-new.php' !== $hook ) {
return;
}
wp_enqueue_script(
'influactive-form',
plugin_dir_url( __FILE__ ) . 'dist/backEndForm.bundled.js',
array(
'wp-tinymce',
'influactive-tabs',
'influactive-form-layout',
),
'1.5.1',
true
);
wp_localize_script(
'influactive-form',
'influactiveFormsTranslations',
array(
'addOptionText' => __( 'Add option', 'influactive-forms' ),
'removeOptionText' => __( 'Remove option', 'influactive-forms' ),
'removeFieldText' => __( 'Remove the field', 'influactive-forms' ),
'typeLabelText' => __( 'Type', 'influactive-forms' ),
'labelLabelText' => __( 'Label', 'influactive-forms' ),
'nameLabelText' => __( 'Name', 'influactive-forms' ),
'optionLabelLabelText' => __( 'Option Label', 'influactive-forms' ),
'optionValueLabelText' => __( 'Option Value', 'influactive-forms' ),
'gdprTextLabelText' => __( 'Text', 'influactive-forms' ),
'fieldAddedText' => __( 'Field added!', 'influactive-forms' ),
'optionAddedText' => __( 'Option added!', 'influactive-forms' ),
'optionRemovedText' => __( 'Option removed!', 'influactive-forms' ),
'Text' => __( 'Text', 'influactive-forms' ),
'Textarea' => __( 'Textarea', 'influactive-forms' ),
'Select' => __( 'Select', 'influactive-forms' ),
'Email' => __( 'Email', 'influactive-forms' ),
'GDPR' => __( 'GDPR', 'influactive-forms' ),
'Number' => __( 'Number', 'influactive-forms' ),
'Freetext' => __( 'Free text', 'influactive-forms' ),
)
);
// Global CSS.
wp_enqueue_style(
'influactive-form-style',
plugin_dir_url( __FILE__ ) . 'dist/style.bundled.css',
array(),
'1.5.1'
);
// Form CSS and JS.
wp_enqueue_script(
'influactive-form',
plugin_dir_url( __FILE__ )
. 'dist/backEndForm.bundled.js',
array(),
'1.5.1',
true
);
wp_enqueue_style(
'influactive-form',
plugin_dir_url( __FILE__ )
. 'dist/backForm.bundled.css',
array(),
'1.5.1'
);
// Tabs CSS and JS.
wp_enqueue_script(
'influactive-tabs',
plugin_dir_url( __FILE__ )
. 'dist/backEndTab.bundled.js',
array(),
'1.5.1',
true
);
wp_enqueue_style(
'influactive-tabs',
plugin_dir_url( __FILE__ )
. 'dist/tab.bundled.css',
array(),
'1.5.1'
);
// Layout CSS and JS.
wp_enqueue_style(
'influactive-form-layout',
plugin_dir_url( __FILE__ )
. 'dist/layout.bundled.css',
array(),
'1.5.1'
);
wp_enqueue_script(
'influactive-form-layout',
plugin_dir_url( __FILE__ ) . 'dist/backEndLayout.bundled.js',
array(),
'1.5.1',
true
);
wp_localize_script(
'influactive-form-layout',
'influactiveFormsTranslations',
array(
'delete_layout' => __( 'Delete layout', 'influactive-forms' ),
)
);
}
add_action( 'admin_enqueue_scripts', 'influactive_form_edit' );
/**
* Enqueues the necessary scripts and styles for the Influactive form shortcode.
*
* @return void
*/
function influactive_form_shortcode_enqueue(): void {
if ( is_admin() ) {
return;
}
$options_captcha = get_option( 'influactive-forms-captcha-fields' ) ?? array();
$public_site_key = $options_captcha['google-captcha']['public-site-key'] ?? null;
$secret_site_key = $options_captcha['google-captcha']['secret-site-key'] ?? null;
if ( ! empty( $public_site_key ) && ! empty( $secret_site_key ) ) {
wp_enqueue_script(
'google-captcha',
"https://www.google.com/recaptcha/api.js?render=$public_site_key",
array(),
'1.5.1',
true
);
$script_handle = array( 'google-captcha' );
} else {
$script_handle = array();
}
// Form CSS and JS.
wp_enqueue_script(
'influactive-form',
plugin_dir_url( __FILE__ ) .
'dist/frontEnd.bundled.js',
$script_handle,
'1.5.1',
true
);
wp_enqueue_style(
'influactive-form',
plugin_dir_url( __FILE__ ) . 'dist/frontForm.bundled.css',
array(),
'1.5.1'
);
wp_localize_script(
'influactive-form',
'ajaxObject',
array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) )
);
}
add_action( 'wp_enqueue_scripts', 'influactive_form_shortcode_enqueue' );
/**
* Loads the Forms by Influactive text domain for localization.
*
* @return void
*/
function influactive_load_forms_textdomain(): void {
load_plugin_textdomain(
'influactive-forms',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages'
);
}
add_action( 'plugins_loaded', 'influactive_load_forms_textdomain' );