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
hurrytimer / includes / Bootstrap.php

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

250 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 $this->setLocale();
69 Installer::get_instance()->upgrade();
70 $this->register_post_type();
71 $this->define_admin_hooks();
72 $this->define_front_hooks();
73 }
74
75 /**
76 * Autoload the required dependencies for this plugin.
77 *
78 * @since 1.0.0
79 * @access private
80 */
81 public function load_macros()
82 {
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 );
97 }
98 else{
99 $this->nthOfMonth(4, $baseDate->dayOfWeek);
100 }
101
102 return $this;
103 } );
104
105 }
106
107 /**
108 * Define the locale for this plugin for internationalization.
109 *
110 * @since 1.0.0
111 * @access private
112 */
113 private function setLocale()
114 {
115
116 add_action(
117 'plugins_loaded',
118 [
119 new I18n(),
120 'load_plugin_textdomain',
121 ]
122 );
123 }
124
125
126 /**
127 * Register all of the hooks related to the admin area functionality
128 * of the plugin.
129 *
130 * @since 1.0.0
131 * @access private
132 */
133 private function define_admin_hooks()
134 {
135 $plugin_admin = new Admin(
136 $this->getPluginName(),
137 $this->getVersion()
138 );
139 add_action( 'admin_menu', [ $plugin_admin, 'menu' ] );
140 add_action( 'admin_init', [ $plugin_admin, 'settingsBox' ] );
141
142 //removeIf(pro)
143 add_filter( 'add_meta_boxes', [ $plugin_admin, 'upgradeBanner' ] );
144 //endRemoveIf(pro)
145 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueStyles' ] );
146 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueScripts' ] );
147 }
148
149 /**
150 * Register all of the hooks related to the public-facing functionality
151 * of the plugin.
152 *
153 * @since 1.0.0
154 * @access private
155 */
156 private function define_front_hooks()
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
169 $front = new Frontend(
170 $this->getPluginName(),
171 $this->getVersion()
172 );
173
174 $front->init();
175
176
177 }
178
179 /**
180 * Register shortcode callback.
181 */
182 function register_shortcode()
183 {
184 $shortcode = new CampaignShortcode();
185 $shortcode->init();
186 }
187
188 /**
189 * The name of the plugin used to uniquely identify it within the context of
190 * WordPress and to define internationalization functionality.
191 *
192 * @return string The name of the plugin.
193 * @since 1.0.0
194 */
195 public function getPluginName()
196 {
197 return $this->pluginName;
198 }
199
200 /**
201 * Retrieve the version number of the plugin.
202 *
203 * @return string The version number of the plugin.
204 * @since 1.0.0
205 */
206 public function getVersion()
207 {
208 return $this->version;
209 }
210
211 public function register_post_type()
212 {
213 $args = array(
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 ),
227 'not_found_in_trash' => __(
228 'No Countdown Timer found in trash',
229 DOMAIN
230 ),
231 'parent' => __( 'Parent Campaign', DOMAIN ),
232 'menu_name' => __( 'All Campaigns', DOMAIN ),
233 ),
234 'public' => false,
235 'show_ui' => true,
236 'publicly_queryable' => false,
237 'exclude_from_search' => true,
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,
246 );
247 register_post_type( HURRYT_POST_TYPE, $args );
248 }
249 }
250