PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.14.3
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.14.3
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.14.3, at includes/Bootstrap.php

240 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 add_action('init', function(){
69 (new I18n())->load_plugin_textdomain();
70 $this->register_post_type();
71 Installer::get_instance()->upgrade();
72 $this->define_front_hooks();
73 });
74 $this->define_admin_hooks();
75 $this->define_ip_logs_cleanup_hook();
76
77 }
78
79
80 function define_ip_logs_cleanup_hook(){
81 add_action( IP_Log_Manager::CLEANUP_ACTION, array( new IP_Log_Manager(), 'cleanup_ip_logs' ) );
82 }
83
84 /**
85 * Autoload the required dependencies for this plugin.
86 *
87 * @since 1.0.0
88 * @access private
89 */
90 public function load_macros()
91 {
92 Carbon::macro( 'getBrowserTimestamp', function () {
93 /** @var Carbon $this */
94 return $this->getTimestamp() * 1000;
95 } );
96
97 /**
98 * @var Carbon $baseDate
99 */
100 Carbon::macro( 'modifyWeekOfMonth', function ( $baseDate ) {
101 /** @var Carbon $this */
102 /** @var Carbon $baseDate */
103 $date = $this->copy()->nthOfMonth( $baseDate->weekOfMonth, $baseDate->dayOfWeek );
104 if ( $date ) {
105 $this->nthOfMonth( $baseDate->weekOfMonth, $baseDate->dayOfWeek );
106 }
107 else{
108 $this->nthOfMonth(4, $baseDate->dayOfWeek);
109 }
110
111 return $this;
112 } );
113
114 }
115
116 /**
117 * Register all of the hooks related to the admin area functionality
118 * of the plugin.
119 *
120 * @since 1.0.0
121 * @access private
122 */
123 private function define_admin_hooks()
124 {
125 $plugin_admin = new Admin(
126 $this->getPluginName(),
127 $this->getVersion()
128 );
129 add_action( 'admin_menu', [ $plugin_admin, 'menu' ] );
130 add_action( 'admin_init', [ $plugin_admin, 'settingsBox' ] );
131
132 //removeIf(pro)
133 add_filter( 'add_meta_boxes', [ $plugin_admin, 'upgradeBanner' ] );
134 //endRemoveIf(pro)
135 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueStyles' ] );
136 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueScripts' ] );
137 }
138
139 /**
140 * Register all of the hooks related to the public-facing functionality
141 * of the plugin.
142 *
143 * @since 1.0.0
144 * @access private
145 */
146 private function define_front_hooks()
147 {
148
149 if ( is_admin() && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
150 return;
151 }
152 // Make sure shortcode is recognized.
153 $this->register_shortcode();
154
155 if ( hurryt_count_active_campaigns() == 0 ) {
156 return;
157 }
158
159 $front = new Frontend(
160 $this->getPluginName(),
161 $this->getVersion()
162 );
163
164 $front->init();
165
166
167 }
168
169 /**
170 * Register shortcode callback.
171 */
172 function register_shortcode()
173 {
174 $shortcode = new CampaignShortcode();
175 $shortcode->init();
176 }
177
178 /**
179 * The name of the plugin used to uniquely identify it within the context of
180 * WordPress and to define internationalization functionality.
181 *
182 * @return string The name of the plugin.
183 * @since 1.0.0
184 */
185 public function getPluginName()
186 {
187 return $this->pluginName;
188 }
189
190 /**
191 * Retrieve the version number of the plugin.
192 *
193 * @return string The version number of the plugin.
194 * @since 1.0.0
195 */
196 public function getVersion()
197 {
198 return $this->version;
199 }
200
201 public function register_post_type()
202 {
203 $args = array(
204 'label' => __( 'All', 'hurrytimer' ),
205 'labels' => array(
206 'name' => __( 'Campaigns', 'hurrytimer' ),
207 'singular_name' => __( 'Campaign', 'hurrytimer' ),
208 'add_new' => __( 'Add Campaign', 'hurrytimer' ),
209 'add_new_item' => __( 'Add Campaign', 'hurrytimer' ),
210 'edit' => __( 'Edit', 'hurrytimer' ),
211 'edit_item' => __( 'Edit Campaign', 'hurrytimer' ),
212 'new_item' => __( 'New Campaign', 'hurrytimer' ),
213 'view' => __( 'View Campaign', 'hurrytimer' ),
214 'view_item' => __( 'View Campaign', 'hurrytimer' ),
215 'search_items' => __( 'Search Campaign', 'hurrytimer' ),
216 'not_found' => __( 'No Campaign', 'hurrytimer' ),
217 'not_found_in_trash' => __(
218 'No campaign found in trash',
219 'hurrytimer'
220 ),
221 'parent' => __( 'Parent Campaign', 'hurrytimer' ),
222 'menu_name' => __( 'All Campaigns', 'hurrytimer' ),
223 ),
224 'public' => false,
225 'show_ui' => true,
226 'publicly_queryable' => false,
227 'exclude_from_search' => true,
228 'show_in_menu' => 'hurrytimer',
229 'hierarchical' => false,
230 'show_in_nav_menus' => false,
231 'rewrite' => false,
232 'query_var' => false,
233 'supports' => array( 'title' ),
234 'has_archive' => false,
235 'menu_positon' => 65,
236 );
237 register_post_type( HURRYT_POST_TYPE, $args );
238 }
239 }
240