| Server IP : 69.30.224.78 / Your IP : 216.73.217.95 Web Server : Microsoft-IIS/10.0 System : Windows NT SERVER 10.0 build 14393 (Windows Server 2016) AMD64 User : IWPD_92(newtechtest) ( 0) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Inetpub/vhosts/newtechtest.in/heartcare.newtechtest.in/wp-content/plugins/chatlio/ |
Upload File : |
<?php
/**
* Plugin Name: Chatlio Live Chat for Slack
* Plugin URI: https://chatlio.com/app/#/settings/install
* Description: Chatlio
* Version: 1.3.0
* Author: Chatlio
* Author URI: https://chatlio.com/?ref=wordpress
* Requires at least: 5.9
* Requires PHP: 8.3
**/
/**
* Security Check
*
* @since 1.0
**/
defined("ABSPATH") || die("Direct access to this file is forbidden.");
/**
* Chatlio class
*
* @since 1.0
**/
class Chatlio
{
/**
* Starter defines and vars for use later
*
* @since 1.0
**/
// Holds option data.
private $option_name = "pwl_chatlio_options";
private $options = [];
private $option_defaults;
// DB version, for schema upgrades.
private $db_version = 1;
// Instance
public static $instance;
/**
* Constuct
* Fires when class is constructed, adds init hook
*
* @since 1.0
**/
public function __construct()
{
// Allow this instance to be called from outside the class
self::$instance = $this;
// Add Chatlio script to head
add_action("wp_head", [$this, "wp_head"]);
// Add Chatlio widget element to footer
add_action("wp_footer", [$this, "wp_footer"]);
// Add admin init hook
add_action("admin_init", [$this, "admin_init"]);
// Add admin panel
add_action("admin_menu", [$this, "admin_menu"]);
// Setting plugin defaults here
$this->option_defaults = [
"widget_id" => "",
"db_version" => $this->db_version,
];
}
/**
* Frontend wp_head Callback - loads Chatlio script
*
* @since 1.0
* @since 1.2.0 Updated to new embed code
**/
public function wp_head()
{
// Get options
$this->options = wp_parse_args(
get_option("chatlio_options"),
$this->option_defaults,
);
if (!empty($this->options["widget_id"])) {
echo '<script src="https://js.chatlio.com/widget.js" async></script>';
}
}
/**
* Frontend wp_footer Callback - outputs Chatlio widget element
*
* @since 1.2.0
**/
public function wp_footer()
{
// Get options
$this->options = wp_parse_args(
get_option("chatlio_options"),
$this->option_defaults,
);
if (!empty($this->options["widget_id"])) {
$widget_id = esc_attr($this->options["widget_id"]);
echo '<chatlio-widget widgetid="' .
$widget_id .
'"></chatlio-widget>';
}
}
/**
* Admin init Callback
*
* @since 1.0
**/
public function admin_init()
{
// Fetch and set up options.
$this->options = wp_parse_args(
get_option("chatlio_options"),
$this->option_defaults,
);
// Register Settings
$this->register_settings();
}
/**
* Admin Menu Callback
*
* @since 1.0
**/
public function admin_menu()
{
// Add settings page on Tools
add_management_page(
__("Chatlio", "chatlio"),
__("Chatlio", "chatlio"),
"manage_options",
"chatlio-settings",
[$this, "chatlio_settings"],
);
}
/**
* Register Admin Settings
*
* @since 1.0
**/
public function register_settings()
{
register_setting("chatlio", "chatlio_options", [
$this,
"chatlio_sanitize",
]);
// The main section
add_settings_section(
"chatlio_settings_section",
"Chatlio Settings",
[$this, "chatlio_settings_callback"],
"chatlio-settings",
);
// The Fields
add_settings_field(
"widget_id",
"Widget ID",
[$this, "widget_id_callback"],
"chatlio-settings",
"chatlio_settings_section",
);
}
/**
* Settings Callback
*
* @since 1.0
**/
public function chatlio_settings_callback()
{
echo "<p>" .
sprintf(
__(
'To customize the behavior or appearance of your Chatlio widget, visit the <a href="%s" target="_blank">Chatlio Dashboard</a>. For help with this plugin, see our <a href="%s" target="_blank">WordPress documentation</a>.',
"chatlio",
),
"https://chatlio.com/app/#/",
"https://chatlio.com/docs/wordpress/",
) .
"</p>";
}
/**
* Widget ID Statuses Callback
*
* @since 1.0
**/
public function widget_id_callback()
{
?>
<input type="text" id="chatlio_options[widget_id]" name="chatlio_options[widget_id]" value="<?php echo esc_attr(
$this->options["widget_id"],
); ?>" >
<label for="chatlio_options[widget_id]"><?php _e(
"Add your Widget ID to enable Chatlio",
"chatlio",
); ?></label>
<?php
}
/**
* Call settings page
*
* @since 1.0
**/
public function chatlio_settings()
{
?>
<div class="wrap">
<h2><?php _e("Chatlio", "chatlio"); ?></h2>
<form action="options.php" method="POST">
<?php
settings_fields("chatlio");
do_settings_sections("chatlio-settings");
submit_button();?>
</form>
</div>
<?php
}
/**
* Options sanitization and validation
*
* @param $input the input to be sanitized
* @since 1.0
**/
public function chatlio_sanitize($input)
{
$options = $this->options;
$input["db_version"] = $this->db_version;
foreach ($options as $key => $value) {
$output[$key] = sanitize_text_field($input[$key]);
}
return $output;
}
/**
* Add settings link on plugin
*
* @since 1.0
**/
public function add_settings_link($links, $file)
{
if (plugin_basename(__FILE__) == $file) {
$settings_link =
'<a href="' .
admin_url("tools.php?page=chatlio-settings") .
'">' .
__("Settings", "chatlio") .
"</a>";
array_unshift($links, $settings_link);
}
return $links;
}
}
new Chatlio();