* @author : Premio <contact@premio.io>
if (defined('ABSPATH') === false) {
class Chaty_Affiliate_Program
* The Name of this plugin.
* @var string $pluginName The Name of this plugin.
public $pluginName = "Chaty";
* The Slug of this plugin.
* @var string $pluginSlug The Slug of this plugin.
public $pluginSlug = "chaty";
* __construct method initializes the object and adds action hooks.
public function __construct()
add_action("wp_ajax_".$this->pluginSlug."_affiliate_program", [$this, "affiliate_program"]);
add_action('admin_notices', [$this, 'admin_notices']);
* affiliate_program method handles the affiliate program action.
* This method checks if the current user has the capability to manage options.
* If the user has the capability, it retrieves the nonce and days values from the POST data.
* Then, it verifies the nonce and performs the necessary actions based on the values.
* If the days value is -1, it adds an option to hide the affiliate box.
* Otherwise, it adds an option to set the date after which the affiliate box should be shown.
public function affiliate_program()
if (current_user_can('manage_options')) {
$nonce = filter_input(INPUT_POST, 'nonce');
$days = filter_input(INPUT_POST, 'days');
if (!empty($nonce) && wp_verify_nonce($nonce, $this->pluginSlug."_affiliate_program")) {
add_option($this->pluginSlug."_hide_affiliate_box", "1");
$date = gmdate("Y-m-d", strtotime("+".$days." days"));
update_option($this->pluginSlug."_show_affiliate_box_after", $date);
}//end affiliate_program()
* admin_notices method displays notices in the admin area for users with the 'manage_options' capability.
public function admin_notices()
if (current_user_can('manage_options')) {
$isHidden = get_option($this->pluginSlug."_hide_affiliate_box");
if ($isHidden !== false) {
$dateToShow = get_option($this->pluginSlug."_show_affiliate_box_after");
if ($dateToShow === false || empty($dateToShow)) {
$date = gmdate("Y-m-d", strtotime("+5 days"));
update_option($this->pluginSlug."_show_affiliate_box_after", $date);
$currentDate = gmdate("Y-m-d");
if ($currentDate < $dateToShow) {
.<?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate p a {
.notice.chaty-premio-affiliate {
display: block !important;
.<?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate p a:hover, .<?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate p a:focus {
.<?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate .button span {
.<?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate {
padding: 1px 100px 12px 12px;
.<?php echo esc_attr($this->pluginSlug) ?>-affiliate-popup {
background: rgba(0, 0, 0, 0.65);
.<?php echo esc_attr($this->pluginSlug) ?>-affiliate-popup-content {
-webkit-border-radius: 5px;
.<?php echo esc_attr($this->pluginSlug) ?>-affiliate-title {
.<?php echo esc_attr($this->pluginSlug) ?>-affiliate-options a {
.<?php echo esc_attr($this->pluginSlug) ?>-affiliate-options a.dismiss {
.<?php echo esc_attr($this->pluginSlug) ?>-affiliate-options a:hover, .affiliate-options a:focus {
button.<?php echo esc_attr($this->pluginSlug) ?>-close-affiliate-popup {
a.button.button-primary.<?php echo esc_attr($this->pluginSlug) ?>-affiliate-btn {
border: solid 1px #F51366;
-webkit-box-shadow: 0 3px 5px -3px #333333;
-moz-box-shadow: 0 3px 5px -3px #333333;
box-shadow: 0 3px 5px -3px #333333;
<div class="notice notice-info <?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate <?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate">
<?php printf(esc_html__("Hi there, you've been using %1\$s for a while now. Do you know that %2\$s has an affiliate program? Join now and get %3\$s", 'chaty'), "<b>".esc_attr($this->pluginName)."</b>", "<b>".esc_attr($this->pluginName)."</b>", "<b>25% lifetime commission</b>") ?>
<a href="#" class="dismiss-btn"><span class="dashicons dashicons-no-alt"></span><?php esc_html_e("Dismiss", 'chaty')?></a>
<div class="clear clearfix"></div>
<a class="button button-primary <?php echo esc_attr($this->pluginSlug) ?>-affiliate-btn" target="_blank" href="https://premio.io/affiliates/?utm_source=inapp&plugin=stars-testimonials&domain=<?php echo esc_attr($_SERVER['HTTP_HOST']) ?>"><?php esc_html_e("Tell me more", 'chaty') ?> <span class="dashicons dashicons-arrow-right-alt"></span></a>
<div class="<?php echo esc_attr($this->pluginSlug) ?>-affiliate-popup">
<div class="<?php echo esc_attr($this->pluginSlug) ?>-affiliate-popup-content">
<button class="<?php echo esc_attr($this->pluginSlug) ?>-close-affiliate-popup"><span class="dashicons dashicons-no-alt"></span></button>
<div class="<?php echo esc_attr($this->pluginSlug) ?>-affiliate-title"><?php esc_html_e("Would you like us to remind you about this later?", 'chaty') ?></div>
<div class="<?php echo esc_attr($this->pluginSlug) ?>-affiliate-options">
<a href="#" data-days="3"><?php esc_html_e("Remind me in 3 days", 'chaty') ?></a>
<a href="#" data-days="10"><?php esc_html_e("Remind me in 10 days", 'chaty') ?></a>
<a href="#" data-days="-1" class="dismiss"><?php esc_html_e("Don't remind me about this", 'chaty') ?></a>
jQuery(document).ready(function () {
jQuery(document).on("click", ".<?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate p a.dismiss-btn", function () {
jQuery(".<?php echo esc_attr($this->pluginSlug) ?>-affiliate-popup").show();
jQuery(document).on("click", ".<?php echo esc_attr($this->pluginSlug) ?>-close-affiliate-popup", function () {
jQuery(".<?php echo esc_attr($this->pluginSlug) ?>-affiliate-popup").hide();
jQuery(document).on("click", ".<?php echo esc_attr($this->pluginSlug) ?>-affiliate-options a", function () {
var dataDays = jQuery(this).attr("data-days");
jQuery(".<?php echo esc_attr($this->pluginSlug) ?>-affiliate-popup").hide();
jQuery(".<?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate").hide();
url: "<?php echo esc_url(admin_url("admin-ajax.php")) ?>",
data: "action=<?php echo esc_attr($this->pluginSlug) ?>_affiliate_program&days=" + dataDays + "&nonce=<?php echo esc_attr(wp_create_nonce($this->pluginSlug."_affiliate_program")) ?>",
jQuery(".<?php echo esc_attr($this->pluginSlug) ?>-affiliate-popup").remove();
jQuery(".<?php echo esc_attr($this->pluginSlug) ?>-premio-affiliate").remove();
$chatyAffiliateProgram = new Chaty_Affiliate_Program();