forked from maximeschoeni/sublanguage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivation.php
108 lines (79 loc) · 2.67 KB
/
activation.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
106
<?php
/**
* @from 1.5.1
*/
class Sublanguage_Activation {
/**
* @from 1.1
* @from 1.5.1 Moved in Sublanguage_Activation
* @from 2.5 bug fix: replace cpt by post_type
*/
public static function activate() {
global $sublanguage_admin;
// initialization
$options = get_option($sublanguage_admin->option_name);
$languages = $sublanguage_admin->get_languages();
if (empty($options)) {
$post_id = 0;
if (empty($languages)) {
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
$translations = wp_get_available_translations();
$locale = get_locale();
$language_name = isset($translations[$locale]['native_name']) ? $translations[$locale]['native_name'] : 'English';
$language_slug = (isset($translations[$locale]['iso']) && !empty($translations[$locale]['iso'])) ? array_shift($translations[$locale]['iso']) : 'en';
$post_id = wp_insert_post(array(
'post_type' => $sublanguage_admin->language_post_type,
'post_title' => $language_name,
'post_name' => $language_slug,
'post_status' => 'publish',
'post_content' => $locale
));
}
$options = array(
'main' => $post_id,
'default' => $post_id,
'show_slug' => false,
'autodetect' => false,
'current_first' => false,
'taxonomy' => array(
'category' => array('translatable' => true)
),
'post_type' => array(
'post' => array('translatable' => true),
'page' => array('translatable' => true)
),
'frontend_ajax' => false,
'need_flush' => 1,
'version' => $sublanguage_admin->version
);
update_option($sublanguage_admin->option_name, $options);
}
$admins = get_role( 'administrator' );
$admins->add_cap( 'edit_language' );
$admins->add_cap( 'edit_languages' );
$admins->add_cap( 'edit_other_languages' );
$admins->add_cap( 'publish_languages' );
$admins->add_cap( 'read_language' );
$admins->add_cap( 'read_private_languages' );
$admins->add_cap( 'delete_language' );
}
/**
* @from 1.5.1 Moved in Sublanguage_Activation
* @from 1.1
*/
public static function desactivate() {
global $sublanguage_admin;
$languages = $sublanguage_admin->get_languages();
if (count($languages) < 1) {
delete_option($sublanguage_admin->option_name);
}
$admins = get_role( 'administrator' );
$admins->remove_cap( 'edit_language' );
$admins->remove_cap( 'edit_languages' );
$admins->remove_cap( 'edit_other_languages' );
$admins->remove_cap( 'publish_languages' );
$admins->remove_cap( 'read_language' );
$admins->remove_cap( 'read_private_languages' );
$admins->remove_cap( 'delete_language' );
}
}