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