| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Novelist |
| 4 |
* Plugin URI: https://novelistplugin.com |
| 5 |
* Description: Easily organize and display your portfolio of books |
| 6 |
* Version: 1.4.0 |
| 7 |
* Author: Nose Graze |
| 8 |
* Author URI: https://www.nosegraze.com |
| 9 |
* License: GPL2 |
| 10 |
* Text Domain: novelist |
| 11 |
* Domain Path: languages |
| 12 |
* Requires at least: 5.0 |
| 13 |
* Requires PHP: 8.0 |
| 14 |
* |
| 15 |
* Novelist is free software: you can redistribute it and/or modify |
| 16 |
* it under the terms of the GNU General Public License as published by |
| 17 |
* the Free Software Foundation, either version 2 of the License, or |
| 18 |
* any later version. |
| 19 |
* |
| 20 |
* Novelist is distributed in the hope that it will be useful, |
| 21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
* GNU General Public License for more details. |
| 24 |
* |
| 25 |
* You should have received a copy of the GNU General Public License |
| 26 |
* along with Novelist. If not, see <http://www.gnu.org/licenses/>. |
| 27 |
* |
| 28 |
* Thanks to Easy Digital Downloads for serving as a great code base |
| 29 |
* and resource, which a lot of Novelist's structure is based on. |
| 30 |
* Easy Digital Downloads is made by Pippin Williamson and licensed |
| 31 |
* under GPL2+. |
| 32 |
* |
| 33 |
* @package novelist |
| 34 |
* @copyright Copyright (c) 2026 Nose Graze Ltd |
| 35 |
* @license GPL2+ |
| 36 |
*/ |
| 37 |
|
| 38 |
// Exit if accessed directly |
| 39 |
if (! defined('ABSPATH')) { |
| 40 |
exit; |
| 41 |
} |
| 42 |
|
| 43 |
if (version_compare(PHP_VERSION, '7.4', '<')) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
require __DIR__.'/vendor/autoload.php'; |
| 48 |
|
| 49 |
if (! class_exists('Novelist')) : |
| 50 |
|
| 51 |
class Novelist |
| 52 |
{ |
| 53 |
private \Novelist\Container\Container $container; |
| 54 |
|
| 55 |
private static Novelist $instance; |
| 56 |
|
| 57 |
/** |
| 58 |
* Service providers to boot. |
| 59 |
* |
| 60 |
* @see Novelist::boot() |
| 61 |
* @see Novelist::loadServiceProviders() |
| 62 |
* |
| 63 |
* @var string[] |
| 64 |
*/ |
| 65 |
private array $serviceProviders = [ |
| 66 |
\Novelist\ServiceProviders\CsvImportServiceProvider::class, |
| 67 |
]; |
| 68 |
|
| 69 |
private bool $serviceProvidersLoaded = false; |
| 70 |
|
| 71 |
/** |
| 72 |
* Novelist_Roles object |
| 73 |
* |
| 74 |
* @var Novelist_Roles |
| 75 |
* @since 1.0.0 |
| 76 |
*/ |
| 77 |
public Novelist_Roles $roles; |
| 78 |
|
| 79 |
/** |
| 80 |
* HTML elements helper class. |
| 81 |
* |
| 82 |
* @var Novelist_HTML |
| 83 |
* @since 1.1.0 |
| 84 |
*/ |
| 85 |
public Novelist_HTML $html; |
| 86 |
|
| 87 |
public function __construct() |
| 88 |
{ |
| 89 |
$this->container = new \Novelist\Container\Container(); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Initializes the plugin. |
| 94 |
* |
| 95 |
* @since 2.0 |
| 96 |
*/ |
| 97 |
public function boot() |
| 98 |
{ |
| 99 |
$this->setup_constants(); |
| 100 |
$this->loadServiceProviders(); |
| 101 |
|
| 102 |
add_action('plugins_loaded', [$this, 'load_textdomain']); |
| 103 |
|
| 104 |
$this->includes(); |
| 105 |
$this->roles = new Novelist_Roles(); |
| 106 |
$this->html = new Novelist_HTML(); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Novelist instance. |
| 111 |
* |
| 112 |
* Insures that only one instance of Novelist exists at any one time. |
| 113 |
* |
| 114 |
* @uses Novelist::setup_constants() Set up the plugin constants. |
| 115 |
* @uses Novelist::includes() Include any required files. |
| 116 |
* @uses Novelist::load_textdomain() Load the language files. |
| 117 |
* |
| 118 |
* @access public |
| 119 |
* @since 1.0.0 |
| 120 |
* @return Novelist Instance of Novelist class |
| 121 |
*/ |
| 122 |
public static function instance() : Novelist |
| 123 |
{ |
| 124 |
if (! isset(static::$instance) || ! static::$instance instanceof Novelist) { |
| 125 |
static::$instance = new static(); |
| 126 |
} |
| 127 |
|
| 128 |
return static::$instance; |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Gets the container |
| 133 |
* |
| 134 |
* @since 2.0 |
| 135 |
* |
| 136 |
* @return \Novelist\Container\Container |
| 137 |
*/ |
| 138 |
public function container() : \Novelist\Container\Container |
| 139 |
{ |
| 140 |
return $this->container; |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Throw error on object clone. |
| 145 |
* |
| 146 |
* The whole idea of the singleton design pattern is that there is a single |
| 147 |
* object therefore, we don't want the object to be cloned. |
| 148 |
* |
| 149 |
* @access protected |
| 150 |
* @since 1.0.0 |
| 151 |
* @return void |
| 152 |
*/ |
| 153 |
public function __clone() |
| 154 |
{ |
| 155 |
// Cloning instances of the class is forbidden. |
| 156 |
_doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'novelist'), '1.0.0'); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Disable unserializing of the class. |
| 161 |
* |
| 162 |
* @access protected |
| 163 |
* @since 1.0.0 |
| 164 |
* @return void |
| 165 |
*/ |
| 166 |
public function __wakeup() |
| 167 |
{ |
| 168 |
// Unserializing instances of the class is forbidden. |
| 169 |
_doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'novelist'), '1.0.0'); |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* Setup plugin constants. |
| 174 |
* |
| 175 |
* @access private |
| 176 |
* @since 1.0.0 |
| 177 |
* @return void |
| 178 |
*/ |
| 179 |
private function setup_constants() |
| 180 |
{ |
| 181 |
// Plugin version. |
| 182 |
if (! defined('NOVELIST_VERSION')) { |
| 183 |
define('NOVELIST_VERSION', '1.4.0'); |
| 184 |
} |
| 185 |
|
| 186 |
// Plugin Folder Path. |
| 187 |
if (! defined('NOVELIST_PLUGIN_DIR')) { |
| 188 |
define('NOVELIST_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
| 189 |
} |
| 190 |
|
| 191 |
// Plugin Folder URL. |
| 192 |
if (! defined('NOVELIST_PLUGIN_URL')) { |
| 193 |
define('NOVELIST_PLUGIN_URL', plugin_dir_url(__FILE__)); |
| 194 |
} |
| 195 |
|
| 196 |
// Plugin Root File. |
| 197 |
if (! defined('NOVELIST_PLUGIN_FILE')) { |
| 198 |
define('NOVELIST_PLUGIN_FILE', __FILE__); |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Registers and boots all service providers. |
| 204 |
* |
| 205 |
* @since 2.0 |
| 206 |
*/ |
| 207 |
private function loadServiceProviders() |
| 208 |
{ |
| 209 |
if ($this->serviceProvidersLoaded) { |
| 210 |
return; |
| 211 |
} |
| 212 |
|
| 213 |
$providers = []; |
| 214 |
foreach ($this->serviceProviders as $serviceProvider) { |
| 215 |
if (! is_subclass_of($serviceProvider, \Novelist\ServiceProviders\ServiceProvider::class)) { |
| 216 |
throw new \InvalidArgumentException(sprintf( |
| 217 |
'%s class must implement the ServiceProvider interface.', |
| 218 |
$serviceProvider |
| 219 |
)); |
| 220 |
} |
| 221 |
|
| 222 |
/** @var \Novelist\ServiceProviders\ServiceProvider $serviceProvider */ |
| 223 |
$serviceProvider = new $serviceProvider($this->container); |
| 224 |
$serviceProvider->register(); |
| 225 |
$providers[] = $serviceProvider; |
| 226 |
} |
| 227 |
|
| 228 |
foreach ($providers as $serviceProvider) { |
| 229 |
$serviceProvider->boot(); |
| 230 |
} |
| 231 |
|
| 232 |
$this->serviceProvidersLoaded = true; |
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* Include Required Files |
| 237 |
* |
| 238 |
* @access private |
| 239 |
* @since 1.0.0 |
| 240 |
* @return void |
| 241 |
*/ |
| 242 |
private function includes() |
| 243 |
{ |
| 244 |
|
| 245 |
global $novelist_options; |
| 246 |
|
| 247 |
// Settings. |
| 248 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/settings/register-settings.php'; |
| 249 |
if (empty($novelist_options)) { |
| 250 |
$novelist_options = novelist_get_settings(); |
| 251 |
} |
| 252 |
|
| 253 |
require_once NOVELIST_PLUGIN_DIR.'includes/class-novelist-html.php'; |
| 254 |
require_once NOVELIST_PLUGIN_DIR.'includes/class-novelist-roles.php'; |
| 255 |
require_once NOVELIST_PLUGIN_DIR.'includes/post-types.php'; |
| 256 |
require_once NOVELIST_PLUGIN_DIR.'includes/class-novelist-book.php'; |
| 257 |
require_once NOVELIST_PLUGIN_DIR.'includes/class-novelist-shortcodes.php'; |
| 258 |
require_once NOVELIST_PLUGIN_DIR.'includes/book-functions.php'; |
| 259 |
require_once NOVELIST_PLUGIN_DIR.'includes/book-filters.php'; |
| 260 |
require_once NOVELIST_PLUGIN_DIR.'includes/load-assets.php'; |
| 261 |
require_once NOVELIST_PLUGIN_DIR.'includes/misc-functions.php'; |
| 262 |
require_once NOVELIST_PLUGIN_DIR.'includes/template-functions.php'; |
| 263 |
require_once NOVELIST_PLUGIN_DIR.'includes/widgets/widget-book.php'; |
| 264 |
require_once NOVELIST_PLUGIN_DIR.'includes/widgets/widget-books-by-series.php'; |
| 265 |
require_once NOVELIST_PLUGIN_DIR.'includes/widgets/widget-word-count.php'; |
| 266 |
|
| 267 |
if (is_admin()) { |
| 268 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/admin-actions.php'; |
| 269 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/extensions.php'; |
| 270 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/thickbox.php'; |
| 271 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/tools.php'; |
| 272 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/admin-pages.php'; |
| 273 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/class-novelist-notices.php'; |
| 274 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/class-welcome.php'; |
| 275 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/settings/display-settings.php'; |
| 276 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/books/meta-box.php'; |
| 277 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/books/sanitize-meta-fields.php'; |
| 278 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/books/dashboard-columns.php'; |
| 279 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/books/demo-book.php'; |
| 280 |
require_once NOVELIST_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php'; |
| 281 |
} |
| 282 |
|
| 283 |
require_once NOVELIST_PLUGIN_DIR.'includes/install.php'; |
| 284 |
|
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* Loads the plugin language files. |
| 289 |
* |
| 290 |
* @access public |
| 291 |
* @since 1.0.0 |
| 292 |
* @return void |
| 293 |
*/ |
| 294 |
public function load_textdomain() |
| 295 |
{ |
| 296 |
$lang_dir = dirname(plugin_basename(NOVELIST_PLUGIN_FILE)).'/languages/'; |
| 297 |
$lang_dir = apply_filters('novelist/languages-directory', $lang_dir); |
| 298 |
load_plugin_textdomain('novelist', false, $lang_dir); |
| 299 |
} |
| 300 |
|
| 301 |
} |
| 302 |
|
| 303 |
endif; // End class exists check. |
| 304 |
|
| 305 |
/** |
| 306 |
* Get Novelist up and running. |
| 307 |
* |
| 308 |
* This function returns an instance of the Novelist class. |
| 309 |
* |
| 310 |
* @since 1.0.0 |
| 311 |
* @return Novelist |
| 312 |
*/ |
| 313 |
function Novelist() |
| 314 |
{ |
| 315 |
return Novelist::instance(); |
| 316 |
} |
| 317 |
|
| 318 |
Novelist()->boot(); |
| 319 |
|