# hurrytimer/1.2.0/includes/class-hurrytimer-public.php

HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress &amp; WooCommerce, version 1.2.0. 174 lines.

- Page: https://pluginprobe.com/plugins/hurrytimer/1.2.0/code/includes/class-hurrytimer-public.php
- Raw: https://pluginprobe.com/plugins/hurrytimer/1.2.0/raw/includes/class-hurrytimer-public.php
- Modified: 2019-01-21T18:38:36+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/hurrytimer/1.2.0/code/includes/class-hurrytimer-public.php#L10-L20`.

```php
<?php
namespace Hurrytimer;

require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-hurrytimer-countdown.php';
require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-hurrytimer-evergreen.php';
require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-hurrytimer-woocommerce.php';

/**
 * The public-facing functionality of the plugin.
 *
 * @link       http://nabillemsieh.com
 * @since      1.0.0
 *
 * @package    Hurrytimer
 * @subpackage Hurrytimer/public
 */

/**
 * The public-facing functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the public-facing stylesheet and JavaScript.
 *
 * @package    Hurrytimer
 * @subpackage Hurrytimer/public
 * @author     Nabil Lemsieh <contact@nabillemsieh.com>
 */
class Hurrytimer_Public
{

    /**
     * The ID of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string $plugin_name The ID of this plugin.
     */
    private $plugin_name;

    /**
     * The version of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string $version The current version of this plugin.
     */
    private $version;

    /**
     * Initialize the class and set its properties.
     *
     * @since    1.0.0
     *
     * @param      string $plugin_name The name of the plugin.
     * @param      string $version The version of this plugin.
     */
    public function __construct($plugin_name, $version)
    {

        $this->plugin_name = $plugin_name;
        $this->version = $version;
        add_shortcode('hurrytimer', [$this, 'countdown_shortcode']);
        add_action('wp', [$this, 'maybe_show_countdown_on_product_page']);
    }

    public function maybe_show_countdown_on_product_page()
    {
        global $post;

        if (!Helper::is_wc_active() || !is_product()) {
            return;
        }

        $wc_countdown = new WC_Countdown();
        $wc_countdown->maybe_show_countdown($post->ID);
    }

    /**
     * Register the stylesheets for the public-facing side of the site.
     *
     * @since    1.0.0
     */
    public function enqueue_styles()
    {

        wp_enqueue_style(
            $this->plugin_name,
            HURRYTIMER_PLUGIN_URL . '/assets/css/hurrytimer.css', array(),
            time(), 'all'
        );

        $countdowns = get_posts([
            'post_type' => HURRYTIMER_COUNTDOWN_PT,
            'posts_per_page' => -1,
            'post_status' => 'publish',
        ]);
        $css = "";
        foreach ($countdowns as $ct) {
            $countdown = new Hurrytimer_Countdown($ct->ID);
            $block_class = ".hurrytimer-cdt";
            $modifier_class = ".hurrytimer-cdt--{$countdown->get_id()}";
            $css .= "$modifier_class {$block_class}__time, $modifier_class {$block_class}__label, $modifier_class {$block_class}__sep { color: {$countdown->get_text_color()} !important;font-size: {$countdown->get_text_size()}px}\n";
            $css .= "$modifier_class {$block_class}__label { font-size: {$countdown->get_label_size()}px}\n";
            $css .= "$modifier_class {$block_class}__headline { font-size: {$countdown->get_headline_size()}px; color:{$countdown->get_headline_color()}}\n";
        }

        wp_add_inline_style(HURRYTIMER_PLUGIN_NAME, $css);

    }

    public function countdown_shortcode($attrs)
    {

        if (!isset($attrs['id']) || !is_numeric($attrs['id'])) {
            return null;
        }

        $attrs = shortcode_atts(
            [
                'id' => null,
            ], $attrs
        );

        return $this->get_countdown_timer_shortcode($attrs);
    }

    public function get_countdown_timer_shortcode($attrs)
    {
        $id = intval($attrs['id']);
        if (!get_post($id)) {
            return null;
        }

        $countdown = new Hurrytimer_Countdown($id);
        if (!$countdown->is_active()) {
            return null;
        }
        $config = $countdown->get_client_config();
        if (is_null($config)) {
            return null;
        }
        return "<div class='hurrytimer-cdt hurrytimer-cdt--" . $id . "' data-config='" . json_encode($config) . "'></div>";
    }

    /**
     * Register the JavaScript for the public-facing side of the site.
     *
     * @since    1.0.0
     */
    public function enqueue_scripts()
    {
        wp_enqueue_script(
            $this->plugin_name,
            plugin_dir_url(__DIR__) . 'assets/js/hurrytimer.js', array('jquery'),
            time(), true
        );

        wp_localize_script($this->plugin_name, 'hurrytimer_object', [
            'countdown_end_actions' => [
                'none' => CDT_End_Action::NO_ACTION,
                'hide' => CDT_End_Action::HIDE_COUNTDOWN_TIMER,
                'noAction' => CDT_End_Action::NO_ACTION,
                'redirect' => CDT_End_Action::REDIRECT,
            ],
            'restart' => [
                'no_restart' => Restart_Coundown::NO_RESTART,
                'immediately' => Restart_Coundown::IMMEDIATELY,
                'after_reload' => Restart_Coundown::AFTER_RELOAD
            ]
        ]);
    }

}

```
