-
Notifications
You must be signed in to change notification settings - Fork 2
/
activation-hook.php
105 lines (85 loc) · 2.19 KB
/
activation-hook.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
class H_ActivationHook {
/**
* Run when the plugin is activated
*/
function on_activation() {
$options = get_option('h_options');
// create empty option if doesn't exist
if (!$options) {
add_option('h_options', []);
}
// If first time activation
if (!isset($options['init'])) {
$this->_create_frontpage();
$this->_create_blogpage();
$this->_set_default_setting();
$options['init'] = true;
}
update_option('h_options', $options);
}
/**
* Run when the plugin is deactivated
*/
function deactivation_hook() {
}
/////
/**
* Create default Frontpage
*/
private function _create_frontpage() {
$frontpage_id = get_option('page_on_front');
// if already exists, just change the title
if ($frontpage_id) {
$args = [
'ID' => $frontpage_id,
'post_title' => get_bloginfo()
];
wp_update_post($args);
}
// if does not exists, create it
else {
$home = [
'post_title' => get_bloginfo(),
'post_type' => 'page',
'post_status' => 'publish',
];
$home_id = wp_insert_post($home);
update_option('show_on_front', 'page');
update_option('page_on_front', $home_id);
}
}
/**
* Create default Blog page
*/
private function _create_blogpage() {
$blogpage_id = get_option('page_for_posts');
// If does not exists, create one
if (!$blogpage_id) {
$blog = [
'post_title' => 'Blog',
'post_type' => 'page',
'post_status' => 'publish',
];
$blog_id = wp_insert_post($blog);
update_option('page_for_posts', $blog_id);
}
}
/**
* Default setting for Standard website
*/
private function _set_default_setting() {
// general
update_option('use_smiles', 0);
// discussion
update_option('default_comment_status', 'closed');
update_option('thread_comments_depth', 2);
// media
update_option('medium_size_w', 480);
update_option('medium_size_h', 480);
update_option('large_size_w', 1120);
update_option('large_size_h', 800);
update_option('medium_large_size_w', 0);
update_option('medium_large_size_h', 0);
}
}