-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-team-manager.php
executable file
·348 lines (291 loc) · 14.8 KB
/
wp-team-manager.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
/*
Plugin Name: WordPress Team Manager
Plugin URI: http://www.dynamicweblab.com/
Description: This plugin allows you to manage the members of your team or staff and display them using shortcode.
Author: Dynamic Web Lab
Version: 1.5.6
Author URI:http://www.dynamicweblab.com/
License: GPL2
*/
if (!defined('WTM_VERSION_KEY'))
define('WTM_VERSION_KEY', 'wtm_version');
if (!defined('WTM_VERSION_NUM'))
define('WTM_VERSION_NUM', '1.5.6');
add_option(WTM_VERSION_KEY, WTM_VERSION_NUM);
define( 'PLUGIN_DIR', dirname(__FILE__).'/' );
//include language
function wtm_load_textdomain()
{
// Localization
load_plugin_textdomain('wp-team-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
// Add actions
add_action('init', 'wtm_load_textdomain');
//include Meta Box Class
require_once PLUGIN_DIR . '/meta-box.php';
//include Shortcode Generator
require_once PLUGIN_DIR . '/shortcode-generator.php';
//include Settings
require_once PLUGIN_DIR . '/settings.php';
// add feature image on team_manager post type
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails', array( 'team_manager' ) );
}
function team_manager_featured_image_alttext($translation, $text, $domain) {
global $post;
if (is_object($post)){
if ($post->post_type == 'team_manager') {
$translations = get_translations_for_domain( $domain);
if ( $text == 'Featured Image')
return $translations->translate( 'Team Member Picture' );
if ( $text == 'Set featured image')
return $translations->translate( 'Select an image' );
}
}
return $translation;
}
//add_filter('gettext', 'team_manager_featured_image_alttext', 10, 4);
//Adding the necessary actions
add_action('init', 'register_team_manager' );
//register the custom post type for the team manager
function register_team_manager() {
$labels = array(
'name' => _x( 'Team', 'wp-team-manager' ),
'singular_name' => _x( 'Team Member', 'wp-team-manager' ),
'add_new' => _x( 'Add New Member', 'wp-team-manager' ),
'add_new_item' => _x( 'Add New ', 'wp-team-manager' ),
'edit_item' => _x( 'Edit Team Member ', 'wp-team-manager' ),
'new_item' => _x( 'New Team Member', 'wp-team-manager' ),
'view_item' => _x( 'View Team Members', 'wp-team-manager' ),
'search_items' => _x( 'Search Team Members', 'wp-team-manager' ),
'not_found' => _x( 'Not found any Team Member', 'wp-team-manager' ),
'not_found_in_trash' => _x( 'No Team Member found in Trash', 'wp-team-manager' ),
'parent_item_colon' => _x( 'Parent Team Member:', 'wp-team-manager' ),
'menu_name' => _x( 'Team', 'wp-team-manager' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'supports' => array( 'title', 'thumbnail','editor','page-attributes'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
'menu_icon' => plugins_url( 'img/icon16.png',__FILE__),
'rewrite' => array( 'slug' => 'team-manager' )
);
register_post_type( 'team_manager', $args );
//register custom category for the team manager
$labels = array(
'name' => _x( 'Groups', 'wp-team-manager' ),
'singular_name' => _x( 'Group', 'wp-team-manager' ),
'search_items' => _x( 'Search Groups', 'wp-team-manager' ),
'popular_items' => _x( 'Popular Groups', 'wp-team-manager' ),
'all_items' => _x( 'All Groups', 'wp-team-manager' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => _x( 'Edit Group', 'wp-team-manager' ),
'update_item' => _x( 'Update Group', 'wp-team-manager' ),
'add_new_item' => _x( 'Add New Group', 'wp-team-manager' ),
'new_item_name' => _x( 'New Group Name', 'wp-team-manager' ),
'separate_items_with_commas' => _x( 'Separate Groups with commas', 'wp-team-manager' ),
'add_or_remove_items' => _x( 'Add or remove Groups', 'wp-team-manager' ),
'choose_from_most_used' => _x( 'Choose from the most used Groups', 'wp-team-manager' ),
'not_found' => _x( 'No Groups found.', 'wp-team-manager' ),
'menu_name' => _x( 'Team Groups', 'wp-team-manager' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'team_groups' ),
);
register_taxonomy( 'team_groups', 'team_manager', $args );
}
// add VCF file type upload support
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() ) {
// add your extension to the array
$existing_mimes['vcf'] = 'text/x-vcard';
return $existing_mimes;
}
/********************* BEGIN DEFINITION OF META BOXES ***********************/
$prefix = 'tm_';
$meta_boxes = array();
$meta_boxes[] = array(
'id' => 'team_personal', // meta box id, unique per meta box
'title' => 'Team Member Information', // meta box title
'pages' => array('team_manager'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array( // list of meta fields
array(
'name' => __('Job Title','wp-team-manager'), // field name
'desc' => __('Job title of this team member.','wp-team-manager'), // field description, optional
'id' => $prefix . 'jtitle', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => __('') // default value, optional
),
array(
'name' => __('Telephone','wp-team-manager'), // field name
'desc' => __('Telephone no of this team member.','wp-team-manager'), // field description, optional
'id' => $prefix . 'telephone', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('Location','wp-team-manager'), // field name
'desc' => __('Location of this team member.','wp-team-manager'), // field description, optional
'id' => $prefix . 'location', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('Web URL','wp-team-manager'), // field name
'desc' => __('Website url of this team member.','wp-team-manager'), // field description, optional
'id' => $prefix . 'web_url', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('VCARD','wp-team-manager'),
'desc' => __('Upload your VCARD','wp-team-manager'),
'id' => $prefix . 'vcard',
'type' => 'file' // file upload
)
)
);
// first meta box
$meta_boxes[] = array(
'id' => 'team_social', // meta box id, unique per meta box
'title' => __('Social Profile','wp-team-manager'), // meta box title
'pages' => array('team_manager'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array( // list of meta fields
array(
'name' => __('Facebook','wp-team-manager'), // field name
'desc' => __('Facebook profile or page link.','wp-team-manager'), // field description, optional
'id' => $prefix . 'flink', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('Twitter','wp-team-manager'), // field name
'desc' => __('Twitter profile link.','wp-team-manager'), // field description, optional
'id' => $prefix . 'tlink', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('LinkedIn','wp-team-manager'), // field name
'desc' => __('LinkedIn profile link.','wp-team-manager'), // field description, optional
'id' => $prefix . 'llink', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('Google Plus','wp-team-manager'), // field name
'desc' => __('Google Plus profile link.','wp-team-manager'), // field description, optional
'id' => $prefix . 'gplink', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('Dribbble','wp-team-manager'), // field name
'desc' => __('Dribbble profile link.','wp-team-manager'), // field description, optional
'id' => $prefix . 'dribbble', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('Youtube','wp-team-manager'), // field name
'desc' => __('Youtube profile link.','wp-team-manager'), // field description, optional
'id' => $prefix . 'ylink', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('Vimeo','wp-team-manager'), // field name
'desc' => __('Vimeo profile link.','wp-team-manager'), // field description, optional
'id' => $prefix . 'vlink', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
),
array(
'name' => __('Email','wp-team-manager'), // field name
'desc' => __('Email Id','wp-team-manager'), // field description, optional
'id' => $prefix . 'emailid', // field id, i.e. the meta key
'type' => 'text', // text box
'std' => '' // default value, optional
)
)
);
/********************* BEGIN EXTENDING CLASS ***********************/
/**
* Extend WTM_Meta_Box class
* Add field type: 'taxonomy'
*/
class WTM_Meta_Box_Taxonomy extends WTM_Meta_Box {
function add_missed_values() {
parent::add_missed_values();
// add 'multiple' option to taxonomy field with checkbox_list type
foreach ($this->_meta_box['fields'] as $key => $field) {
if ('taxonomy' == $field['type'] && 'checkbox_list' == $field['options']['type']) {
$this->_meta_box['fields'][$key]['multiple'] = true;
}
}
}
// show taxonomy list
function show_field_taxonomy($field, $meta) {
global $post;
if (!is_array($meta)) $meta = (array) $meta;
$this->show_field_begin($field, $meta);
$options = $field['options'];
$terms = get_terms($options['taxonomy'], $options['args']);
// checkbox_list
if ('checkbox_list' == $options['type']) {
foreach ($terms as $term) {
echo "<input type='checkbox' name='{$field['id']}[]' value='$term->slug'" . checked(in_array($term->slug, $meta), true, false) . " /> $term->name<br/>";
}
}
// select
else {
echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">";
foreach ($terms as $term) {
echo "<option value='$term->slug'" . selected(in_array($term->slug, $meta), true, false) . ">$term->name</option>";
}
echo "</select>";
}
$this->show_field_end($field, $meta);
}
}
foreach ($meta_boxes as $meta_box) {
$wptm_box = new WTM_Meta_Box_Taxonomy($meta_box);
}
/********************* END DEFINITION OF META BOXES ***********************/
/********************* CSS enqueue functions ***********************/
function team_manager_add_css() {
wp_register_style( 'team-manager-style', plugins_url( '/css/tm-style.css', __FILE__ ),array(),false,false);
wp_enqueue_style( 'team-manager-style' );
}
add_action( 'wp_head', 'team_manager_add_css' );
function team_manager_add_custom_css()
{
echo '<style type="text/css" media="screen">';
echo get_option('tm_custom_css');
echo '</style>';
}
add_action( 'wp_head', 'team_manager_add_custom_css' );
?>