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