PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.6.2
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.6.2
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
← All changes | includes/Bootstrap.php +89 -62 2.1.72.6.2 View file →
@@ -1,8 +1,10 @@
1 1 <?php
2 2
3 3 namespace Hurrytimer;
4 4
5 +use Hurrytimer\Dependencies\Carbon\Carbon;
6 +
5 7 /**
6 8 * The file that defines the core plugin class
7 9 *
8 10 * A class definition that includes attributes and functions used across both the
@@ -55,20 +57,20 @@
55 57 * @since 1.0.0
56 58 */
57 59 public function __construct()
58 60 {
59 - $this->version = HURRYT_VERSION;
61 + $this->version = HURRYT_VERSION;
60 62 $this->pluginName = 'hurrytimer';
61 63 }
62 64
63 65 public function run()
64 66 {
65 - $this->loadDependencies();
67 + $this->load_macros();
66 68 $this->setLocale();
67 - $this->maybeUpgrade();
68 - $this->registerPostType();
69 - $this->defineAdminHooks();
70 - $this->defineFrontHooks();
69 + Installer::get_instance()->upgrade();
70 + $this->register_post_type();
71 + $this->define_admin_hooks();
72 + $this->define_front_hooks();
71 73 }
72 74
73 75 /**
74 76 * Autoload the required dependencies for this plugin.
@@ -75,18 +77,31 @@
75 77 *
76 78 * @since 1.0.0
77 79 * @access private
78 80 */
79 - public function loadDependencies()
81 + public function load_macros()
80 82 {
81 - \spl_autoload_register(function ($class) {
82 - if (strpos($class, __NAMESPACE__) !== 0) {
83 - return;
83 + Carbon::macro( 'getBrowserTimestamp', function () {
84 + /** @var Carbon $this */
85 + return $this->getTimestamp() * 1000;
86 + } );
87 +
88 + /**
89 + * @var Carbon $baseDate
90 + */
91 + Carbon::macro( 'modifyWeekOfMonth', function ( $baseDate ) {
92 + /** @var Carbon $this */
93 + /** @var Carbon $baseDate */
94 + $date = $this->copy()->nthOfMonth( $baseDate->weekOfMonth, $baseDate->dayOfWeek );
95 + if ( $date ) {
96 + $this->nthOfMonth( $baseDate->weekOfMonth, $baseDate->dayOfWeek );
84 97 }
85 - $class = str_replace('Hurrytimer', '', $class);
86 - $class = str_replace('\\', '/', $class);
87 - require_once HURRYT_DIR . "includes/{$class}.php";
88 - });
98 + else{
99 + $this->nthOfMonth(4, $baseDate->dayOfWeek);
100 + }
101 +
102 + return $this;
103 + } );
89 104
90 105 }
91 106
92 107 /**
@@ -106,18 +121,9 @@
106 121 ]
107 122 );
108 123 }
109 124
110 - private function maybeUpgrade()
111 - {
112 - add_action(
113 - 'plugins_loaded', function () {
114 125
115 - Upgrade::getInstance()->run();
116 - }
117 - );
118 - }
119 -
120 126 /**
121 127 * Register all of the hooks related to the admin area functionality
122 128 * of the plugin.
123 129 *
@@ -123,22 +129,22 @@
123 129 *
124 130 * @since 1.0.0
125 131 * @access private
126 132 */
127 - private function defineAdminHooks()
133 + private function define_admin_hooks()
128 134 {
129 135 $plugin_admin = new Admin(
130 136 $this->getPluginName(),
131 137 $this->getVersion()
132 138 );
133 - add_action('admin_menu', [$plugin_admin, 'menu']);
134 - add_action('admin_init', [$plugin_admin, 'settingsBox']);
139 + add_action( 'admin_menu', [ $plugin_admin, 'menu' ] );
140 + add_action( 'admin_init', [ $plugin_admin, 'settingsBox' ] );
135 141
136 142 //removeIf(pro)
137 - add_filter('add_meta_boxes', [$plugin_admin, 'upgradeBanner']);
143 + add_filter( 'add_meta_boxes', [ $plugin_admin, 'upgradeBanner' ] );
138 144 //endRemoveIf(pro)
139 - add_action('admin_enqueue_scripts', [$plugin_admin, 'enqueueStyles']);
140 - add_action('admin_enqueue_scripts', [$plugin_admin, 'enqueueScripts']);
145 + add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueStyles' ] );
146 + add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueScripts' ] );
141 147 }
142 148
143 149 /**
144 150 * Register all of the hooks related to the public-facing functionality
@@ -146,25 +152,46 @@
146 152 *
147 153 * @since 1.0.0
148 154 * @access private
149 155 */
150 - private function defineFrontHooks()
156 + private function define_front_hooks()
151 157 {
158 +
159 + if ( is_admin() && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
160 + return;
161 + }
162 + // Make sure shortcode is recognized.
163 + $this->register_shortcode();
164 +
165 + if ( hurryt_count_active_campaigns() == 0 ) {
166 + return;
167 + }
168 +
152 169 $front = new Frontend(
153 170 $this->getPluginName(),
154 171 $this->getVersion()
155 172 );
156 173
157 - add_action('wp_enqueue_scripts', [$front, 'enqueue_styles']);
158 - add_action('wp_enqueue_scripts', [$front, 'enqueue_scripts']);
174 + $front->init();
175 +
176 +
159 177 }
160 178
161 179 /**
180 + * Register shortcode callback.
181 + */
182 + function register_shortcode()
183 + {
184 + $shortcode = new CampaignShortcode();
185 + $shortcode->init();
186 + }
187 +
188 + /**
162 189 * The name of the plugin used to uniquely identify it within the context of
163 190 * WordPress and to define internationalization functionality.
164 191 *
192 + * @return string The name of the plugin.
165 193 * @since 1.0.0
166 - * @return string The name of the plugin.
167 194 */
168 195 public function getPluginName()
169 196 {
170 197 return $this->pluginName;
@@ -172,10 +199,10 @@
172 199
173 200 /**
174 201 * Retrieve the version number of the plugin.
175 202 *
203 + * @return string The version number of the plugin.
176 204 * @since 1.0.0
177 - * @return string The version number of the plugin.
178 205 */
179 206 public function getVersion()
180 207 {
181 208 return $this->version;
@@ -180,43 +207,43 @@
180 207 {
181 208 return $this->version;
182 209 }
183 210
184 - public function registerPostType()
211 + public function register_post_type()
185 212 {
186 213 $args = array(
187 - 'label' => __('All', DOMAIN),
188 - 'labels' => array(
189 - 'name' => __('Campaign', DOMAIN),
190 - 'singular_name' => __('Campaign', DOMAIN),
191 - 'add_new' => __('Add Campaign', DOMAIN),
192 - 'add_new_item' => __('Add Campaign', DOMAIN),
193 - 'edit' => __('Edit', DOMAIN),
194 - 'edit_item' => __('Edit Campaign', DOMAIN),
195 - 'new_item' => __('New Campaign', DOMAIN),
196 - 'view' => __('View Campaign', DOMAIN),
197 - 'view_item' => __('View Campaign', DOMAIN),
198 - 'search_items' => __('Search Campaign', DOMAIN),
199 - 'not_found' => __('No Campaign', DOMAIN),
214 + 'label' => __( 'All', DOMAIN ),
215 + 'labels' => array(
216 + 'name' => __( 'Campaigns', DOMAIN ),
217 + 'singular_name' => __( 'Campaign', DOMAIN ),
218 + 'add_new' => __( 'Add Campaign', DOMAIN ),
219 + 'add_new_item' => __( 'Add Campaign', DOMAIN ),
220 + 'edit' => __( 'Edit', DOMAIN ),
221 + 'edit_item' => __( 'Edit Campaign', DOMAIN ),
222 + 'new_item' => __( 'New Campaign', DOMAIN ),
223 + 'view' => __( 'View Campaign', DOMAIN ),
224 + 'view_item' => __( 'View Campaign', DOMAIN ),
225 + 'search_items' => __( 'Search Campaign', DOMAIN ),
226 + 'not_found' => __( 'No Campaign', DOMAIN ),
200 227 'not_found_in_trash' => __(
201 228 'No Countdown Timer found in trash',
202 229 DOMAIN
203 230 ),
204 - 'parent' => __('Parent Campaign', DOMAIN),
205 - 'menu_name' => __('All Campaigns', DOMAIN),
231 + 'parent' => __( 'Parent Campaign', DOMAIN ),
232 + 'menu_name' => __( 'All Campaigns', DOMAIN ),
206 233 ),
207 - 'public' => false,
208 - 'show_ui' => true,
209 - 'publicly_queryable' => false,
234 + 'public' => false,
235 + 'show_ui' => true,
236 + 'publicly_queryable' => false,
210 237 'exclude_from_search' => true,
211 - 'show_in_menu' => 'hurrytimer',
212 - 'hierarchical' => false,
213 - 'show_in_nav_menus' => false,
214 - 'rewrite' => false,
215 - 'query_var' => false,
216 - 'supports' => array('title'),
217 - 'has_archive' => false,
218 - 'menu_positon' => 65,
238 + 'show_in_menu' => 'hurrytimer',
239 + 'hierarchical' => false,
240 + 'show_in_nav_menus' => false,
241 + 'rewrite' => false,
242 + 'query_var' => false,
243 + 'supports' => array( 'title' ),
244 + 'has_archive' => false,
245 + 'menu_positon' => 65,
219 246 );
220 - register_post_type(HURRYT_POST_TYPE, $args);
247 + register_post_type( HURRYT_POST_TYPE, $args );
221 248 }
222 249 }