This repository was archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwp_funcaptcha_cf7.php
More file actions
executable file
·90 lines (78 loc) · 2.16 KB
/
wp_funcaptcha_cf7.php
File metadata and controls
executable file
·90 lines (78 loc) · 2.16 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
<?php
/**
* setup actions for contact form 7
**
* @return null
*/
function funcaptcha_register_cf7_actions() {
// Register the funcaptcha CF7 shortcode
wpcf7_add_shortcode('funcaptcha', 'funcaptchacf7_tag_handler', true);
// Register the funcaptcha CF7 validation function
add_filter('wpcf7_validate_funcaptcha', 'funcaptchacf7_validate', 10, 2);
// Register the funcaptcha CF7 tag pane generator
add_action('admin_init', 'funcaptchacf7_tag_generator');
}
/**
* display [funcaptcha] tag
*
* @return string outputs funcaptcha for the form
*/
function funcaptchacf7_tag_handler($tag) {
$tag = new WPCF7_Shortcode($tag);
if( empty($tag->name))
return '';
$html = funcaptcha_get_fc_html();
$html .= '<span class="wpcf7-form-control-wrap ' . $tag->name . '"> </span>';
return apply_filters('wpcf7_funcaptcha_html_output', $html);
}
/**
* validate funcaptcha
*
* @return array
*/
function funcaptchacf7_validate($result, $tag) {
$tag = new WPCF7_Shortcode( $tag );
$name = $tag->name;
$funcaptcha = funcaptcha_API();
$options = funcaptcha_get_settings();
if ( $funcaptcha->checkResult($options['private_key']) ) {
return $result;
} else {
$result['valid'] = false;
$result['reason'] = array($name => $options['error_message']);
return $result;
}
}
/**
* setup [funcaptcha] tag
*
* @return null
*/
function funcaptchacf7_tag_generator() {
wpcf7_add_tag_generator('funcaptcha', 'FunCaptcha', 'funcaptchacf7-tag-pane', 'funcaptchacf7_tag_pane');
}
/**
* display funcaptcha in contact form 7 editor
*
* @return null
*/
function funcaptchacf7_tag_pane($contact_form) {
?>
<div id="funcaptchacf7-tag-pane" class="hidden">
<form action="">
<table>
<tr>
<td><?php _e('Name', 'funcaptcha'); ?><br /><input type="text" name="name" class="tg-name oneline" /></td>
<td></td>
</tr>
</table>
<div class="tg-tag">
<?php _e('Copy this code and paste it into the form left.', 'funcaptcha' ); ?>
<br />
<input type="text" name="funcaptcha" class="tag" readonly="readonly" onfocus="this.select()" />
</div>
</form>
</div>
<?php
}
?>