-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjotform-wp-embed.php
executable file
·96 lines (80 loc) · 3.32 KB
/
jotform-wp-embed.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
<?php
/**
* Plugin Name: Jotform Online Forms
* Description: Securely embed online forms in your WordPress website.
* Requires at least: 5.3
* Requires PHP: 7.4
* Version: 1.3.7
* Author: Jotform
* Author URI: https://www.jotform.com
* License: GNU General Public License v3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
class JotFormWPEmbed {
public function __construct() {
/* Hook action to init */
add_action('init', array($this ,'addTinyMCEButton') );
add_shortcode('jotform', array($this, 'apiEmbedHandler'));
add_action('admin_notices', array($this, 'showNewPluginNotification'));
add_action('wp_ajax_jotform-ai-chatbot_dismiss_notice', array($this, 'dismissNewPluginNotification'));
}
public function showNewPluginNotification() {
if (!current_user_can('manage_options')) {
return;
}
if (get_option('jotform-ai-chatbot_admin_notice_dismissed')) {
return;
}
$plugin_slug = 'jotform-ai-chatbot';
$plugin_url = esc_url("plugin-install.php?tab=plugin-information&plugin=$plugin_slug&TB_iframe=true&width=600&height=550");
?>
<div class="notice notice-info is-dismissible" id="jotform-ai-chatbot-admin-notice">
<p>🚀 <strong>Meet Jotform AI Chatbot!</strong> Automate support, boost engagement & generate leads. No coding needed. <a href="<?php echo $plugin_url; ?>" class="thickbox">Try it now!</a> 🤖✨</p>
</div>
<?php
add_thickbox();
?>
<script>
jQuery(document).on('click', '#jotform-ai-chatbot-admin-notice .notice-dismiss', function () {
jQuery.post(ajaxurl, {
action: 'jotform-ai-chatbot_dismiss_notice'
});
});
</script>
<?php
}
public function dismissNewPluginNotification() {
update_option('jotform-ai-chatbot_admin_notice_dismissed', true);
wp_die();
}
public function addTinyMCEButton() {
if ( ( current_user_can('edit_posts') || current_user_can('edit_pages') ) && get_user_option('rich_editing') ) {
add_filter("mce_external_plugins", array($this ,'addTinyMCEPlugin'));
add_filter('mce_buttons', array($this ,'registerFormPicker'));
}
}
public function registerFormPicker($buttons) {
wp_enqueue_script( 'jotform-wp-embed-fp-wrapper', plugins_url( 'jotform-wp-embed-fp-wrapper.js', __FILE__ ));
array_push($buttons, "|", "JotFormWPEmbed");
return $buttons;
}
/* Load the TinyMCE plugin */
public function addTinyMCEPlugin($plugin_array) {
$plugin_array['JotFormWPEmbed'] = plugins_url('jotform-wp-embed.js', __FILE__ );
return $plugin_array;
}
public function replaceTags($matches)
{
$url = '//www.jotform.com/jsform/'.$matches["formID"].'?redirect=1';
return '<script type="text/javascript" src="'.esc_url($url).'"></script>';
}
/*
* Reads form id returned from shortcode api and inserts form
*/
public function apiEmbedHandler($args) {
return isset($args['id']) && ctype_digit($args['id'])
? $this->replaceTags(array('formID' => $args['id']))
: '';
}
}
$jotformwp = new JotFormWPEmbed();