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