| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Collectchat |
| 4 |
Version: 1.0 |
| 5 |
Plugin URI: www.collect.chat |
| 6 |
Description: Collect data from your visitors using our automated chatbot. Zero coding involved. Engage every single visitor on your site. |
| 7 |
Author: Team Collect Chat |
| 8 |
Author URI:https://profiles.wordpress.org/collectchat/ |
| 9 |
License: GPL v2 |
| 10 |
*/ |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
add_action( 'admin_menu', 'collectchat_admin_menu' ); |
| 16 |
function collectchat_admin_menu() { |
| 17 |
add_options_page( __('Collect Chat', 'collectchat' ), __('Collect Chat', 'collectchat' ), 'manage_options', 'collectchat-plugin', 'collectchat_options_page' ); |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
add_action( 'admin_init', 'collectchat_admin_init' ); |
| 22 |
|
| 23 |
function collectchat_admin_init() { |
| 24 |
|
| 25 |
register_setting( 'collectchat-settings-group', 'collectchat-plugin-settings' ); |
| 26 |
add_settings_section( 'collectchat-section-1', __( 'Collect Chat Script', 'collectchat' ), 'collectchat_section_1_view', 'collectchat-plugin' ); |
| 27 |
|
| 28 |
add_settings_section( 'collectchat-section-2', __( 'Exclude Pages', 'collectchat' ), 'collectchat_section_2_view', 'collectchat-plugin' ); |
| 29 |
|
| 30 |
|
| 31 |
add_settings_field( 'script', __( 'Script', 'collectchat' ), 'collectchat_script_callback', 'collectchat-plugin', 'collectchat-section-1' ); |
| 32 |
|
| 33 |
add_settings_field( 'home', __( 'Home', 'collectchat' ), 'collectchat_home_callback', 'collectchat-plugin', 'collectchat-section-2' ); |
| 34 |
// Post types specific |
| 35 |
|
| 36 |
add_settings_field( 'allpages', __( 'All Pages', 'collectchat' ), 'collectchat_allpages_callback', 'collectchat-plugin', 'collectchat-section-2' ); |
| 37 |
add_settings_field( 'allposts', __( 'All Posts', 'collectchat' ), 'collectchat_allposts_callback', 'collectchat-plugin', 'collectchat-section-2' ); |
| 38 |
|
| 39 |
// Woocommerce Support |
| 40 |
if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { |
| 41 |
add_settings_field( 'cart', __( 'Cart', 'collectchat' ), 'collectchat_cart_callback', 'collectchat-plugin', 'collectchat-section-2' ); |
| 42 |
add_settings_field( 'checkout', __( 'Checkout', 'collectchat' ), 'collectchat_checkout_callback', 'collectchat-plugin', 'collectchat-section-2' ); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
} |
| 47 |
/* |
| 48 |
* THE ACTUAL PAGE |
| 49 |
* */ |
| 50 |
function collectchat_options_page() { |
| 51 |
?> |
| 52 |
<div class="wrap"> |
| 53 |
<h2><?php _e('Collect.Chat Options', 'collectchat'); ?></h2> |
| 54 |
<form action="options.php" method="POST"> |
| 55 |
<?php settings_fields('collectchat-settings-group'); ?> |
| 56 |
<?php do_settings_sections('collectchat-plugin'); ?> |
| 57 |
<?php submit_button(); ?> |
| 58 |
</form> |
| 59 |
</div> |
| 60 |
<?php } |
| 61 |
/* |
| 62 |
* THE SECTIONS |
| 63 |
* */ |
| 64 |
function collectchat_section_1_view() { |
| 65 |
_e( 'Please copy the code snippet from collect.chat and paste it here.', 'collectchat' ); |
| 66 |
echo "<p>Don't have collect.chat account? <a href='https://collect.chat/' target='_blank'> click here to register.</a> <p>"; |
| 67 |
|
| 68 |
} |
| 69 |
function collectchat_section_2_view() { |
| 70 |
_e( 'Hide collect chat in some pages for better conversions.', 'collectchat' ); |
| 71 |
} |
| 72 |
/* |
| 73 |
* THE FIELDS |
| 74 |
* */ |
| 75 |
function collectchat_script_callback() { |
| 76 |
|
| 77 |
$settings = (array) get_option( 'collectchat-plugin-settings' ); |
| 78 |
$field = "script"; |
| 79 |
$value =$settings[$field] ; |
| 80 |
echo '<textarea rows="7" cols="50" name="collectchat-plugin-settings[script]">'.$value.'</textarea>'; |
| 81 |
} |
| 82 |
// CHECKBOX - Name: plugin_options[chkbox1] |
| 83 |
function collectchat_home_callback() { |
| 84 |
$options =get_option('collectchat-plugin-settings'); |
| 85 |
if(isset($options['home']) && $options['home']==1 ){ |
| 86 |
echo "<input type='checkbox' name='collectchat-plugin-settings[home]' value='1' checked/>"; |
| 87 |
} |
| 88 |
else{ |
| 89 |
echo "<input type='checkbox' name='collectchat-plugin-settings[home]' value='1'/>"; |
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
function collectchat_allpages_callback() { |
| 94 |
$options =get_option('collectchat-plugin-settings'); |
| 95 |
if(isset($options['allpages']) && $options['allpages']==1 ){ |
| 96 |
echo "<input type='checkbox' name='collectchat-plugin-settings[allpages]' value='1' checked/>"; |
| 97 |
} |
| 98 |
else{ |
| 99 |
echo "<input type='checkbox' name='collectchat-plugin-settings[allpages]' value='1'/>"; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
function collectchat_allposts_callback() { |
| 104 |
$options =get_option('collectchat-plugin-settings'); |
| 105 |
if(isset($options['allposts']) && $options['allposts']==1 ){ |
| 106 |
echo "<input type='checkbox' name='collectchat-plugin-settings[allposts]' value='1' checked/>"; |
| 107 |
} |
| 108 |
else{ |
| 109 |
echo "<input type='checkbox' name='collectchat-plugin-settings[allposts]' value='1'/>"; |
| 110 |
} |
| 111 |
} |
| 112 |
function collectchat_cart_callback() { |
| 113 |
$options =get_option('collectchat-plugin-settings'); |
| 114 |
if(isset($options['cart']) && $options['cart']==1 ){ |
| 115 |
echo "<input type='checkbox' name='collectchat-plugin-settings[cart]' value='1' checked/>"; |
| 116 |
} |
| 117 |
else{ |
| 118 |
echo "<input type='checkbox' name='collectchat-plugin-settings[cart]' value='1'/>"; |
| 119 |
} |
| 120 |
} |
| 121 |
function collectchat_checkout_callback() { |
| 122 |
$options =get_option('collectchat-plugin-settings'); |
| 123 |
if(isset($options['checkout']) && $options['checkout']==1 ){ |
| 124 |
echo "<input type='checkbox' name='collectchat-plugin-settings[checkout]' value='1' checked/>"; |
| 125 |
} |
| 126 |
else{ |
| 127 |
echo "<input type='checkbox' name='collectchat-plugin-settings[checkout]' value='1'/>"; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
add_action("wp_footer","collectchat_footer_script",100,1); |
| 132 |
function collectchat_footer_script($pos_id){ |
| 133 |
|
| 134 |
$settings = (array) get_option( 'collectchat-plugin-settings' ); |
| 135 |
|
| 136 |
if(isset($settings['script'])){ |
| 137 |
$script =$settings['script']; |
| 138 |
} |
| 139 |
if(isset($settings['home']) && $settings['home']==1){ |
| 140 |
if((is_home() || is_front_page() )){ |
| 141 |
return; |
| 142 |
} |
| 143 |
} |
| 144 |
if(isset($settings['allpages'])&& $settings['allpages']==1){ |
| 145 |
if (is_page()) { |
| 146 |
return; |
| 147 |
} |
| 148 |
} |
| 149 |
if(isset($settings['allposts']) && $settings['allposts']==1){ |
| 150 |
if ('post' == get_post_type()) { |
| 151 |
return ; |
| 152 |
} |
| 153 |
|
| 154 |
} |
| 155 |
if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) { |
| 156 |
if(isset($settings['cart'])){ |
| 157 |
if(is_cart() && $settings['cart']==1) { |
| 158 |
return; |
| 159 |
} |
| 160 |
} |
| 161 |
if(isset($settings['checkout'])){ |
| 162 |
if(is_checkout() && $settings['checkout']==1) { |
| 163 |
return; |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
echo $script; |
| 169 |
|
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
?> |