| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Hurrytimer; |
| 4 | 4 | |
| 5 | -use Hurrytimer\Dependencies\Carbon\Carbon; | |
| 5 | +use Carbon\Carbon; | |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * The file that defines the core plugin class |
| 9 | 9 | * |
| @@ -63,25 +63,16 @@ | ||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public function run() |
| 66 | 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 | - | |
| 67 | + $this->loadDependencies(); | |
| 68 | + $this->setLocale(); | |
| 69 | + $this->maybeUpgrade(); | |
| 70 | + $this->registerPostType(); | |
| 71 | + $this->defineAdminHooks(); | |
| 72 | + $this->defineFrontHooks(); | |
| 77 | 73 | } |
| 78 | 74 | |
| 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 | 75 | /** |
| 85 | 76 | * Autoload the required dependencies for this plugin. |
| 86 | 77 | * |
| 87 | 78 | * @since 1.0.0 |
| @@ -86,34 +77,56 @@ | ||
| 86 | 77 | * |
| 87 | 78 | * @since 1.0.0 |
| 88 | 79 | * @access private |
| 89 | 80 | */ |
| 90 | - public function load_macros() | |
| 81 | + public function loadDependencies() | |
| 91 | 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 | + | |
| 92 | 94 | Carbon::macro( 'getBrowserTimestamp', function () { |
| 93 | - /** @var Carbon $this */ | |
| 95 | + /** | |
| 96 | + * @var Carbon $this | |
| 97 | + */ | |
| 94 | 98 | return $this->getTimestamp() * 1000; |
| 95 | 99 | } ); |
| 100 | + } | |
| 96 | 101 | |
| 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 | - } ); | |
| 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 | + { | |
| 113 | 110 | |
| 111 | + add_action( | |
| 112 | + 'plugins_loaded', | |
| 113 | + [ | |
| 114 | + new I18n(), | |
| 115 | + 'load_plugin_textdomain', | |
| 116 | + ] | |
| 117 | + ); | |
| 114 | 118 | } |
| 115 | 119 | |
| 120 | + private function maybeUpgrade() | |
| 121 | + { | |
| 122 | + add_action( | |
| 123 | + 'plugins_loaded', function () { | |
| 124 | + Upgrade::getInstance()->run(); | |
| 125 | + } | |
| 126 | + ); | |
| 127 | + } | |
| 128 | + | |
| 116 | 129 | /** |
| 117 | 130 | * Register all of the hooks related to the admin area functionality |
| 118 | 131 | * of the plugin. |
| 119 | 132 | * |
| @@ -119,9 +132,9 @@ | ||
| 119 | 132 | * |
| 120 | 133 | * @since 1.0.0 |
| 121 | 134 | * @access private |
| 122 | 135 | */ |
| 123 | - private function define_admin_hooks() | |
| 136 | + private function defineAdminHooks() | |
| 124 | 137 | { |
| 125 | 138 | $plugin_admin = new Admin( |
| 126 | 139 | $this->getPluginName(), |
| 127 | 140 | $this->getVersion() |
| @@ -142,41 +155,20 @@ | ||
| 142 | 155 | * |
| 143 | 156 | * @since 1.0.0 |
| 144 | 157 | * @access private |
| 145 | 158 | */ |
| 146 | - private function define_front_hooks() | |
| 159 | + private function defineFrontHooks() | |
| 147 | 160 | { |
| 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 | 161 | $front = new Frontend( |
| 160 | 162 | $this->getPluginName(), |
| 161 | 163 | $this->getVersion() |
| 162 | 164 | ); |
| 163 | 165 | |
| 164 | - $front->init(); | |
| 165 | - | |
| 166 | - | |
| 166 | + add_action( 'wp_enqueue_scripts', [ $front, 'enqueue_styles' ] ); | |
| 167 | + add_action( 'wp_enqueue_scripts', [ $front, 'enqueue_scripts' ] ); | |
| 167 | 168 | } |
| 168 | 169 | |
| 169 | 170 | /** |
| 170 | - * Register shortcode callback. | |
| 171 | - */ | |
| 172 | - function register_shortcode() | |
| 173 | - { | |
| 174 | - $shortcode = new CampaignShortcode(); | |
| 175 | - $shortcode->init(); | |
| 176 | - } | |
| 177 | - | |
| 178 | - /** | |
| 179 | 171 | * The name of the plugin used to uniquely identify it within the context of |
| 180 | 172 | * WordPress and to define internationalization functionality. |
| 181 | 173 | * |
| 182 | 174 | * @return string The name of the plugin. |
| @@ -197,30 +189,30 @@ | ||
| 197 | 189 | { |
| 198 | 190 | return $this->version; |
| 199 | 191 | } |
| 200 | 192 | |
| 201 | - public function register_post_type() | |
| 193 | + public function registerPostType() | |
| 202 | 194 | { |
| 203 | 195 | $args = array( |
| 204 | - 'label' => __( 'All', 'hurrytimer' ), | |
| 196 | + 'label' => __( 'All', DOMAIN ), | |
| 205 | 197 | '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' ), | |
| 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 ), | |
| 217 | 209 | 'not_found_in_trash' => __( |
| 218 | - 'No campaign found in trash', | |
| 219 | - 'hurrytimer' | |
| 210 | + 'No Countdown Timer found in trash', | |
| 211 | + DOMAIN | |
| 220 | 212 | ), |
| 221 | - 'parent' => __( 'Parent Campaign', 'hurrytimer' ), | |
| 222 | - 'menu_name' => __( 'All Campaigns', 'hurrytimer' ), | |
| 213 | + 'parent' => __( 'Parent Campaign', DOMAIN ), | |
| 214 | + 'menu_name' => __( 'All Campaigns', DOMAIN ), | |
| 223 | 215 | ), |
| 224 | 216 | 'public' => false, |
| 225 | 217 | 'show_ui' => true, |
| 226 | 218 | 'publicly_queryable' => false, |