custom-post-type-permalinks
Last commit date
CPTP
7 years ago
assets
8 years ago
language
8 years ago
CONTRIBUTING.md
9 years ago
CPTP.php
8 years ago
LICENSE
9 years ago
custom-post-type-permalinks.php
7 years ago
readme.md
8 years ago
readme.txt
7 years ago
screenshot-1.png
14 years ago
CPTP.php
137 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CPTP core. |
| 4 | * |
| 5 | * @package Custom_Post_Type_Permalinks |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * CPTP |
| 10 | * |
| 11 | * @since 0.9.4 |
| 12 | * */ |
| 13 | class CPTP { |
| 14 | |
| 15 | /** |
| 16 | * CPTP instance. |
| 17 | * |
| 18 | * @var CPTP |
| 19 | */ |
| 20 | private static $_instance; |
| 21 | |
| 22 | /** |
| 23 | * Module instances. |
| 24 | * |
| 25 | * @var CPTP_Module[] |
| 26 | */ |
| 27 | public $modules; |
| 28 | |
| 29 | /** |
| 30 | * CPTP constructor. |
| 31 | */ |
| 32 | private function __construct() { |
| 33 | $this->load_modules(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * |
| 38 | * Load CPTP_Modules. |
| 39 | * |
| 40 | * @since 0.9.5 |
| 41 | */ |
| 42 | private function load_modules() { |
| 43 | $this->set_module( 'setting', new CPTP_Module_Setting() ); |
| 44 | $this->set_module( 'rewrite', new CPTP_Module_Rewrite() ); |
| 45 | $this->set_module( 'admin', new CPTP_Module_Admin() ); |
| 46 | $this->set_module( 'option', new CPTP_Module_Option() ); |
| 47 | $this->set_module( 'permalink', new CPTP_Module_Permalink() ); |
| 48 | $this->set_module( 'get_archives', new CPTP_Module_GetArchives() ); |
| 49 | $this->set_module( 'flush_rules', new CPTP_Module_FlushRules() ); |
| 50 | |
| 51 | do_action( 'CPTP_load_modules', $this ); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Initialize modules. |
| 57 | * |
| 58 | * @since 2.0.0 |
| 59 | */ |
| 60 | private function init_modules() { |
| 61 | foreach ( $this->modules as $module ) { |
| 62 | $module->init(); |
| 63 | } |
| 64 | |
| 65 | do_action( 'CPTP_registered_modules', $this ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Set module instance. |
| 70 | * |
| 71 | * @since 1.5.0 |
| 72 | * |
| 73 | * @param String $name Module Name. |
| 74 | * @param CPTP_Module $module Module instance. |
| 75 | */ |
| 76 | public function set_module( $name, CPTP_Module $module ) { |
| 77 | |
| 78 | $this->modules[ $name ] = apply_filters( "CPTP_set_{$name}_module", $module ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Init |
| 83 | * |
| 84 | * Fire Module::add_hook |
| 85 | * |
| 86 | * @since 0.9.5 |
| 87 | */ |
| 88 | public function init() { |
| 89 | $this->init_modules(); |
| 90 | do_action( 'CPTP_init' ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Singleton |
| 95 | * |
| 96 | * @static |
| 97 | */ |
| 98 | public static function get_instance() { |
| 99 | |
| 100 | if ( ! isset( self::$_instance ) ) { |
| 101 | self::$_instance = new CPTP(); |
| 102 | } |
| 103 | |
| 104 | return self::$_instance; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /** |
| 109 | * Activation Hooks |
| 110 | * This function will browse initialized modules and execute their activation_hook methods. |
| 111 | * It will also set the uninstall_hook to the cptp_uninstall function which behaves the same way as this one. |
| 112 | * |
| 113 | * @since 2.0.0 |
| 114 | */ |
| 115 | public function activate() { |
| 116 | foreach ( $this->modules as $module ) { |
| 117 | $module->activation_hook(); |
| 118 | } |
| 119 | |
| 120 | register_uninstall_hook( CPTP_PLUGIN_FILE, array( __CLASS__, 'uninstall' ) ); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Uninstall Hooks |
| 125 | * This function will browse initialized modules and execute their uninstall_hook methods. |
| 126 | * |
| 127 | * @since 2.0.0 |
| 128 | */ |
| 129 | public static function uninstall() { |
| 130 | $cptp = CPTP::get_instance(); |
| 131 | |
| 132 | foreach ( $cptp->modules as $module ) { |
| 133 | $module->uninstall_hook(); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 |