| 1 |
<?php |
| 2 |
/** |
| 3 |
* The file that defines the core plugin class |
| 4 |
* |
| 5 |
* A class definition that includes attributes and functions used across both the |
| 6 |
* public-facing side of the site and the admin area. |
| 7 |
* |
| 8 |
* @link https://profiles.wordpress.org/pattihis/ |
| 9 |
* @since 1.0.0 |
| 10 |
* |
| 11 |
* @package Simple_Cpt |
| 12 |
* @subpackage Simple_Cpt/includes |
| 13 |
*/ |
| 14 |
|
| 15 |
/** |
| 16 |
* The core plugin class. |
| 17 |
* |
| 18 |
* This is used to define internationalization, admin-specific hooks, and |
| 19 |
* public-facing site hooks. |
| 20 |
* |
| 21 |
* Also maintains the unique identifier of this plugin as well as the current |
| 22 |
* version of the plugin. |
| 23 |
* |
| 24 |
* @since 1.0.0 |
| 25 |
* @package Simple_Cpt |
| 26 |
* @subpackage Simple_Cpt/includes |
| 27 |
* @author George Pattichis <gpattihis@gmail.com> |
| 28 |
*/ |
| 29 |
class Simple_Cpt { |
| 30 |
|
| 31 |
/** |
| 32 |
* The loader that's responsible for maintaining and registering all hooks that power |
| 33 |
* the plugin. |
| 34 |
* |
| 35 |
* @since 1.0.0 |
| 36 |
* @access protected |
| 37 |
* @var Simple_Cpt_Loader $loader Maintains and registers all hooks for the plugin. |
| 38 |
*/ |
| 39 |
protected $loader; |
| 40 |
|
| 41 |
/** |
| 42 |
* The unique identifier of this plugin. |
| 43 |
* |
| 44 |
* @since 1.0.0 |
| 45 |
* @access protected |
| 46 |
* @var string $plugin_name The string used to uniquely identify this plugin. |
| 47 |
*/ |
| 48 |
protected $plugin_name; |
| 49 |
|
| 50 |
/** |
| 51 |
* The current version of the plugin. |
| 52 |
* |
| 53 |
* @since 1.0.0 |
| 54 |
* @access protected |
| 55 |
* @var string $version The current version of the plugin. |
| 56 |
*/ |
| 57 |
protected $version; |
| 58 |
|
| 59 |
/** |
| 60 |
* Define the core functionality of the plugin. |
| 61 |
* |
| 62 |
* Set the plugin name and the plugin version that can be used throughout the plugin. |
| 63 |
* Load the dependencies, define the locale, and set the hooks for the admin area and |
| 64 |
* the public-facing side of the site. |
| 65 |
* |
| 66 |
* @since 1.0.0 |
| 67 |
*/ |
| 68 |
public function __construct() { |
| 69 |
if ( defined( 'SIMPLE_CPT_VERSION' ) ) { |
| 70 |
$this->version = SIMPLE_CPT_VERSION; |
| 71 |
} else { |
| 72 |
$this->version = '1.1.1'; |
| 73 |
} |
| 74 |
$this->plugin_name = 'simple-cpt'; |
| 75 |
|
| 76 |
$this->load_dependencies(); |
| 77 |
$this->set_locale(); |
| 78 |
$this->define_admin_hooks(); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Load the required dependencies for this plugin. |
| 83 |
* |
| 84 |
* Include the following files that make up the plugin: |
| 85 |
* |
| 86 |
* - Simple_Cpt_Loader. Orchestrates the hooks of the plugin. |
| 87 |
* - Simple_Cpt_i18n. Defines internationalization functionality. |
| 88 |
* - Simple_Cpt_Admin. Defines all hooks for the admin area. |
| 89 |
* |
| 90 |
* Create an instance of the loader which will be used to register the hooks |
| 91 |
* with WordPress. |
| 92 |
* |
| 93 |
* @since 1.0.0 |
| 94 |
* @access private |
| 95 |
*/ |
| 96 |
private function load_dependencies() { |
| 97 |
|
| 98 |
/** |
| 99 |
* The class responsible for orchestrating the actions and filters of the |
| 100 |
* core plugin. |
| 101 |
*/ |
| 102 |
require_once plugin_dir_path( __DIR__ ) . 'includes/class-simple-cpt-loader.php'; |
| 103 |
|
| 104 |
/** |
| 105 |
* The class responsible for defining internationalization functionality |
| 106 |
* of the plugin. |
| 107 |
*/ |
| 108 |
require_once plugin_dir_path( __DIR__ ) . 'includes/class-simple-cpt-i18n.php'; |
| 109 |
|
| 110 |
/** |
| 111 |
* The class responsible for defining all actions that occur in the admin area. |
| 112 |
*/ |
| 113 |
require_once plugin_dir_path( __DIR__ ) . 'admin/class-simple-cpt-admin.php'; |
| 114 |
|
| 115 |
$this->loader = new Simple_Cpt_Loader(); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Define the locale for this plugin for internationalization. |
| 120 |
* |
| 121 |
* Uses the Simple_Cpt_i18n class in order to set the domain and to register the hook |
| 122 |
* with WordPress. |
| 123 |
* |
| 124 |
* @since 1.0.0 |
| 125 |
* @access private |
| 126 |
*/ |
| 127 |
private function set_locale() { |
| 128 |
|
| 129 |
$plugin_i18n = new Simple_Cpt_i18n(); |
| 130 |
|
| 131 |
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Register all of the hooks related to the admin area functionality |
| 136 |
* of the plugin. |
| 137 |
* |
| 138 |
* @since 1.0.0 |
| 139 |
* @access private |
| 140 |
*/ |
| 141 |
private function define_admin_hooks() { |
| 142 |
|
| 143 |
$plugin_admin = new Simple_Cpt_Admin( $this->get_plugin_name(), $this->get_version() ); |
| 144 |
|
| 145 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 146 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 147 |
|
| 148 |
// initialise. |
| 149 |
$this->loader->add_action( 'init', $plugin_admin, 'plugin_init' ); |
| 150 |
$this->loader->add_action( 'init', $plugin_admin, 'register_simple_cpts' ); |
| 151 |
|
| 152 |
// admin setup. |
| 153 |
$this->loader->add_action( 'admin_init', $plugin_admin, 'simple_cpt_settings_flush_rewrite' ); |
| 154 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'simple_cpt_admin_menu' ); |
| 155 |
$this->loader->add_filter( 'plugin_action_links', $plugin_admin, 'simple_cpt_plugin_links', 10, 2 ); |
| 156 |
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'simple_cpt_metabox' ); |
| 157 |
$this->loader->add_action( 'save_post', $plugin_admin, 'simple_cpt_save_metabox' ); |
| 158 |
$this->loader->add_filter( 'post_updated_messages', $plugin_admin, 'simple_cpt_update_messages' ); |
| 159 |
$this->loader->add_action( 'admin_footer', $plugin_admin, 'simple_cpt_admin_footer' ); |
| 160 |
|
| 161 |
// table columns. |
| 162 |
$this->loader->add_filter( 'manage_simple_cpt_posts_columns', $plugin_admin, 'simple_cpt_posts_columns' ); |
| 163 |
$this->loader->add_action( 'manage_simple_cpt_posts_custom_column', $plugin_admin, 'simple_cpt_posts_custom_columns', 10, 2 ); |
| 164 |
$this->loader->add_filter( 'manage_simple_tax_posts_columns', $plugin_admin, 'simple_tax_posts_columns' ); |
| 165 |
$this->loader->add_action( 'manage_simple_tax_posts_custom_column', $plugin_admin, 'simple_tax_posts_custom_columns', 10, 2 ); |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Run the loader to execute all of the hooks with WordPress. |
| 170 |
* |
| 171 |
* @since 1.0.0 |
| 172 |
*/ |
| 173 |
public function run() { |
| 174 |
$this->loader->run(); |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* The name of the plugin used to uniquely identify it within the context of |
| 179 |
* WordPress and to define internationalization functionality. |
| 180 |
* |
| 181 |
* @since 1.0.0 |
| 182 |
* @return string The name of the plugin. |
| 183 |
*/ |
| 184 |
public function get_plugin_name() { |
| 185 |
return $this->plugin_name; |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 190 |
* |
| 191 |
* @since 1.0.0 |
| 192 |
* @return Simple_Cpt_Loader Orchestrates the hooks of the plugin. |
| 193 |
*/ |
| 194 |
public function get_loader() { |
| 195 |
return $this->loader; |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Retrieve the version number of the plugin. |
| 200 |
* |
| 201 |
* @since 1.0.0 |
| 202 |
* @return string The version number of the plugin. |
| 203 |
*/ |
| 204 |
public function get_version() { |
| 205 |
return $this->version; |
| 206 |
} |
| 207 |
} |
| 208 |
|