| 1 |
<?php |
| 2 |
/** |
| 3 |
* Booktics Main Class |
| 4 |
* |
| 5 |
* @package Booktics/Booktics |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Booktics; |
| 9 |
|
| 10 |
use Booktics\Container\Container; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class Booktics |
| 14 |
*/ |
| 15 |
class Booktics { |
| 16 |
|
| 17 |
/** |
| 18 |
* Plugin version. |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
public $version; |
| 23 |
|
| 24 |
/** |
| 25 |
* Plugin file. |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
public $plugin_file; |
| 30 |
|
| 31 |
/** |
| 32 |
* Plugin directory. |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
public $plugin_directory; |
| 37 |
|
| 38 |
/** |
| 39 |
* @var string |
| 40 |
*/ |
| 41 |
public $build_url; |
| 42 |
|
| 43 |
/** |
| 44 |
* Plugin base name. |
| 45 |
* |
| 46 |
* @var string |
| 47 |
*/ |
| 48 |
public $basename; |
| 49 |
|
| 50 |
/** |
| 51 |
* Plugin text directory path. |
| 52 |
* |
| 53 |
* @var string |
| 54 |
*/ |
| 55 |
public $text_domain_directory; |
| 56 |
|
| 57 |
/** |
| 58 |
* Plugin text directory path. |
| 59 |
* |
| 60 |
* @var string |
| 61 |
*/ |
| 62 |
public $template_directory; |
| 63 |
|
| 64 |
/** |
| 65 |
* Plugin assets directory path. |
| 66 |
* |
| 67 |
* @var string |
| 68 |
*/ |
| 69 |
public $assets_url; |
| 70 |
|
| 71 |
/** |
| 72 |
* Plugin url. |
| 73 |
* |
| 74 |
* @var string |
| 75 |
*/ |
| 76 |
public $plugin_url; |
| 77 |
|
| 78 |
/** |
| 79 |
* Container that holds all the services. |
| 80 |
* |
| 81 |
* @var Container |
| 82 |
*/ |
| 83 |
public $container; |
| 84 |
|
| 85 |
/** |
| 86 |
* Booktics Constructor. |
| 87 |
*/ |
| 88 |
public function __construct() { |
| 89 |
$this->init(); |
| 90 |
add_action( 'init', array( $this, 'init_classes' ) ); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Initialize the plugin. |
| 95 |
* |
| 96 |
* @return void |
| 97 |
*/ |
| 98 |
protected function init(): void { |
| 99 |
$this->version = '1.0.1'; |
| 100 |
$this->plugin_file = BOOKTICS_FILE; |
| 101 |
$this->plugin_directory = BOOKTICS_DIR; |
| 102 |
$this->basename = plugin_basename( $this->plugin_file ); |
| 103 |
$this->text_domain_directory = $this->plugin_directory . '/languages'; |
| 104 |
$this->template_directory = $this->plugin_directory . '/templates'; |
| 105 |
$this->plugin_url = plugins_url( '', $this->plugin_file ); |
| 106 |
$this->assets_url = $this->plugin_url . '/assets'; |
| 107 |
$this->build_url = $this->plugin_url . '/build'; |
| 108 |
register_activation_hook( |
| 109 |
$this->plugin_file, array( |
| 110 |
$this, |
| 111 |
'activate', |
| 112 |
) |
| 113 |
); |
| 114 |
register_deactivation_hook( |
| 115 |
$this->plugin_file, array( |
| 116 |
$this, |
| 117 |
'deactivate', |
| 118 |
) |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Init classes |
| 124 |
* |
| 125 |
* @return void |
| 126 |
*/ |
| 127 |
public function init_classes() { |
| 128 |
if ( ! session_id() ) { |
| 129 |
session_start(); |
| 130 |
} |
| 131 |
$service_provider = $this->get_container()->get( 'global' ); |
| 132 |
|
| 133 |
// Initilize Plugin Banner Notice. |
| 134 |
Plugin_Notice::run(); |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Get container |
| 139 |
* |
| 140 |
* @return Container |
| 141 |
*/ |
| 142 |
public function get_container() { |
| 143 |
return booktics_container(); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Initializes the Booktics class. |
| 148 |
* |
| 149 |
* Checks for an existing WeMeal instance |
| 150 |
* and if it doesn't find one, creates it. |
| 151 |
* |
| 152 |
* @return Booktics |
| 153 |
*/ |
| 154 |
public static function instance(): Booktics { |
| 155 |
static $instance = false; |
| 156 |
|
| 157 |
if ( ! $instance ) { |
| 158 |
$instance = new self(); |
| 159 |
} |
| 160 |
|
| 161 |
return $instance; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Trigger plugin activation class |
| 166 |
* |
| 167 |
* @return void |
| 168 |
*/ |
| 169 |
public function activate() { |
| 170 |
Activate::handle(); |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Trigger plugin deactivation |
| 175 |
* |
| 176 |
* @return void |
| 177 |
*/ |
| 178 |
public function deactivate() { |
| 179 |
Deactivate::handle(); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* returns assets url |
| 184 |
* |
| 185 |
* @return string |
| 186 |
*/ |
| 187 |
public static function assets_url(): string { |
| 188 |
return trailingslashit( plugins_url( '', BOOKTICS_FILE ) . '/assets' ); |
| 189 |
} |
| 190 |
} |
| 191 |
|