-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-cjd-services-install.php
58 lines (49 loc) · 1.38 KB
/
class-cjd-services-install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Run on plugin install.
*
* @package CDJ_Services
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* CJD_Services_Install Class
*/
class CJD_Services_Install {
/**
* Constructor
*/
public function __construct() {
register_activation_hook( CJD_SERVICES_PLUGIN_FILE, array( $this, 'register_defaults' ) );
register_deactivation_hook( CJD_SERVICES_PLUGIN_FILE, array( $this, 'deactivate_services' ) );
}
/**
* Register plugin defaults.
*/
public function register_defaults() {
if ( is_admin() ) {
if ( ! get_option( 'cjd_services_date_installed' ) ) {
add_option( 'cjd_services_date_installed', gmdate( 'Y-m-d h:i:s' ) );
}
}
}
/**
* Remove post types and taxonomies from memory
*/
public function deactivate_services() {
unregister_taxonomy_from_object_type( 'service-category', 'services' );
// Unregister the post type, so the rules are no longer in memory.
unregister_post_type( 'services' );
// If taxonomy no longer has any post types associated with it,
// remove from memory as well
$taxonomy = get_taxonomy( 'service-category' );
if ( !$taxonomy->object_type ) {
unregister_taxonomy( 'service-category' );
}
// Clear the permalinks to remove our post type's rules from the database.
flush_rewrite_rules();
}
}
return new CJD_Services_Install();