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

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