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

241 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 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 * The unique identifier of this plugin.
37 *
38 * @since 1.0.0
39 * @access protected
40 * @var string $pluginName The string used to uniquely identify this plugin.
41 */
42 protected $pluginName;
43
44 /**
45 * The current version of the plugin.
46 *
47 * @since 1.0.0
48 * @access protected
49 * @var string $version The current version of the plugin.
50 */
51 protected $version;
52
53 /**
54 * Define the core functionality of the plugin.
55 *
56 * @since 1.0.0
57 */
58 public function __construct() {
59 $this->version = HURRYT_VERSION;
60 $this->pluginName = 'hurrytimer';
61 }
62
63 public function run() {
64 $this->load_dependencies();
65 $this->setLocale();
66 $this->maybe_upgrade();
67 $this->register_post_type();
68 $this->define_admin_hooks();
69 $this->define_front_hooks();
70 }
71
72 /**
73 * Autoload the required dependencies for this plugin.
74 *
75 * @since 1.0.0
76 * @access private
77 */
78 public function load_dependencies() {
79 require HURRYT_DIR . 'includes/vendor/autoload.php';
80 \spl_autoload_register( function ( $class ) {
81 if ( strpos( $class, __NAMESPACE__ ) !== 0 ) {
82 return;
83 }
84 $class = str_replace( 'Hurrytimer', '', $class );
85 $class = str_replace( '\\', '/', $class );
86 require_once HURRYT_DIR . "includes/{$class}.php";
87 } );
88 require_once HURRYT_DIR . 'includes/functions.php';
89
90 Carbon::macro( 'getBrowserTimestamp', function () {
91 /**
92 * @var Carbon $this
93 */
94 return $this->getTimestamp() * 1000;
95 } );
96 }
97
98 /**
99 * Define the locale for this plugin for internationalization.
100 *
101 * @since 1.0.0
102 * @access private
103 */
104 private function setLocale() {
105
106 add_action(
107 'plugins_loaded',
108 [
109 new I18n(),
110 'load_plugin_textdomain',
111 ]
112 );
113 }
114
115 private function maybe_upgrade() {
116 add_action(
117 'plugins_loaded', function () {
118 Upgrade::getInstance()->run();
119 }
120 );
121 }
122
123 /**
124 * Register all of the hooks related to the admin area functionality
125 * of the plugin.
126 *
127 * @since 1.0.0
128 * @access private
129 */
130 private function define_admin_hooks() {
131 $plugin_admin = new Admin(
132 $this->getPluginName(),
133 $this->getVersion()
134 );
135 add_action( 'admin_menu', [ $plugin_admin, 'menu' ] );
136 add_action( 'admin_init', [ $plugin_admin, 'settingsBox' ] );
137
138 //removeIf(pro)
139 add_filter( 'add_meta_boxes', [ $plugin_admin, 'upgradeBanner' ] );
140 //endRemoveIf(pro)
141 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueStyles' ] );
142 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueueScripts' ] );
143 }
144
145 /**
146 * Register all of the hooks related to the public-facing functionality
147 * of the plugin.
148 *
149 * @since 1.0.0
150 * @access private
151 */
152 private function define_front_hooks() {
153
154 if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
155 return;
156 }
157 // Make sure shortcode is recognized.
158 $this->register_shortcode();
159
160 if ( hurryt_count_active_campaigns() == 0 ) {
161 return;
162 }
163
164 $front = new Frontend(
165 $this->getPluginName(),
166 $this->getVersion()
167 );
168
169 $front->init();
170
171
172 }
173
174 /**
175 * Register shortcode callback.
176 */
177 function register_shortcode() {
178 $shortcode = new CampaignShortcode();
179 $shortcode->init();
180 }
181
182 /**
183 * The name of the plugin used to uniquely identify it within the context of
184 * WordPress and to define internationalization functionality.
185 *
186 * @return string The name of the plugin.
187 * @since 1.0.0
188 */
189 public function getPluginName() {
190 return $this->pluginName;
191 }
192
193 /**
194 * Retrieve the version number of the plugin.
195 *
196 * @return string The version number of the plugin.
197 * @since 1.0.0
198 */
199 public function getVersion() {
200 return $this->version;
201 }
202
203 public function register_post_type() {
204 $args = array(
205 'label' => __( 'All', DOMAIN ),
206 'labels' => array(
207 'name' => __( 'Campaigns', DOMAIN ),
208 'singular_name' => __( 'Campaign', DOMAIN ),
209 'add_new' => __( 'Add Campaign', DOMAIN ),
210 'add_new_item' => __( 'Add Campaign', DOMAIN ),
211 'edit' => __( 'Edit', DOMAIN ),
212 'edit_item' => __( 'Edit Campaign', DOMAIN ),
213 'new_item' => __( 'New Campaign', DOMAIN ),
214 'view' => __( 'View Campaign', DOMAIN ),
215 'view_item' => __( 'View Campaign', DOMAIN ),
216 'search_items' => __( 'Search Campaign', DOMAIN ),
217 'not_found' => __( 'No Campaign', DOMAIN ),
218 'not_found_in_trash' => __(
219 'No Countdown Timer found in trash',
220 DOMAIN
221 ),
222 'parent' => __( 'Parent Campaign', DOMAIN ),
223 'menu_name' => __( 'All Campaigns', DOMAIN ),
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