-
Notifications
You must be signed in to change notification settings - Fork 0
/
wz-distributor-postype.php
234 lines (228 loc) · 7.6 KB
/
wz-distributor-postype.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
// Add Post Type: Distributors.
add_action( 'init', 'cptui_register_my_cpts' );
function cptui_register_my_cpts() {
$labels = array(
"name" => __( "Distributors", 'wz-distributor'),
"singular_name" => __( "Distributor", 'wz-distributor'),
"menu_name" => __( "Distributor", 'wz-distributor'),
"all_items" => __( "All Distributors", 'wz-distributor'),
"add_new" => __( "Add Distributor", 'wz-distributor'),
"add_new_item" => __( "Add New Distributor", 'wz-distributor'),
"edit_item" => __( "Edit", 'wz-distributor'),
"new_item" => __( "New Distributor", 'wz-distributor'),
"view_item" => __( "View", 'wz-distributor'),
"view_items" => __( "View", 'wz-distributor'),
"search_items" => __( "Search Distributors", 'wz-distributor'),
"not_found" => __( "No Distributor found", 'wz-distributor'),
"not_found_in_trash" => __( "No Distributor found in trash", 'wz-distributor'),
"featured_image" => __( "Featured image for Distributor", 'wz-distributor'),
"set_featured_image" => __( "Set featured image for Distributor", 'wz-distributor'),
"remove_featured_image" => __( "Remove featured image for Distributor", 'wz-distributor'),
"use_featured_image" => __( "Use featured image for Distributor", 'wz-distributor'),
"archives" => __( "Distributor archives", 'wz-distributor'),
"insert_into_item" => __( "Insert into Distributor", 'wz-distributor'),
"uploaded_to_this_item" => __( "Uploaded to Distributor", 'wz-distributor'),
"filter_items_list" => __( "Filter Distributor list", 'wz-distributor'),
"items_list_navigation" => __( "Distributor list navigation", 'wz-distributor'),
"items_list" => __( "Distributor list", 'wz-distributor'),
"attributes" => __( "Distributor Attributes", 'wz-distributor'),
);
$args = array(
"label" => __( "Distributors", 'wz-distributor'),
"labels" => $labels,
"description" => __("Create list Distributor contact page for wordpress.", 'wz-distributor'),
"public" => true,
"publicly_queryable" => false,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => true,
"rewrite" => array( "slug" => "wz_distributor", "with_front" => true ),
"query_var" => true,
"menu_position" => 26,
"menu_icon" => "dashicons-businessman",
"supports" => array( "title", "thumbnail" ),
);
register_post_type( "wz_distributor", $args );
}
/* Add Taxonomy: Role for Distributor */
add_action( 'init', 'cptui_register_my_taxes' );
function cptui_register_my_taxes() {
$labels = array(
"name" => __( "Role", 'wz-distributor'),
"singular_name" => __( "Role", 'wz-distributor'),
"menu_name" => __( "Role", 'wz-distributor'),
"all_items" => __( "All Role", 'wz-distributor'),
"edit_item" => __( "Edit Role", 'wz-distributor'),
"view_item" => __( "View Role", 'wz-distributor'),
"update_item" => __( "Update Role", 'wz-distributor'),
"add_new_item" => __( "Add New Role", 'wz-distributor'),
"new_item_name" => __( "New Role", 'wz-distributor'),
"parent_item" => __( "Parent Role", 'wz-distributor'),
"parent_item_colon" => __( "Parent Role", 'wz-distributor'),
"search_items" => __( "Search Role", 'wz-distributor'),
"popular_items" => __( "Popular Role", 'wz-distributor'),
"add_or_remove_items" => __( "Add or Remove Role", 'wz-distributor'),
"not_found" => __( "No role found", 'wz-distributor'),
"no_terms" => __( "No role", 'wz-distributor'),
"items_list_navigation" => __( "Role list navigation", 'wz-distributor'),
"items_list" => __( "Role list", 'wz-distributor'),
);
$args = array(
"label" => __( "Role", 'wz-distributor'),
"labels" => $labels,
"public" => true,
"hierarchical" => true,
"label" => "Role",
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => array( 'slug' => 'role_member', 'with_front' => true, 'hierarchical' => true, ),
"show_admin_column" => true,
"show_in_rest" => false,
"rest_base" => "role_member",
"show_in_quick_edit" => true,
);
register_taxonomy( "role_member", array( "wz_distributor" ), $args );
}
/* Add Default Terms: new member for Distributor */
add_action( 'init', 'register_new_terms' );
function register_new_terms() {
$taxonomy = 'role_member';
$terms = array (
'0' => array (
'name' => 'New Member',
'slug' => 'new-member',
'description' => 'New member level',
),
);
foreach ( $terms as $term_key=>$term) {
wp_insert_term(
$term['name'],
$taxonomy,
array(
'description' => $term['description'],
'slug' => $term['slug'],
)
);
unset( $term );
}
}
function set_default_object_terms( $post_id, $post ) {
if ( 'publish' === $post->post_status && $post->post_type === 'wz_distributor' ) {
$defaults = array(
'role_member' => array( 'new-member' )
);
$taxonomies = get_object_taxonomies( $post->post_type );
foreach ( (array) $taxonomies as $taxonomy ) {
$terms = wp_get_post_terms( $post_id, $taxonomy );
if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) {
wp_set_object_terms( $post_id, $defaults[$taxonomy], $taxonomy );
}
}
}
}
add_action( 'save_post', 'set_default_object_terms', 0, 2 );
/* Add custom field to Distributor post type */
require_once( dirname( __FILE__ ) . '/vendor/advanced-custom-fields/acf.php');
define( 'ACF_LITE', true );
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_info-distributor',
'title' => 'Info Distributor',
'fields' => array (
array (
'key' => 'field_5b39e78c1a313',
'label' => 'Distributor ID',
'name' => 'distributor_id',
'type' => 'text',
'instructions' => '"insert for Distributor ID"',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_5b39e8c71a315',
'label' => 'Line',
'name' => 'line',
'type' => 'text',
'instructions' => 'Sample link "https://line.me/R/ti/p/%40walnutztudio"',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_5b39ebef1a316',
'label' => 'Instragram',
'name' => 'instragram',
'type' => 'text',
'instructions' => 'Sample link "https://www.instagram.com/walnutztudio/"',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_5b39ec021a317',
'label' => 'Facebook',
'name' => 'facebook',
'type' => 'text',
'instructions' => 'Sample link "https://www.facebook.com/walnutztudio"',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_5b39ec0c1a318',
'label' => 'Website',
'name' => 'website',
'type' => 'text',
'instructions' => 'Sample link "https://walnutztudio.com"',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'wz_distributor',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}