# hurrytimer/1.2.2/includes/class-hurrytimer.php

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

- Page: https://pluginprobe.com/plugins/hurrytimer/1.2.2/code/includes/class-hurrytimer.php
- Raw: https://pluginprobe.com/plugins/hurrytimer/1.2.2/raw/includes/class-hurrytimer.php
- Modified: 2019-01-22T11:07: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.2/code/includes/class-hurrytimer.php#L10-L20`.

```php
<?php
namespace Hurrytimer;

/**
 * The file that defines the core plugin class
 *
 * A class definition that includes attributes and functions used across both the
 * public-facing side of the site and the admin area.
 *
 * @link       http://nabillemsieh.com
 * @since      1.0.0
 *
 * @package    Hurrytimer
 * @subpackage Hurrytimer/includes
 */

/**
 * The core plugin class.
 *
 * This is used to define internationalization, admin-specific hooks, and
 * public-facing site hooks.
 *
 * Also maintains the unique identifier of this plugin as well as the current
 * version of the plugin.
 *
 * @since      1.0.0
 * @package    Hurrytimer
 * @subpackage Hurrytimer/includes
 * @author     Nabil Lemsieh <contact@nabillemsieh.com>
 */
class Hurrytimer
{

    /**
     * The loader that's responsible for maintaining and registering all hooks that power
     * the plugin.
     *
     * @since    1.0.0
     * @access   protected
     * @var      Hurrytimer_Loader $loader Maintains and registers all hooks for the plugin.
     */
    protected $loader;

    /**
     * The unique identifier of this plugin.
     *
     * @since    1.0.0
     * @access   protected
     * @var      string $plugin_name The string used to uniquely identify this plugin.
     */
    protected $plugin_name;

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

    /**
     * Define the core functionality of the plugin.
     *
     * Set the plugin name and the plugin version that can be used throughout the plugin.
     * Load the dependencies, define the locale, and set the hooks for the admin area and
     * the public-facing side of the site.
     *
     * @since    1.0.0
     */
    public function __construct()
    {
        $this->version = HURRYTIMER_PLUGIN_VERSION;
        $this->plugin_name = 'hurrytimer';
        $this->load_dependencies();
        $this->set_locale();
        $this->on_upgrade();
        $this->register_post_type();
        $this->define_admin_hooks();
        $this->define_public_hooks();

    }

    /**
     * Load the required dependencies for this plugin.
     *
     * Include the following files that make up the plugin:
     *
     * - Hurrytimer_Loader. Orchestrates the hooks of the plugin.
     * - Hurrytimer_i18n. Defines internationalization functionality.
     * - Hurrytimer_Admin. Defines all hooks for the admin area.
     * - Hurrytimer_Public. Defines all hooks for the public side of the site.
     *
     * Create an instance of the loader which will be used to register the hooks
     * with WordPress.
     *
     * @since    1.0.0
     * @access   private
     */
    private function load_dependencies()
    {

        require_once HURRYTIMER_PLUGIN_DIR . '/includes/utils/class-hurrytimer-constants.php';
        require_once HURRYTIMER_PLUGIN_DIR . '/includes/utils/class-hurrytimer-helper.php';
        require_once HURRYTIMER_PLUGIN_DIR . '/includes/utils/class-sql-builder.php';
        require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-ip-detection.php';
        require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-cookie-detection.php';

        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-hurrytimer-countdown.php';
        /**
         * The class responsible for orchestrating the actions and filters of the
         * core plugin.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-hurrytimer-loader.php';

        /**
         * The class responsible for defining internationalization functionality
         * of the plugin.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-hurrytimer-i18n.php';

        /**
         * The class responsible for defining all actions that occur in the admin area.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-hurrytimer-admin.php';

        /**
         * The class responsible for defining all actions that occur in the public-facing
         * side of the site.
         */
        require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-hurrytimer-public.php';

        $this->loader = new Hurrytimer_Loader();

    }

    /**
     * Define the locale for this plugin for internationalization.
     *
     * Uses the Hurrytimer_i18n class in order to set the domain and to register the hook
     * with WordPress.
     *
     * @since    1.0.0
     * @access   private
     */
    private function set_locale()
    {

        $plugin_i18n = new Hurrytimer_i18n();

        $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');

    }

    private function on_upgrade()
    {

        add_action('plugins_loaded', function () {
            $installed_ver = get_option('hurrytimer_db_version');
            if(!$installed_ver || $installed_ver != HURRYTIMER_DB_VERSION){
            $sql_builder = new SQL_Builder('hurrytimer_evergreen');
            $sql_builder
                ->create()
                ->bigint('id', 20, true, false, true)
                ->bigint('countdown_id', 20, true)
                ->string('client_ip_address', 50, false)
                ->boolean('expired')
                ->bigint('client_expires_at', 20, true)
                ->timestamp('destroy_at', true)
                ->primary_key('id')
                ->run();
                update_option('hurrytimer_db_version', HURRYTIMER_DB_VERSION);
            }

            $current_version = get_option('hurrytimer_version');
            if (version_compare($current_version, '1.1.3', '<=')) {
                @delete_option('_htmr_reset_cookie');
            }
            if (version_compare($current_version, '1.0.1', '<=')) {
                $result = get_posts(['post_type' => 'hurrytimer_countdown']);
                foreach ($result as $item) {
                    $countdown = new Hurrytimer_Countdown($item->ID);
                    $headline_status = get_post_meta($item->ID, 'headline_status', true);
                    if (intval($headline_status) === Headline_Status::HIDE) {
                        $countdown->set_display_headline(false);
                        $countdown->set_headline_position(Headline_Position::ABOVE_TIMER);
                    } else {
                        $countdown->set_display_headline(true);
                        $countdown->set_headline_position($headline_status);
                    }
                    delete_post_meta($item->ID, 'headline_status');
                }
            }
            update_option('hurrytimer_version', HURRYTIMER_PLUGIN_VERSION);

        });
    }

    /**
     * Register all of the hooks related to the admin area functionality
     * of the plugin.
     *
     * @since    1.0.0
     * @access   private
     */
    private function define_admin_hooks()
    {
        $plugin_admin = new Hurrytimer_Admin($this->get_plugin_name(), $this->get_version());
        $this->loader->add_action('admin_menu', $plugin_admin, 'menu');
        $this->loader->add_action('admin_init', $plugin_admin, 'meta_boxes');
        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
    }

    /**
     * Register all of the hooks related to the public-facing functionality
     * of the plugin.
     *
     * @since    1.0.0
     * @access   private
     */
    private function define_public_hooks()
    {

        $plugin_public = new Hurrytimer_Public($this->get_plugin_name(), $this->get_version());

        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');

    }

    /**
     * Run the loader to execute all of the hooks with WordPress.
     *
     * @since    1.0.0
     */
    public function run()
    {
        $this->loader->run();
    }

    /**
     * The name of the plugin used to uniquely identify it within the context of
     * WordPress and to define internationalization functionality.
     *
     * @since     1.0.0
     * @return    string    The name of the plugin.
     */
    public function get_plugin_name()
    {
        return $this->plugin_name;
    }

    /**
     * The reference to the class that orchestrates the hooks with the plugin.
     *
     * @since     1.0.0
     * @return    Hurrytimer_Loader    Orchestrates the hooks of the plugin.
     */
    public function get_loader()
    {
        return $this->loader;
    }

    /**
     * Retrieve the version number of the plugin.
     *
     * @since     1.0.0
     * @return    string    The version number of the plugin.
     */
    public function get_version()
    {
        return $this->version;
    }

    public function register_post_type()
    {
        $args = array(
            'label' => __('All', DOMAIN),
            'labels' => array(
                'name' => __('Countdown Timer', DOMAIN),
                'singular_name' => __('Countdown Timer', DOMAIN),
                'add_new' => __('Add Timer', DOMAIN),
                'add_new_item' => __('Add New Timer', DOMAIN),
                'edit' => __('Edit', DOMAIN),
                'edit_item' => __('Edit Countdown Timer', DOMAIN),
                'new_item' => __('New Countdown Timer', DOMAIN),
                'view' => __('View Countdown Timer', DOMAIN),
                'view_item' => __('View Countdown Timer', DOMAIN),
                'search_items' => __('Search Countdown Timer', DOMAIN),
                'not_found' => __('No Countdown Timer', DOMAIN),
                'not_found_in_trash' => __('No Countdown Timer found in trash', DOMAIN),
                'parent' => __('Parent Campaign', DOMAIN),
                'menu_name' => __('All Timers', DOMAIN),
            ),
            'public' => false,
            'show_ui' => true,
            'publicly_queryable' => false,
            'exclude_from_search' => true,
            'show_in_menu' => 'hurrytimer',
            'hierarchical' => false,
            'show_in_nav_menus' => false,
            'rewrite' => false,
            'query_var' => false,
            'supports' => array('title'),
            'has_archive' => false,
            'menu_positon' => 65,

        );
        register_post_type(
            HURRYTIMER_COUNTDOWN_PT,
            $args
        );
    }
}

```
