';
}
else
{
return 'Please enter a valid Collect.chat bot id';
}
}
function collectchat_activation_redirect($plugin)
{
if( $plugin == plugin_basename( __FILE__ ) ) {
exit(wp_redirect(admin_url('admin.php?page=collectchat')));
}
}
function collectchat_settings_link($links)
{
$settings_link = '' . __('Settings', 'collectchat') . '';
$support_link = '' . __('Support', 'collectchat') . '';
array_push($links, $settings_link);
array_push($links, $support_link);
return $links;
}
function collectchat_settings_message()
{
$settings = get_option('collectchat-plugin-settings');
$postmeta_query_args = array(
'post_type' => 'post',
'meta_key' => '_inpost_head_script',
);
$postmeta_query = new WP_Query( $postmeta_query_args );
if (!(isset($settings) && !empty($settings['script'])) && !$postmeta_query->have_posts() && !(isset($_GET['page']) && $_GET['page'] == 'collectchat'))
{
?>
= 7){
$cc_new_URI = $_SERVER['REQUEST_URI'];
$cc_new_URI = add_query_arg('collectchat-ignore-notice', '0', $cc_new_URI);
$cc_new_URI = esc_url($cc_new_URI);
echo '';
echo '

';
printf(__('
Awesome! You have been using Collect.chat chatbot plugin for more than 1 week 😎
Would you mind taking a few seconds to give it a 5-star rating on WordPress?
Thank you in advance :)
'));
printf(__('
Ok, you deserved it
I already did
No, not good enough', 'advanced-database-cleaner'), $cc_new_URI,
'https://wordpress.org/support/plugin/collectchat/reviews/?filter=5');
echo "
";
}
}
}
}
function collectchat_ignore_notice(){
if(isset($_GET['collectchat-ignore-notice']) && $_GET['collectchat-ignore-notice'] == "0"){
$settings = get_option('collectchat-plugin-settings');
$settings['ignore_rating'] = "yes";
update_option('collectchat-plugin-settings', $settings, "no");
}
}
function collectchat_html_sanitize($input) {
$allowed_html = array(
'script' => array(),
);
if (current_user_can('unfiltered_html')) {
$input['script'] = wp_kses($input['script'], $allowed_html); // Script sanitization for users with the unfiltered_html capability
} else {
$input['script'] = wp_kses_post($input['script']); // Sanitize all content for other users
}
return $input;
}
function admin_init()
{
// register settings for sitewide script
register_setting('collectchat-settings-group', 'collectchat-plugin-settings', array( 'sanitize_callback' => array( $this, 'collectchat_html_sanitize') ));
add_settings_field('script', 'Script', 'trim', 'collectchat');
add_settings_field('showOn', 'Show On', 'trim', 'collectchat');
add_settings_field('installedOn', 'Show On', 'trim', 'collectchat');
// default value for settings
$initialSettings = get_option('collectchat-plugin-settings');
if ($initialSettings === false)
{
$initialSettings['showOn'] = 'all';
$initialSettings['installedOn'] = date("Y/m/d");
update_option('collectchat-plugin-settings', $initialSettings);
}
if($initialSettings === true && !$initialSettings['showOn']) {
$initialSettings['showOn'] = 'all';
update_option('collectchat-plugin-settings', $initialSettings);
}
if($initialSettings === true && !$initialSettings['installedOn']) {
$initialSettings['installedOn'] = date("Y/m/d");
update_option('collectchat-plugin-settings', $initialSettings);
}
// add meta box to all post types
add_meta_box('cc_all_post_meta', esc_html__('Collect.chat Snippet:', 'collectchat-settings') , 'collectchat_meta_setup', array(
'post',
'page'
) , 'normal', 'default');
add_action('save_post', 'collectchat_post_meta_save');
}
// adds menu item to wordpress admin dashboard
function admin_menu()
{
add_menu_page(__('Collect.chat', 'collectchat-settings') , __('Collect.chat', 'collectchat-settings') , 'manage_options', 'collectchat', array(&$this,
'collectchat_options_panel'
) , 'data:image/svg+xml;base64,PHN2ZyBpZD0ic3ZnIiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSI0MDAiIGhlaWdodD0iNDAwIiB2aWV3Qm94PSIwLCAwLCA0MDAsNDAwIj48ZyBpZD0ic3ZnZyI+PHBhdGggaWQ9InBhdGgwIiBkPSJNMTkxLjM1OCA2NC45MjYgQyAxMTEuNjcyIDcwLjg0OSw1My41MTkgMTQzLjgwNCw2NS4zNTIgMjIzLjAwNiBDIDY3LjY4MiAyMzguNTk5LDc0LjI5MyAyNTcuMzc3LDgyLjA5OCAyNzAuNTcyIEwgODIuOTMzIDI3MS45ODMgNzkuMTQ5IDI4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TYsMzM4LjU3NSAxOTkuMjEwLDMzOC41NzYgMjAxLjY5NCAiIHN0cm9rZT0ibm9uZSIgZmlsbD0iIzljYTRhNCIgZmlsbC1ydWxlPSJldmVub2RkIj48L3BhdGg+PHBhdGggaWQ9InBhdGgyIiBkPSIiIHN0cm9rZT0ibm9uZSIgZmlsbD0iI2E0YTRiMCIgZmlsbC1ydWxlPSJldmVub2RkIj48L3BhdGg+PHBhdGggaWQ9InBhdGgzIiBkPSIiIHN0cm9rZT0ibm9uZSIgZmlsbD0iI2E0YTRiMCIgZmlsbC1ydWxlPSJldmVub2RkIj48L3BhdGg+PHBhdGggaWQ9InBhdGg0IiBkPSIiIHN0cm9rZT0ibm9uZSIgZmlsbD0iI2E0YTRiMCIgZmlsbC1ydWxlPSJldmVub2RkIj48L3BhdGg+PC9nPjwvc3ZnPg==');
}
function wp_head()
{
$settings = get_option('collectchat-plugin-settings');
$allowed_html = array(
'script' => array(),
);
if (is_array($settings) && array_key_exists('script', $settings))
{
$script = $settings['script'];
$showOn = $settings['showOn'];
// main bot
if ($script != '')
{
if (($showOn === 'all') || ($showOn === 'home' && (is_home() || is_front_page())) || ($showOn === 'nothome' && !is_home() && !is_front_page()) || !$showOn === 'none')
{
echo wp_kses($script, $allowed_html), wp_kses('', $allowed_html), "\n";
}
}
}
// post and page bots
$cc_post_meta = get_post_meta(get_the_ID() , '_inpost_head_script', true);
if ($cc_post_meta != '' && !is_home() && !is_front_page())
{
echo wp_kses($cc_post_meta['synth_header_script'], $allowed_html), wp_kses('', $allowed_html), "\n";
}
}
function collectchat_options_panel()
{
// Load options page
require_once (CC_PLUGIN_DIR . '/options.php');
}
}
function collectchat_meta_setup()
{
global $post;
// using an underscore, prevents the meta variable
// from showing up in the custom fields section
$meta = get_post_meta($post->ID, '_inpost_head_script', true);
// instead of writing HTML here, lets do an include
include_once (CC_PLUGIN_DIR . '/meta.php');
// create a custom nonce for submit verification later
echo '';
}
function collectchat_post_meta_save($post_id)
{
// make sure data came from our meta box
if (!isset($_POST['cc_post_meta_noncename']) || !wp_verify_nonce($_POST['cc_post_meta_noncename'], __FILE__)) return $post_id;
// check user permissions
if ($_POST['post_type'] == 'page')
{
if (!current_user_can('edit_page', $post_id)) return $post_id;
}
else
{
if (!current_user_can('edit_post', $post_id)) return $post_id;
}
// only users with unfiltered_html capability can save scripts
if (!current_user_can('unfiltered_html')) return $post_id;
$current_data = get_post_meta($post_id, '_inpost_head_script', true);
$new_data = $_POST['_inpost_head_script'];
collectchat_post_meta_clean($new_data);
if ($current_data)
{
if (is_null($new_data)) delete_post_meta($post_id, '_inpost_head_script');
else update_post_meta($post_id, '_inpost_head_script', $new_data);
}
elseif (!is_null($new_data))
{
add_post_meta($post_id, '_inpost_head_script', $new_data, true);
}
return $post_id;
}
function collectchat_post_meta_clean(&$arr)
{
$allowed_html = array(
'script' => array(),
);
if (is_array($arr))
{
foreach ($arr as $i => $v)
{
if (is_array($arr[$i]))
{
collectchat_post_meta_clean($arr[$i]);
if (!count($arr[$i]))
{
unset($arr[$i]);
}
}
else
{
if (trim($arr[$i]) == '')
{
unset($arr[$i]);
} else {
if (current_user_can('unfiltered_html')) {
$arr[$i] = wp_kses($v, $allowed_html);
} else {
$arr[$i] = wp_kses_post($v);
}
}
}
}
if (!count($arr))
{
$arr = NULL;
}
}
}
$scripts = new ScriptLoader();
}
?>