-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
580 lines (463 loc) · 22.1 KB
/
functions.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
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
575
576
577
578
579
580
<?php
/**
* Starkers functions and definitions
*
* For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
*
* @package WordPress
* @subpackage Starkers
* @since Starkers 4.0
*/
/* ========================================================================================================================
Required external files
======================================================================================================================== */
require_once( 'external/starkers-utilities.php' );
/* ========================================================================================================================
Theme specific settings
Uncomment register_nav_menus to enable a single menu with the title of "Primary Navigation" in your theme
======================================================================================================================== */
add_theme_support('post-thumbnails');
// seet default post thumbnail size with a hard crop
// use "false" for soft crop, or box resize mode
set_post_thumbnail_size( auto, auto, true );
register_nav_menus(array('primary' => 'Primary Navigation'));
/* ========================================================================================================================
Actions and Filters
======================================================================================================================== */
// add_action( 'wp_enqueue_scripts', 'starkers_script_enqueuer' );
add_filter( 'body_class', array( 'Starkers_Utilities', 'add_slug_to_body_class' ) );
/* Removing the P tag from a field wich has WYSIWYG */
function the_field_without_wpautop( $field_name ) {
remove_filter('acf_the_content', 'wpautop');
the_field( $field_name );
add_filter('acf_the_content', 'wpautop');
}
/* ========================================================================================================================
Custom Post Types - include custom post types and taxonimies here e.g.
e.g. require_once( 'custom-post-types/your-custom-post-type.php' );
======================================================================================================================== */
// RECETAS cpt and taxonomies
// Register Custom Post Type
add_action( 'init', 'create_cpt_recetas', 0 );
function create_cpt_recetas() {
$labels = array(
'name' => _x( 'Recetas', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Receta', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Recetas', 'text_domain' ),
'name_admin_bar' => __( 'Recetas', 'text_domain' ),
'parent_item_colon' => __( 'Receta padre', 'text_domain' ),
'all_items' => __( 'Todas las recetas', 'text_domain' ),
'add_new_item' => __( 'Añadir receta', 'text_domain' ),
'add_new' => __( 'Añadir nueva', 'text_domain' ),
'new_item' => __( 'Nueva receta', 'text_domain' ),
'edit_item' => __( 'Editar receta', 'text_domain' ),
'update_item' => __( 'Actualizar receta', 'text_domain' ),
'view_item' => __( 'Ver receta', 'text_domain' ),
'search_items' => __( 'Buscar receta', 'text_domain' ),
'not_found' => __( 'Receta no encontrada', 'text_domain' ),
'not_found_in_trash' => __( 'No hay recetas en la papelera', 'text_domain' ),
);
$args = array(
'label' => __( 'Receta', 'text_domain' ),
'description' => __( 'Entradas de recetas', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ),
'taxonomies' => array( 'recetas_cat', 'recetas_tag' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 25,
'menu_icon' => get_stylesheet_directory_uri() . '/img/icons/icon-menu-recipes.png',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'recetas', $args );
}
// Register Custom Taxonomy
add_action( 'init', 'create_recetas_cat', 0 );
function create_recetas_cat() {
$labels = array(
'name' => _x( 'Categorías de recetas', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Categoría', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Categorías de receta', 'text_domain' ),
'all_items' => __( 'Todas las categorías', 'text_domain' ),
'parent_item' => __( 'Categoría padre', 'text_domain' ),
'parent_item_colon' => __( 'Categoría padre:', 'text_domain' ),
'new_item_name' => __( 'Nueva categoría', 'text_domain' ),
'add_new_item' => __( 'Añadir nueva', 'text_domain' ),
'edit_item' => __( 'Editar categoría', 'text_domain' ),
'update_item' => __( 'Actualizar categoría', 'text_domain' ),
'view_item' => __( 'Ver categoría', 'text_domain' ),
'separate_items_with_commas' => __( 'Separar por comas', 'text_domain' ),
'add_or_remove_items' => __( 'Añadir o quitar categorías', 'text_domain' ),
'choose_from_most_used' => __( 'Escoge entre las más usadas', 'text_domain' ),
'popular_items' => __( 'Categorías populares', 'text_domain' ),
'search_items' => __( 'Buscar categorías', 'text_domain' ),
'not_found' => __( 'Categoría no encontrada', 'text_domain' ),
);
$rewrite = array(
'slug' => 'categorias',
'with_front' => true,
'hierarchical' => true,
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy( 'recetas_cat', array( 'recetas' ), $args );
}
// Register Custom Taxonomy
add_action( 'init', 'create_recetas_tag', 0 );
function create_recetas_tag() {
$labels = array(
'name' => _x( 'Etiquetas', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Etiqueta', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Etiquetas de recetas', 'text_domain' ),
'all_items' => __( 'Todas las etiquetas', 'text_domain' ),
'parent_item' => __( 'Etiqueta padre', 'text_domain' ),
'parent_item_colon' => __( 'Etiqueta padre:', 'text_domain' ),
'new_item_name' => __( 'Nueva etiqueta', 'text_domain' ),
'add_new_item' => __( 'Añadir nueva etiqueta', 'text_domain' ),
'edit_item' => __( 'Editar etiqueta', 'text_domain' ),
'update_item' => __( 'Actualizar etiqueta', 'text_domain' ),
'view_item' => __( 'Ver etiqueta', 'text_domain' ),
'separate_items_with_commas' => __( 'Separar por comas', 'text_domain' ),
'add_or_remove_items' => __( 'Añadir o quitar etiquetas', 'text_domain' ),
'choose_from_most_used' => __( 'Escoge entre las más usadas', 'text_domain' ),
'popular_items' => __( 'Etiquetas populares', 'text_domain' ),
'search_items' => __( 'Buscar etiquetas', 'text_domain' ),
'not_found' => __( 'Etiqueta no encontrada', 'text_domain' ),
);
$rewrite = array(
'slug' => 'etiquetas',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy( 'recetas_tag', array( 'recetas' ), $args );
}
// MÚSICA cpt and taxonomies
// Register Custom Post Type
add_action( 'init', 'create_cpt_musica', 0 );
function create_cpt_musica() {
$labels = array(
'name' => _x( 'Musica', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Música', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Música', 'text_domain' ),
'name_admin_bar' => __( 'Música', 'text_domain' ),
'parent_item_colon' => __( 'Música padre', 'text_domain' ),
'all_items' => __( 'Todas las músicas', 'text_domain' ),
'add_new_item' => __( 'Añadir música', 'text_domain' ),
'add_new' => __( 'Añadir nueva', 'text_domain' ),
'new_item' => __( 'Nueva música', 'text_domain' ),
'edit_item' => __( 'Editar música', 'text_domain' ),
'update_item' => __( 'Actualizar música', 'text_domain' ),
'view_item' => __( 'Ver música', 'text_domain' ),
'search_items' => __( 'Buscar música', 'text_domain' ),
'not_found' => __( 'Música no encontrada', 'text_domain' ),
'not_found_in_trash' => __( 'No hay música en la papelera', 'text_domain' ),
);
$args = array(
'label' => __( 'Musica', 'text_domain' ),
'description' => __( 'Entradas de música', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ),
'taxonomies' => array( 'musica_cat', 'musica_tag' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 25,
'menu_icon' => get_stylesheet_directory_uri() . '/img/icons/icon-menu-music.png',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'musica', $args );
}
// Register Custom Taxonomy
add_action( 'init', 'create_musica_cat', 0 );
function create_musica_cat() {
$labels = array(
'name' => _x( 'Categorías de música', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Categoría', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Categorías de música', 'text_domain' ),
'all_items' => __( 'Todas las categorías', 'text_domain' ),
'parent_item' => __( 'Categoría padre', 'text_domain' ),
'parent_item_colon' => __( 'Categoría padre:', 'text_domain' ),
'new_item_name' => __( 'Nueva categoría', 'text_domain' ),
'add_new_item' => __( 'Añadir nueva', 'text_domain' ),
'edit_item' => __( 'Editar categoría', 'text_domain' ),
'update_item' => __( 'Actualizar categoría', 'text_domain' ),
'view_item' => __( 'Ver categoría', 'text_domain' ),
'separate_items_with_commas' => __( 'Separar por comas', 'text_domain' ),
'add_or_remove_items' => __( 'Añadir o quitar categorías', 'text_domain' ),
'choose_from_most_used' => __( 'Escoge entre las más usadas', 'text_domain' ),
'popular_items' => __( 'Categorías populares', 'text_domain' ),
'search_items' => __( 'Buscar categorías', 'text_domain' ),
'not_found' => __( 'Categoría no encontrada', 'text_domain' ),
);
$rewrite = array(
'slug' => 'secciones',
'with_front' => true,
'hierarchical' => true,
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy( 'musica_cat', array( 'musica' ), $args );
}
// Register Custom Taxonomy
add_action( 'init', 'create_musica_tag', 0 );
function create_musica_tag() {
$labels = array(
'name' => _x( 'Etiquetas', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Etiqueta', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Etiquetas de música', 'text_domain' ),
'all_items' => __( 'Todas las etiquetas', 'text_domain' ),
'parent_item' => __( 'Etiqueta padre', 'text_domain' ),
'parent_item_colon' => __( 'Etiqueta padre:', 'text_domain' ),
'new_item_name' => __( 'Nueva etiqueta', 'text_domain' ),
'add_new_item' => __( 'Añadir nueva etiqueta', 'text_domain' ),
'edit_item' => __( 'Editar etiqueta', 'text_domain' ),
'update_item' => __( 'Actualizar etiqueta', 'text_domain' ),
'view_item' => __( 'Ver etiqueta', 'text_domain' ),
'separate_items_with_commas' => __( 'Separar por comas', 'text_domain' ),
'add_or_remove_items' => __( 'Añadir o quitar etiquetas', 'text_domain' ),
'choose_from_most_used' => __( 'Escoge entre las más usadas', 'text_domain' ),
'popular_items' => __( 'Etiquetas populares', 'text_domain' ),
'search_items' => __( 'Buscar etiquetas', 'text_domain' ),
'not_found' => __( 'Etiqueta no encontrada', 'text_domain' ),
);
$rewrite = array(
'slug' => 'apartado',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy( 'musica_tag', array( 'musica' ), $args );
}
//Hide admin bar in wordpress
add_filter('show_admin_bar', '__return_false');
/* ========================================================================================================================
Scripts
======================================================================================================================== */
/**
* Add scripts via wp_head()
*
* @return void
* @author Keir Whitaker
*/
/* Including javascript to the site */
//jQuery Insert From Google
/*
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", true, null);
wp_enqueue_script('jquery');
}
function starkers_script_enqueuer() {
wp_register_script( 'site', get_template_directory_uri().'/js/site.js', array( 'jquery' ), 1, true );
wp_enqueue_script( 'site' );
wp_enqueue_style( 'screen' );
}
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
}
*/
function include_my_scripts_to_template()
{
// Deregister the included library
wp_deregister_script( 'jquery' );
// Register the library again from Google's CDN
wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js', array(), null, true );
// Register the script like this for a plugin: @http://goo.gl/PA1Jaq
//wp_register_script( 'custom-script', plugins_url( '/js/custom-script.js', __FILE__ ), array( 'jquery', 'jquery-ui-core' ), '20120208', true );
// Register the script like this for a theme:
wp_register_script( 'site-scripts', get_template_directory_uri() . '/js/scripts.min.js', array( 'jquery'), '10032016', true );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'site-scripts' );
}
add_action( 'wp_enqueue_scripts', 'include_my_scripts_to_template' );
/* ========================================================================================================================
Styles
======================================================================================================================== */
// load css into the website's front-end @my-stylesheet--screen
function load_my_styles_in_frontend() {
// Register and enqueue the stylesheet for SCREEN
// wp_register_style( $handle, $src, $deps, $ver, $media );
wp_register_style(
'my-stylesheet--screen', // handle name
get_template_directory_uri() . '/css/styles.css', // the URL of the stylesheet
// array( 'bootstrap-main' ), // an array of dependent styles
array(),
'10032016', // version number
'screen' // CSS media type
);
// if we registered the style before:
wp_enqueue_style( 'my-stylesheet--screen' );
// Register and enqueue the stylesheet for PRINT
// wp_register_style( $handle, $src, $deps, $ver, $media );
wp_register_style(
'my-stylesheet--print', // handle name
get_template_directory_uri() . '/css/print.css', // the URL of the stylesheet
// array( 'bootstrap-main' ), // an array of dependent styles
array(),
'10032016', // version number
'print' // CSS media type
);
// if we registered the style before:
wp_enqueue_style( 'my-stylesheet--print' );
}
add_action( 'wp_enqueue_scripts', 'load_my_styles_in_frontend' );
/* ========================================================================================================================
Comments
======================================================================================================================== */
/**
* Custom callback for outputting comments
*
* @return void
* @author Keir Whitaker
*/
function starkers_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment; ?>
<?php if ( $comment->comment_approved == '1' ): ?>
<li>
<article id="comment-<?php comment_ID() ?>" class="comments">
<div class="comment__commentator">
<?php echo get_avatar( $comment ); ?>
<h3><?php comment_author_link() ?></h3>
<time class="small"><a href="#comment-<?php comment_ID() ?>" pubdate><?php comment_date() ?></a></time>
</div>
<div class="comment__missaticum">
<?php comment_text() ?>
</div>
<!-- the reply link -
but it's missing how to print it inside the article
that warps the replied comment
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'], $add_below ) ) ); ?>
</div>
-->
</article>
<?php endif;
}
/* Custom function to get post image */
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches[1][0];
if(empty($first_img)) {
/*$first_img = "/path/to/default.png";*/
}
return $first_img;
}
/*
ADD FILTER TO THE FUNCTION NEXT-POST-LINK AND PREVIOUS-POST-LINK
IN ORDER TO ADD CLASSES TO THE HTML OUT FOR THOSE FUNCTIONS
http://goo.gl/0mJ9B6
*/
add_filter('next_posts_link_attributes', 'posts_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_link_attributes');
function posts_link_attributes() {
return 'class="btn btn-primary"';
}
/**
* Get taxonomies terms links.
* reference: https://developer.wordpress.org/reference/functions/get_the_terms/
*
* @see get_object_taxonomies()
*/
function wpdocs_custom_taxonomies_terms_links() {
// Get post by post ID.
$post = get_post( $post->ID );
// Get post type by post.
$post_type = $post->post_type;
// Get post type taxonomies.
$allTaxonomies = get_object_taxonomies( $post_type, 'objects' );
$taxonomies = $allTaxonomies[0];
$out = array();
foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){
// Get the terms related to post.
$terms = get_the_terms( $post->ID, $taxonomy_slug );
if ( ! empty( $terms ) ) {
// $out[] = "<h2>" . $taxonomy->label . "</h2>\n<ul>";
$out[] = "<ul class='menu'>";
foreach ( $terms as $term ) {
$out[] = sprintf( '<li><a href="%1$s">%2$s</a></li>',
esc_url( get_term_link( $term->slug, $taxonomy_slug ) ),
esc_html( $term->name )
);
}
$out[] = "\n</ul>\n";
}
}
return implode( '', $out );
}
// Displaying only subcategories from the matched taxonomy
// reference @https://goo.gl/Zn8JL2
function wt_get_child_terms( $post_id, $taxonomy = '', $args = array() ) {
$object_terms = wp_get_object_terms( $post_id, $taxonomy, $args );
$res = '';
if ( ! empty( $object_terms ) ) {
// $res .= '<ul class="menu menu__subcategories h-list-row">';
foreach ( $object_terms as $term ) {
if ( !( $term->parent === 0 ) ) {
$termLink = get_term_link( $term );
$res .= '<li><a href="'. $termLink .'" class="menu__subcategories--item">';
$res .= $term->name . '';
$res .= '</a></li>';
}
}
// $res .= '</ul>';
}
return apply_filters( 'wt_get_child_terms', rtrim( $res, ', ' ) );
}