PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.11.0
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.11.0
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / Bootstrap.php

Bootstrap.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.11.0, at includes/Bootstrap.php

235 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hurrytimer;
4
5 use Hurrytimer\Dependencies\Carbon\Carbon;
6
7 /**
8 * The file that defines the core plugin class
9 *
10 * A class definition that includes attributes and functions used across both the
11 * public-facing side of the site and the admin area.
12 *
13 * @link http:nabillemsieh.com
14 * @since 1.0.0
15 *
16 * @package Hurrytimer
17 * @subpackage Hurrytimer/includes
18 */
19
20 /**
21 * The core plugin class.
22 *
23 * This is used to define internationalization, admin-specific hooks, and
24 * public-facing site hooks.
25 *
26 * Also maintains the unique identifier of this plugin as well as the current
27 * version of the plugin.
28 *
29 * @since 1.0.0
30 * @package Hurrytimer
31 * @subpackage Hurrytimer/includes
32 * @author Nabil Lemsieh <contact@nabillemsieh.com>
33 */
34 class Bootstrap
35 {
36 /**
37 * The unique identifier of this plugin.
38 *
39 * @since 1.0.0
40 * @access protected
41 * @var string $pluginName The string used to uniquely identify this plugin.
42 */
43 protected $pluginName;
44
45 /**
46 * The current version of the plugin.
47 *
48 * @since 1.0.0
49 * @access protected
50 * @var string $version The current version of the plugin.
51 */
52 protected $version;
53
54 /**
55 * Define the core functionality of the plugin.
56 *
57 * @since 1.0.0
58 */
59 public function __construct()
60 {
61 $this->version = HURRYT_VERSION;
62 $this->pluginName = 'hurrytimer';
63 }
64
65 public function run()
66 {
67 $this->load_macros();
68 (new I18n())->load_plugin_textdomain();
69 Installer::get_instance()->upgrade();
70 $this->register_post_type();
71 $this->define_admin_hooks();
72 $this->define_front_hooks();
73 $this->define_ip_logs_cleanup_hook();
74 }
75 function define_ip_logs_cleanup_hook(){
76 add_action( IP_Log_Manager::CLEANUP_ACTION, array( new IP_Log_Manager(), 'cleanup_ip_logs' ) );
77 }
78
79 /**
80 * Autoload the required dependencies for this plugin.
81 *
82 * @since 1.0.0
83 * @access private
84 */
85 public function load_macros()
86 {
87 Carbon::macro( 'getBrowserTimestamp', function () {
88 /** @var Carbon $this */
89 return $this->getTimestamp() * 1000;
90 } );
91
92 /**
93 * @var Carbon $baseDate
94 */
95 Carbon::macro( 'modifyWeekOfMonth', function ( $baseDate ) {
96 /** @var Carbon $this */
97 /** @var Carbon $baseDate */
98 $date = $this->copy()->nthOfMonth( $baseDate->weekOfMonth, $baseDate->dayOfWeek );
99 if ( $date ) {
100 $this->nthOfMonth( $baseDate->weekOfMonth, $baseDate->dayOfWeek );
101 }
102 else{
103 $this->nthOfMonth(4, $baseDate->dayOfWeek);
104 }
105
106 return $this;
107 } );
108
109 }
110
111 /**
112 * Register all of the hooks related to the admin area functionality
113 * of the plugin.
114 *
115 * @since 1.0.0
116 * @access private
117 */
118 private function define_admin_hooks()
119 {
120 $plugin_admin = new Admin(
121 $this->getPluginName(),
122 $this->getVersion()
123 );
124 add_action( 'admin_menu', [ $plugin_admin, 'menu' ] );
125 add_action( 'admin_init', [ $plugin_admin, 'settingsBox' ] );
126
127 //removeIf(pro)
128 add_filter( 'add_meta_boxes', [ $plugin_admin, 'upgradeBanner' ] );
129 //endRemoveIf(pro)
130 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueStyles' ] );
131 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueScripts' ] );
132 }
133
134 /**
135 * Register all of the hooks related to the public-facing functionality
136 * of the plugin.
137 *
138 * @since 1.0.0
139 * @access private
140 */
141 private function define_front_hooks()
142 {
143
144 if ( is_admin() && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
145 return;
146 }
147 // Make sure shortcode is recognized.
148 $this->register_shortcode();
149
150 if ( hurryt_count_active_campaigns() == 0 ) {
151 return;
152 }
153
154 $front = new Frontend(
155 $this->getPluginName(),
156 $this->getVersion()
157 );
158
159 $front->init();
160
161
162 }
163
164 /**
165 * Register shortcode callback.
166 */
167 function register_shortcode()
168 {
169 $shortcode = new CampaignShortcode();
170 $shortcode->init();
171 }
172
173 /**
174 * The name of the plugin used to uniquely identify it within the context of
175 * WordPress and to define internationalization functionality.
176 *
177 * @return string The name of the plugin.
178 * @since 1.0.0
179 */
180 public function getPluginName()
181 {
182 return $this->pluginName;
183 }
184
185 /**
186 * Retrieve the version number of the plugin.
187 *
188 * @return string The version number of the plugin.
189 * @since 1.0.0
190 */
191 public function getVersion()
192 {
193 return $this->version;
194 }
195
196 public function register_post_type()
197 {
198 $args = array(
199 'label' => __( 'All', 'hurrytimer' ),
200 'labels' => array(
201 'name' => __( 'Campaigns', 'hurrytimer' ),
202 'singular_name' => __( 'Campaign', 'hurrytimer' ),
203 'add_new' => __( 'Add Campaign', 'hurrytimer' ),
204 'add_new_item' => __( 'Add Campaign', 'hurrytimer' ),
205 'edit' => __( 'Edit', 'hurrytimer' ),
206 'edit_item' => __( 'Edit Campaign', 'hurrytimer' ),
207 'new_item' => __( 'New Campaign', 'hurrytimer' ),
208 'view' => __( 'View Campaign', 'hurrytimer' ),
209 'view_item' => __( 'View Campaign', 'hurrytimer' ),
210 'search_items' => __( 'Search Campaign', 'hurrytimer' ),
211 'not_found' => __( 'No Campaign', 'hurrytimer' ),
212 'not_found_in_trash' => __(
213 'No campaign found in trash',
214 'hurrytimer'
215 ),
216 'parent' => __( 'Parent Campaign', 'hurrytimer' ),
217 'menu_name' => __( 'All Campaigns', 'hurrytimer' ),
218 ),
219 'public' => false,
220 'show_ui' => true,
221 'publicly_queryable' => false,
222 'exclude_from_search' => true,
223 'show_in_menu' => 'hurrytimer',
224 'hierarchical' => false,
225 'show_in_nav_menus' => false,
226 'rewrite' => false,
227 'query_var' => false,
228 'supports' => array( 'title' ),
229 'has_archive' => false,
230 'menu_positon' => 65,
231 );
232 register_post_type( HURRYT_POST_TYPE, $args );
233 }
234 }
235