-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtghp-mb-contact.php
83 lines (66 loc) · 2.29 KB
/
tghp-mb-contact.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
<?php
/*
Plugin Name: TGHP Metabox Contact
Description: Utilise MB Frontend Submission for contact forms
Author: TGHP
Version: 1.0.0
Network: False
*/
define('TGHP_CONTACT_VERSION', '1.0.0');
define('TGHP_CONTACT_META_PREFIX', '_tghpcontact_');
define('TGHP_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('TGHP_PLUGIN_URL', plugin_dir_url(__FILE__));
include_once 'vendor/google/recaptcha/autoload.php';
include_once 'inc/graphql.php';
include_once 'inc/autoloader.php';
include_once 'inc/cpt.php';
include_once 'inc/cmb.php';
include_once 'inc/settings.php';
include_once 'inc/validation.php';
include_once 'inc/posts.php';
include_once 'inc/redirect.php';
include_once 'inc/email.php';
include_once 'inc/frontend.php';
include_once 'inc/admin.php';
function tghpcontact_load_types()
{
require 'inc/meta-box/fields/recaptcha.php';
require 'inc/meta-box/fields/dynamic-std-input.php';
}
add_action('init', 'tghpcontact_load_types');
function tghpcontact_form($id = 'contact_submission', $args = [])
{
$args['id'] = $id;
$shortcodeArgs = '';
foreach ($args as $key => $val) {
$shortcodeArgs .= "{$key}=\"{$val}\" ";
}
$metabox = tghpcontact_get_contact_metabox($id);
foreach (['ajax', 'confirmation'] as $copyFromOptionsToMetaboxKey) {
if ($metabox->$copyFromOptionsToMetaboxKey) {
$val = $metabox->$copyFromOptionsToMetaboxKey;
if ($val === true || $val === false) {
$val = $val ? 'true' : 'false';
}
$val = esc_attr($val);
$shortcodeArgs .= "{$copyFromOptionsToMetaboxKey}=\"{$val}\" ";
}
}
ob_start();
?>
<div class="tghpform tghpform--<?= $id ?>">
<?= do_shortcode("[mb_frontend_form {$shortcodeArgs}]"); ?>
</div>
<?php
$output = ob_get_clean();
if ($metabox->button_class) {
$output = preg_replace('/(<button.*?rwmb-button)/', "$1 {$metabox->button_class}", $output);
}
if ($metabox->submit_class) {
$output = preg_replace('/(<button.*rwmb-button[^"]*)(".*rwmb_submit)/', "$1 {$metabox->submit_class}$2", $output);
}
if ($metabox->submit_text_sr_only) {
$output = preg_replace('/("rwmb_submit"[^>]*>)([^<]*?)<\/button>/', "$1<span class=\"sr-only\">$2</span></button>", $output);
}
echo $output;
}