-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
574 lines (511 loc) · 19.3 KB
/
Copy pathfunctions.php
File metadata and controls
574 lines (511 loc) · 19.3 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
<?php
add_action('after_setup_theme', 'my_wikitoki_setup');
function my_wikitoki_setup(){
load_child_theme_textdomain('wikitoki', get_stylesheet_directory() . '/languages');
}
// custom post types
add_action( 'init', 'create_post_type', 0 );
function create_post_type() {
// ACTIVIDAD
register_post_type( 'actividad', array(
'labels' => array(
'name' => __( 'Activities' ),
'singular_name' => __( 'Activity' ),
'add_new_item' => __( 'Añadir una actividad' ),
'edit' => __( 'Editar' ),
'edit_item' => __( 'Editar actividad' ),
'new_item' => __( 'Nueva actividad' ),
'view' => __( 'Ver la actividad' ),
'view_item' => __( 'Ver la actividad' ),
'search_items' => __( 'Buscar una actividad' ),
'not_found' => __( 'No se ha encontrado ninguna actividad' ),
'not_found_in_trash' => __( 'No se han encontrado actividades en la papelera' ),
'parent' => __( 'Parent' )
),
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'menu_position' => 4,
'show_in_nav_menus' => true,
'has_archive' => true,
// 'menu_icon' => get_template_directory_uri() . '/images/icon-post.type-integrantes.png',
'hierarchical' => false, // if true this post type will be as pages
'query_var' => true,
'supports' => array('title','editor','excerpt','custom-fields','author','comments','revisions','thumbnail'),
//'taxonomies' => array('origine',), TODO
'rewrite' => array('slug'=>'actividad','with_front'=>false),
'can_export' => true,
// '_builtin' => false,
// '_edit_link' => 'post.php?post=%d',
// 'map_meta_cap' => true, // should be true to make capability_type works
// 'capability_type' => 'page',
));
}
// Custom Taxonomies
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
// TIPO DE ACTIVIDAD
register_taxonomy( 'tipo-actividad', array('actividad'), array(
'labels' => array(
'name' => _x( 'Tipos de actividad','taxonomy general name' ),
'singular_name' => _x( 'Tipo de actividad','taxonomy general name' ),
'search_items' => __( 'Busca tipo de actividad' ),
'popular_items' => __( 'Tipos de actividad populares' ),
'all_items' => __( 'Todos los tipos de actividad' ),
'parent_item' => __( 'Actividad tipo padre' ),
'edit_item' => __( 'Modifica el tipo de actividad' ),
'update_item' => __( 'Actualiza el tipo de actividad' ),
'add_new_item' => __( 'Añade tipo de actividad' ),
'new_item_name' => __( 'Nuevo nombre del tipo de actividad' ),
),
'public' => true,
'hierarchical' => true,
'update_count_callback' => true,
'query_var' => true,
'rewrite' => array('slug'=>'tipo-actividad','with_front'=>false,'hierarchical'=>true)
));
// ESCALA DE ACTIVIDAD
register_taxonomy( 'escala-actividad', array('actividad'), array(
'labels' => array(
'name' => _x( 'Escalas de actividad','taxonomy general name' ),
'singular_name' => _x( 'Escala de actividad','taxonomy general name' ),
'search_items' => __( 'Busca escala de actividad' ),
'popular_items' => __( 'escala de actividad populares' ),
'all_items' => __( 'Todas las escalas de actividad' ),
'parent_item' => __( 'Escala tipo madre' ),
'edit_item' => __( 'Modifica la escala de actividad' ),
'update_item' => __( 'Actualiza la escala de actividad' ),
'add_new_item' => __( 'Añade la escala de actividad' ),
'new_item_name' => __( 'Nuevo nombre del tipo de actividad' ),
),
'public' => true,
'hierarchical' => true,
'update_count_callback' => true,
'query_var' => true,
'rewrite' => array('slug'=>'escala-actividad','with_front'=>false,'hierarchical'=>true)
));
}
//// CUSTOM METABOXES: Adds new fields for Atividades
// More info about metabox at https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Basic-Usage
function sample_metaboxes( $meta_boxes ) {
$prefixact = '_act_'; // Prefix for all fields
$meta_boxes[] = array(
'id' => 'activiy-info',
'title' => 'Información sobre Actividad',
'pages' => array('actividad'), // post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => 'Lugar',
'desc' => '',
'id' => $prefixact . 'place',
'type' => 'text_small'
),
array(
'name' => 'Hora',
'desc' => 'Hora a la que ocurre el evento. Ej: 18.30h',
'id' => $prefixact . 'time',
'type' => 'text_small',
),
array(
'name' => 'Fecha de inicio',
'desc' => 'Seleccion la fecha',
'id' => $prefixact . 'date-init',
'type' => 'text_datetime_timestamp'
),
array(
'name' => 'Fecha final',
'desc' => 'Seleccion la fecha',
'id' => $prefixact . 'date-end',
'type' => 'text_datetime_timestamp',
),
array(
'name' => 'Actividad permanente',
'id' => $prefixact . 'permanente',
'type' => 'radio_inline',
'default' => 'no',
'options' => array(
'sí' => 'sí',
'no' => 'no',
),
),
array(
'name' => 'Organizador',
'desc' => 'Nombre del grupo o persona organizadora',
'id' => $prefixact . 'organizador',
'type' => 'text_small'
),
array(
'name' => 'Número de asistentes',
'desc' => 'Ejempo: 12',
'id' => $prefixact . 'numero-asistentes',
'type' => 'text_small'
),
array(
'id' => $prefixact . 'mas_info_url',
'type' => 'group',
'desc' => 'Más información URL',
'options' => array('group_title' => 'Más información'),
'fields' => array(
array(
'name' => __( 'Texto del link','spacious-child' ),
'id' => 'url_text',
'type' => 'text',
'desc' => 'Texto del link, tipo: Más fotos, Párrafo con más información',
),
array(
'name' => 'URL',
'id' => 'url',
'type' => 'text_url',
'protocols' => array( 'http', 'https' ),
'desc' => 'URL del link: http://zaramari.com/el-taller-del-mapa',
),
),
),
array(
'name' => __( 'Relación con el barrio','montera34' ),
'desc' => 'Escribe un párrafo',
'id' => $prefixact . 'relacion-barrio',
'type' => 'wysiwyg',
'options' => array(
'textarea_rows' => get_option('default_post_edit_rows', 4),
)
),
array(
'name' => __( 'Qué relación las actividades ha tenido con temas promovidos por el Ayuntamiento','wikitoki' ),
'desc' => 'Escribe un párrafo',
'id' => $prefixact . 'relacion-ayuntamiento',
'type' => 'wysiwyg',
'options' => array(
'textarea_rows' => get_option('default_post_edit_rows', 4),
)
),
array(
'name' => __( 'Resumen de la actividad','wikitoki' ),
'desc' => '',
'id' => $prefixact . 'resumen-actividad',
'type' => 'wysiwyg',
'options' => array(
'textarea_rows' => get_option('default_post_edit_rows', 15),
)
),
),
);
return $meta_boxes;
}
add_filter( 'cmb_meta_boxes', 'sample_metaboxes' );
// Initialize the metabox class
add_action( 'init', 'initialize_cmb_meta_boxes', 9999 );
function initialize_cmb_meta_boxes() {
if ( !class_exists( 'cmb_Meta_Box' ) ) {
require_once( 'lib/metabox/init.php' );
}
}
//// USER
// extra fields in user profile
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) {
$extra_fields = array(
array(
'name' => 'Web (URL) <br>Ej: http://wikitoki.org',
'label' => 'web'
),
array(
'name' => 'Feed (rss) <br>Ej: http://wikitoki.org/feed',
'label' => 'feed'
),
array(
'name' => 'Twitter <br>Ej: wiki_toki',
'label' => 'twitter'
),
array(
'name' => 'Facebook <br>Ej http://facebook.com/wikitoki',
'label' => 'facebook'
),
);
?>
<h3><?php _e("Información", "blank"); ?></h3>
<table class="form-table">
<?php foreach ( $extra_fields as $extra_field ) { ?>
<tr>
<th><label for="<?php echo $extra_field['label']; ?>"><?php echo $extra_field['name']; ?></label></th>
<td>
<input type="text" name="<?php echo $extra_field['label']; ?>" id="<?php echo $extra_field['label']; ?>" value="<?php echo esc_attr( get_the_author_meta( $extra_field['label'], $user->ID ) ); ?>" class="regular-text" /><br />
</td>
</tr>
<?php } ?>
</table>
<?php }
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
$extra_fields = array(
array(
'name' => 'Web (URL) <br>Ej: http://wikitoki.org',
'label' => 'web'
),
array(
'name' => 'Feed (rss) <br>Ej: http://wikitoki.org/feed',
'label' => 'feed'
),
array(
'name' => 'Twitter <br>Ej: wiki_toki',
'label' => 'twitter'
),
array(
'name' => 'Facebook <br>Ej http://facebook.com/wikitoki',
'label' => 'facebook'
),
);
foreach ( $extra_fields as $extra_field ) {
update_user_meta( $user_id, $extra_field['label'], $_POST[$extra_field['label']] );
}
}
////////////////// USER TAXONOMIES
// Custom User Taxonomies
add_action( 'init', 'build_user_taxonomies', 0 );
function build_user_taxonomies() {
// Tipo de usuario
register_taxonomy( 'user-type', 'user', array(
'labels' => array(
'name' => _x( 'Tipos de usuario','taxonomy general name' ),
'singular_name' => _x( 'Tipo de usuario','taxonomy general name' ),
'search_items' => __( 'Busca entre los tipos de usuario' ),
'popular_items' => __( 'Tipos de usuario populares' ),
'all_items' => __( 'Todos los tipos de usuario' ),
'parent_item' => __( 'Tipo de usuario padre' ),
'edit_item' => __( 'Editar tipo de usuario' ),
'update_item' => __( 'Actualizar' ),
'add_new_item' => __( 'Añadir nuevo tipo de usuario' ),
'new_item_name' => __( 'nuevo tipo de usuario' ),
// 'separate_items_with_commas' => __( 'Separate tags with commas' ),
// 'add_or_remove_items' => __( 'Add or remove tags' ),
// 'choose_from_most_used' => __( 'Choose from the most used tags' ),
// 'menu_name' =>
),
'public' => true,
'hierarchical' => true,
// 'update_count_callback' => 'my_update_professionnel_count', // Use a custom function to update the count. TODO
// 'query_var' => true,
'rewrite' => array('slug'=>'user-type','with_front'=>false,'hierarchical'=>true),
'capabilities' => array(
'manage_terms' => 'edit_users', // Using 'edit_users' cap to keep this simple.
'edit_terms' => 'edit_users',
'delete_terms' => 'edit_users',
'assign_terms' => 'read',
),
));
// Usuario al que pertenece
register_taxonomy( 'user-group', 'user', array(
'labels' => array(
'name' => _x( 'Grupos','taxonomy general name' ),
'singular_name' => _x( 'Grupo','taxonomy general name' ),
'search_items' => __( 'Busca entre los grupos' ),
'popular_items' => __( 'Grupos populares' ),
'all_items' => __( 'Todos los grupos' ),
'parent_item' => __( 'Grupo padre' ),
'edit_item' => __( 'Editar grupo' ),
'update_item' => __( 'Actualizar' ),
'add_new_item' => __( 'Añadir nuevo grupo' ),
'new_item_name' => __( 'Nuevo tipo de grupo' ),
// 'separate_items_with_commas' => __( 'Separate tags with commas' ),
// 'add_or_remove_items' => __( 'Add or remove tags' ),
// 'choose_from_most_used' => __( 'Choose from the most used tags' ),
// 'menu_name' =>
),
'public' => true,
'hierarchical' => true,
// 'update_count_callback' => 'my_update_professionnel_count', // Use a custom function to update the count. TODO
// 'query_var' => true,
'rewrite' => array('slug'=>'user-group','with_front'=>false,'hierarchical'=>true),
'capabilities' => array(
'manage_terms' => 'edit_users', // Using 'edit_users' cap to keep this simple.
'edit_terms' => 'edit_users',
'delete_terms' => 'edit_users',
'assign_terms' => 'read',
),
));
}
/* Adds user taxonomies page in the admin. */
add_action( 'admin_menu', 'my_add_user_type_admin_page' );
add_action( 'admin_menu', 'my_add_user_group_admin_page' );
/**
* Creates the admin pages for the 'professionnel', 'secteur' and 'lieu' taxonomies under the 'Users' menu. It works the same as any
* other taxonomy page in the admin. However, this is kind of hacky and is meant as a quick solution. When
* clicking on the menu item in the admin, WordPress' menu system thinks you're viewing something under 'Posts'
* instead of 'Users'. We really need WP core support for this.
*/
function my_add_user_type_admin_page() {
$tax = get_taxonomy( 'user-type' );
add_users_page(
esc_attr( $tax->labels->menu_name ),
esc_attr( $tax->labels->menu_name ),
$tax->cap->manage_terms,
'edit-tags.php?taxonomy=' . $tax->name
);
}
function my_add_user_group_admin_page() {
$tax = get_taxonomy( 'user-group' );
add_users_page(
esc_attr( $tax->labels->menu_name ),
esc_attr( $tax->labels->menu_name ),
$tax->cap->manage_terms,
'edit-tags.php?taxonomy=' . $tax->name
);
}
/* Open the right admin menu when clicking in user taxonomies: Professionnel, Secteur, Lieu */
add_filter( 'parent_file', 'fix_user_tax_page' );
function fix_user_tax_page( $parent_file = '' ) {
global $pagenow;
if ( ! empty( $_GET[ 'taxonomy' ] ) && $_GET[ 'taxonomy' ] == 'user-type' && $pagenow == 'edit-tags.php' ) {
$parent_file = 'users.php';
}
if ( ! empty( $_GET[ 'taxonomy' ] ) && $_GET[ 'taxonomy' ] == 'user-group' && $pagenow == 'edit-tags.php' ) {
$parent_file = 'users.php';
}
return $parent_file;
}
/* Add section to the edit user page in the admin to select profession, secteur or lieu */
add_action( 'show_user_profile', 'my_edit_user_type_section' );
add_action( 'edit_user_profile', 'my_edit_user_type_section' );
add_action( 'show_user_profile', 'my_edit_user_group_section' );
add_action( 'edit_user_profile', 'my_edit_user_group_section' );
/**
* Adds an additional settings section on the edit user/profile page in the admin. This section allows users to
* select a profession, secteur or lieu from a checkbox of terms from each taxonomy.
*
* @param object $user The user object currently being edited.
*/
// user type
function my_edit_user_type_section( $user ) {
$tax = get_taxonomy( 'user-type' );
/* Make sure the user can assign terms of the profession taxonomy before proceeding. */
if ( !current_user_can( $tax->cap->assign_terms ) )
return;
/* Get the terms of the 'profession' taxonomy. */
$terms = get_terms( 'user-type', array( 'hide_empty' => false ) ); ?>
<h3><?php _e( 'Tipo de usuario' ); ?></h3>
<table class="form-table">
<tr>
<th><label for="user-type"><?php _e( 'Elige uno de los tipos' ); ?></label></th>
<td>
<fieldset id="user-type">
<?php
/* If there are any profession terms, loop through them and display checkboxes. */
if ( !empty( $terms ) ) {
foreach ( $terms as $term ) { ?>
<input type="checkbox" name="user-type-<?php echo esc_attr( $term->slug ); ?>" id="user-type-<?php echo esc_attr( $term->slug ); ?>" value="<?php echo esc_attr( $term->slug ); ?>" <?php checked( true, is_object_in_term( $user->ID, 'user-type', $term->slug ) ); ?> /> <label for="user-type-<?php echo esc_attr( $term->slug ); ?>"><?php echo $term->name; ?></label> <br />
<?php }
}
/* If there are no profession terms, display a message. */
else {
_e( 'No hay usuarios de este tipo.' );
}
?></fieldset></td>
</tr>
</table>
<?php }
// user group
function my_edit_user_group_section( $user ) {
$tax = get_taxonomy( 'user-group' );
/* Make sure the user can assign terms of the profession taxonomy before proceeding. */
if ( !current_user_can( $tax->cap->assign_terms ) )
return;
/* Get the terms of the 'profession' taxonomy. */
$terms = get_terms( 'user-group', array( 'hide_empty' => false ) ); ?>
<h3><?php _e( 'Grupo al que pertenece el usuario' ); ?></h3>
<table class="form-table">
<tr>
<th><label for="user-group"><?php _e( 'Elige uno de los grupos' ); ?></label></th>
<td>
<fieldset id="user-group">
<?php
/* If there are any profession terms, loop through them and display checkboxes. */
if ( !empty( $terms ) ) {
foreach ( $terms as $term ) { ?>
<input type="checkbox" name="user-group-<?php echo esc_attr( $term->slug ); ?>" id="user-group-<?php echo esc_attr( $term->slug ); ?>" value="<?php echo esc_attr( $term->slug ); ?>" <?php checked( true, is_object_in_term( $user->ID, 'user-group', $term->slug ) ); ?> /> <label for="user-group-<?php echo esc_attr( $term->slug ); ?>"><?php echo $term->name; ?></label> <br />
<?php }
}
/* If there are no profession terms, display a message. */
else {
_e( 'No hay grupos de usuario.' );
}
?></fieldset></td>
</tr>
</table>
<?php }
/* Update the profession terms when the edit user page is updated. */
add_action( 'personal_options_update', 'my_save_user_type_terms' );
add_action( 'edit_user_profile_update', 'my_save_user_type_terms' );
add_action( 'personal_options_update', 'my_save_user_group_terms' );
add_action( 'edit_user_profile_update', 'my_save_user_group_terms' );
/**
* Saves the term selected on the edit user/profile page in the admin. This function is triggered when the page
* is updated. We just grab the posted data and use wp_set_object_terms() to save it.
*
* @param int $user_id The ID of the user to save the terms for.
*/
// user type
function my_save_user_type_terms( $user_id ) {
$tax = get_taxonomy( 'user-type' );
/* Make sure the current user can edit the user and assign terms before proceeding. */
if ( !current_user_can( 'edit_user', $user_id ) && current_user_can( $tax->cap->assign_terms ) )
return false;
$terms = get_terms('user-type','hide_empty=0');
$add_terms = array();
foreach ( $terms as $term ) {
$toadd = esc_attr( $_POST['user-type-' .$term->slug] );
if ( $toadd != '' ) { array_push($add_terms, $term->slug); }
}
/* Sets the terms (we're just using a single term) for the user. */
wp_set_object_terms( $user_id, $add_terms, 'user-type', false);
clean_object_term_cache( $user_id, 'user-type' );
}
// user group
function my_save_user_group_terms( $user_id ) {
$tax = get_taxonomy( 'user-group' );
/* Make sure the current user can edit the user and assign terms before proceeding. */
if ( !current_user_can( 'edit_user', $user_id ) && current_user_can( $tax->cap->assign_terms ) )
return false;
$terms = get_terms('user-group','hide_empty=0');
$add_terms = array();
foreach ( $terms as $term ) {
$toadd = esc_attr( $_POST['user-group-' .$term->slug] );
if ( $toadd != '' ) { array_push($add_terms, $term->slug); }
}
/* Sets the terms (we're just using a single term) for the user. */
wp_set_object_terms( $user_id, $add_terms, 'user-group', false);
clean_object_term_cache( $user_id, 'user-group' );
}
//adds all the custom post types to the feed
function myfeed_request($qv) {
if (isset($qv['feed']) && !isset($qv['post_type']))
$qv['post_type'] = array('post', 'actividad');
return $qv;
}
add_filter('request', 'myfeed_request');
//Adds filter to make oembed filters (captions shortcode) work in wysiwyg field tpe in custom meta boxes
function wikitoki_get_wysiwyg_output( $meta_key, $post_id = 0 ) {
global $wp_embed;
$post_id = $post_id ? $post_id : get_the_id();
$content = get_post_meta( $post_id, $meta_key, 1 );
$content = $wp_embed->autoembed( $content );
$content = $wp_embed->run_shortcode( $content );
$content = do_shortcode( $content );
$content = wpautop( $content );
return $content;
}
//Adds Orbita menu
function register_my_menus() {
register_nav_menus(
array(
'orbita' => 'Orbita',
)
);
}
add_action( 'init', 'register_my_menus' );