-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.php
168 lines (125 loc) · 4.24 KB
/
loader.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/*
Plugin Name: MyFossil Documents
Plugin URI: https://github.com/myfossil/myfossil-documents
Description: Create and manage Documents
Version: 1.0
Author: MyFossil
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
if ( ! is_admin() ) {
include_once( dirname( __FILE__ ) . '/mf_documents_templates.php' );
include_once( dirname( __FILE__ ) . '/mf_documents_functions.php' );
}
function mf_documents_activation() {
mf_add_documents_caps();
mf_create_post_type_document();
mf_create_documents_page();
mf_create_misc_category();
flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'mf_documents_activation');
function mf_documents_deactivation () {
mf_remove_documents_caps();
}
register_deactivation_hook(__FILE__, 'mf_documents_deactivation');
function mf_documents_uninstall () {
return;
}
register_uninstall_hook( __FILE__, 'mf_documents_uninstall');
function mf_create_documents_page() {
$page = get_page_by_path('documents');
if( ! $page ){
$documents_page = array(
'post_title' => 'Documents',
'post_name' => 'documents',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'page'
);
$post_id = wp_insert_post( $documents_page, true );
}
}
function mf_create_misc_category() {
if( !term_exists('misc') ) {
wp_insert_term(
'Misc',
'category',
array(
'description' => 'Miscellaneous',
'slug' => 'misc'
)
);
}
}
function mf_document_set_default_category( $post_id, $post, $update ) {
$slug = 'myfossil_document';
if ( $slug != $post->post_type )
return;
$terms_list = wp_get_post_terms( $post_id, 'category', array("fields" => "name"));
//if( in_array('Uncategorized', $terms_list) )
if( empty( $terms_list ) )
wp_set_object_terms( $post_id, 'misc', 'category' );
}
//add_action( 'save_post', 'mf_document_set_default_category', 99, 3 );
function mf_create_post_type_document() {
register_post_type( 'myfossil_document',
array(
'labels' => array(
'name' => __( 'Documents' ),
'singular_name' => __( 'Document' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Document' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit Document' ),
'new_item' => __( 'New Document' ),
'view' => __( 'View Documents' ),
'view_item' => __( 'View Document' ),
'search_items' => __( 'Search Documents' ),
'not_found' => __( 'No Documents found' ),
'not_found_in_trash' => __( 'No Documents found in Trash' ),
),
'public' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'document' ),
'capability_type' => array('document', 'documents'),
'exclude_from_search' => false,
'has_archive' => true,
'map_meta_cap' => true,
'hierarchical' => false,
"supports" => array("title", "editor", "thumbnail", "author", "comments", "trackbacks"),
'taxonomies' => array('category'),
)
);
//register_taxonomy_for_object_type('category', 'document');
//$term_list = wp_get_post_terms(1910, 'category', array("fields" => "names"));
//var_dump( $term_list );
//if( in_array('Uncategorized', $term_list) ) echo '........in array';
//if( empty( $term_list) ) echo '........empty';
}
add_action( 'init', 'mf_create_post_type_document' );
function mf_add_documents_caps() {
$role = get_role( 'administrator' );
$role->add_cap( 'delete_published_documents' );
$role->add_cap( 'delete_others_documents' );
$role->add_cap( 'delete_documents' );
$role->add_cap( 'edit_others_documents' );
$role->add_cap( 'edit_published_documents' );
$role->add_cap( 'edit_documents' );
$role->add_cap( 'publish_documents' );
}
function mf_remove_documents_caps() {
global $wp_roles;
$all_roles = $wp_roles->roles;
foreach( $all_roles as $key => $value ){
$role = get_role( $key );
$role->remove_cap( 'delete_published_documents' );
$role->remove_cap( 'delete_others_documents' );
$role->remove_cap( 'delete_documents' );
$role->remove_cap( 'edit_others_documents' );
$role->remove_cap( 'edit_published_documents' );
$role->remove_cap( 'edit_documents' );
$role->remove_cap( 'publish_documents' );
}
}