-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfunctions.php
executable file
·551 lines (459 loc) · 18 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
<?php
/* Theme support */
add_theme_support('post-thumbnails');
add_image_size('320x210', 320, 210, true); // thumbnail
add_image_size('660x250', 660, 250, true); // large thumb
add_image_size('660x9999', 660, 9999, false); // large
/* Menús
/* ----- */
// Definimos áreas para menús (location)
register_nav_menus( array(
'menu_principal' => 'Menu principal',
'menu_footer_1' => 'Menu Footer Columna 1',
'menu_footer_2' => 'Menu Footer Columna 2',
'menu_footer_3' => 'Menu Footer Columna 3',
'menu_inferior' => 'Menu Inferior'
) );
// Función para traer título del menú
function get_menu_title( $theme_location, $default_name = 'menu' ) {
if ( $theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
if( $menu && $menu->name ) {
return $menu->name;
}
}
return $default_name;
}
/* Limpiamos head
/* -------------- */
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
/* Apariencia > Personalizar
/* ---------------------------------- */
function gobcl_theme_customizer( $wp_customize ) {
// Quitamos sección 'Portada estática'
$wp_customize->remove_section( 'static_front_page');
// Añadimos sección 'Isologo'
$wp_customize->add_section( 'gobcl_logo_section' , array(
'title' => __( 'Isologo', 'gobcl' ),
'priority' => 30,
'description' => 'Reemplazar con el isologo correspondiente. 180x180 px',
)
);
$wp_customize->add_setting( 'gobcl_logo', array( 'default' => 'http://placehold.it/180/0168b3&text=Isologo+(180+x+180+px)') );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'gobcl_logo', array(
'label' => __( 'Isologo', 'gobcl' ),
'section' => 'gobcl_logo_section',
'settings' => 'gobcl_logo',
)
)
);
}
add_action('customize_register', 'gobcl_theme_customizer');
/* Apariencia > Personalizar: Imagen de cabecera
/* --------------------------------------------- */
$header_args = array(
'default-image' => 'http://placehold.it/1920x1440/&text=Imagen+de+cabecera+(1920+x+1440+px)',
'width' => 1920,
'height' => 1440,
'header-text' => false,
'uploads' => true
);
add_theme_support( 'custom-header', $header_args );
/**
* GobCL - Opciones del Tema
* Fuente: https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Using-CMB-to-create-an-Admin-Theme-Options-Page
* @version 0.1.0
*/
function update_cmb_meta_box_url( $url ) {
// Actualizamos url de metabox
return get_template_directory_uri().'/lib/metabox/';
}
class gobcl_Admin {
/**
* Option key, and option page slug
* @var string
*/
private $key = 'gobcl_options';
/**
* Array of metaboxes/fields
* @var array
*/
protected $option_metabox = array();
/**
* Options Page title
* @var string
*/
protected $title = '';
/**
* Options Page hook
* @var string
*/
protected $options_page = '';
/**
* Constructor
* @since 0.1.0
*/
public function __construct() {
// Set our title
$this->title = __( 'Opciones del Tema', 'gobcl' );
}
/**
* Initiate our hooks
* @since 0.1.0
*/
public function hooks() {
add_action( 'admin_init', array( $this, 'init' ) );
add_action( 'admin_menu', array( $this, 'add_options_page' ) );
}
/**
* Register our setting to WP
* @since 0.1.0
*/
public function init() {
register_setting( $this->key, $this->key );
}
/**
* Add menu options page
* @since 0.1.0
*/
public function add_options_page() {
$this->options_page = add_menu_page( $this->title, $this->title, 'manage_options', $this->key, array( $this, 'admin_page_display' ) );
}
/**
* Admin page markup. Mostly handled by CMB
* @since 0.1.0
*/
public function admin_page_display() {
?>
<div class="wrap cmb_options_page <?php echo $this->key; ?>">
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
<?php cmb_metabox_form( self::option_fields(), $this->key ); ?>
</div>
<?php
}
/**
* Defines the theme option metabox and field configuration
* @since 0.1.0
* @return array
*/
public function option_fields() {
// Only need to initiate the array once per page-load
if ( ! empty( $this->option_metabox ) ) {
return $this->option_metabox;
}
$prefix = '_gobcl_';
// Acá agregamos los campos de Opciones del Tema
// field types: https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Field-Types
$this->fields = array(
/* Fields Sidebar */
// Redes Sociales
array(
'id' => $prefix . 'lista_redes',
'type' => 'group',
'name' => 'Sidebar: Redes Sociales',
'description' => __( 'URLs de Perfiles de redes sociales', 'gobcl' ),
'options' => array(
'group_title' => __( 'Red {#}', 'gobcl' ), // {#} es reemplazado por el número de row
'add_button' => __( 'Añadir nueva red', 'gobcl' ),
'remove_button' => __( 'Quitar red', 'gobcl' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Activar Red',
'desc' => 'Activa o desactiva la red',
'id' => $prefix . 'activa_red',
'type' => 'checkbox'
),
array(
'name' => 'Redes Sociales',
'desc' => 'Selecciona una opción',
'id' => $prefix . 'redes',
'type' => 'select',
'options' => array(
'facebook' => __( 'Facebook', 'gobcl' ),
'twitter' => __( 'Twitter', 'gobcl' ),
'flickr' => __( 'Flickr', 'gobcl' ),
'youtube' => __( 'YouTube', 'gobcl' ),
'instagram' => __( 'Instagram', 'gobcl' ),
'pinterest' => __( 'Pinterest', 'gobcl' ),
'vimeo' => __( 'Vimeo', 'gobcl' ),
'linkedin' => __( 'LinkedIn', 'gobcl' ),
'slideshare' => __( 'SlideShare', 'gobcl' ),
'scribd' => __( 'Scribd', 'gobcl' ),
'soundcloud' => __( 'Soundcloud', 'gobcl' ),
),
'default' => 'facebook',
),
array(
'name' => 'Nombre de usuario',
'id' => 'user_red',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
array(
'name' => 'URL Perfil',
'id' => 'url_red',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
),
),
// Banners Sidebar
array(
'id' => $prefix . 'banners_sidebar',
'type' => 'group',
'name' => 'Sidebar: Banners Sidebar',
'description' => __( 'Banners sidebar, 320x100 px.', 'gobcl' ),
'options' => array(
'group_title' => __( 'Banner {#}', 'gobcl' ),
'add_button' => __( 'Añadir nuevo Banner', 'gobcl' ),
'remove_button' => __( 'Quitar Banner', 'gobcl' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Imagen Banner',
'id' => 'image_banner_sidebar',
'type' => 'file',
),
array(
'name' => 'URL Banner',
'description' => __( 'URL a la cual dirige el banner', 'gobcl' ),
'id' => 'url_banner_sidebar',
'type' => 'text_url',
'attributes' => array(
'placeholder' => 'Ej: http://www.gob.cl',
),
),
array(
'name' => 'Texto Alternativo Banner',
'description' => __( 'Requerido para lectores de pantalla', 'gobcl' ),
'id' => 'alt_text_banner_sidebar',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
),
),
/* Fields Home - Prefooter */
// Banner Wide Home
array(
'id' => $prefix . 'banner_wide',
'type' => 'group',
'name' => 'Home: Banner Wide',
'repeatable' => false,
'description' => __( 'Banner de 660x130px', 'gobcl' ),
'fields' => array(
array(
'name' => 'Imagen',
'description' => 'Imagen de 660x130 pixeles',
'id' => 'imagen_banner_wide',
'type' => 'file',
),
array(
'name' => 'Texto 1 banner',
'id' => 'texto_1_banner_wide',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
array(
'name' => 'Texto 2 banner',
'id' => 'texto_2_banner_wide',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
array(
'name' => 'URL Banner',
'description' => 'URL a la cual dirige el banner',
'id' => 'url_banner_wide',
'type' => 'text_url',
'attributes' => array(
'placeholder' => 'Ej: http://www.gob.cl',
),
),
),
),
// Cita destacada
array(
'id' => $prefix . 'cita_destacada',
'type' => 'group',
'name' => 'Home: Cita Destacada',
'repeatable' => false,
'description' => __( 'Cita destacada mostrado en el home del sitio', 'gobcl' ),
'fields' => array(
array(
'name' => 'Autor',
'id' => 'autor_cita',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
array(
'name' => 'Cargo autor',
'id' => 'cargo_autor_cita',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
array(
'name' => 'Texto',
'id' => 'texto_cita',
'type' => 'textarea_small',
'sanitization_cb' => 'stripslashes_deep'
),
array(
'name' => 'Información Cita',
'description' => 'Fecha, lugar, etc.',
'id' => 'info_cita',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
array(
'name' => 'URL Fuente Cita',
'description' => 'Fuente de la cita (opcional)',
'id' => 'url_cita',
'type' => 'text_url',
'attributes' => array(
'placeholder' => 'Ej: http://www.gob.cl',
),
),
),
),
// Lista Banners Pre-footer
array(
'id' => $prefix . 'banners_pre_footer',
'type' => 'group',
'name' => 'Home: Banners Sidebar',
'description' => __( 'Banners pre-footer, 320x100 px.', 'gobcl' ),
'options' => array(
'group_title' => __( 'Banner {#}', 'gobcl' ),
'add_button' => __( 'Añadir nuevo Banner', 'gobcl' ),
'remove_button' => __( 'Quitar Banner', 'gobcl' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Imagen Banner',
'id' => 'image_banner_pre_footer',
'type' => 'file',
),
array(
'name' => 'URL Banner',
'description' => __( 'URL a la cual dirige el banner', 'gobcl' ),
'id' => 'url_banner_pre_footer',
'type' => 'text_url',
'attributes' => array(
'placeholder' => 'Ej: http://www.gob.cl',
),
),
array(
'name' => 'Texto Alternativo Banner',
'description' => __( 'Requerido para lectores de pantalla', 'gobcl' ),
'id' => 'alt_text_banner_pre_footer',
'type' => 'text_medium',
'sanitization_cb' => 'stripslashes_deep'
),
),
),
/* Fields Home - Footer */
// Datos de contacto
array(
'name' => 'Datos de contacto',
'desc' => 'Dirección, teléfono, etc.',
'id' => $prefix . 'datos_contacto',
'type' => 'text',
'attributes' => array(
'placeholder' => 'Ej: Palacio de La Moneda - Teléfono: +56 2 26904000',
),
'sanitization_cb' => 'stripslashes_deep'
),
);
$this->option_metabox = array(
'id' => 'option_metabox',
'title' => __( 'Repeating Field Group', 'gobcl' ),
'show_on' => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
'show_names' => true,
'fields' => $this->fields,
);
return $this->option_metabox;
}
/**
* Public getter method for retrieving protected/private variables
* @since 0.1.0
* @param string $field Field to retrieve
* @return mixed Field value or exception is thrown
*/
public function __get( $field ) {
// Allowed fields to retrieve
if ( in_array( $field, array( 'key', 'fields', 'title', 'options_page' ), true ) ) {
return $this->{$field};
}
if ( 'option_metabox' === $field ) {
return $this->option_fields();
}
throw new Exception( 'Invalid property: ' . $field );
}
}
// Get it started
$gobcl_Admin = new gobcl_Admin();
$gobcl_Admin->hooks();
/**
* Wrapper function around cmb_get_option
* @since 0.1.0
* @param string $key Options array key
* @return mixed Option value
*/
function gobcl_get_option( $key = '' ) {
global $gobcl_Admin;
return cmb_get_option( $gobcl_Admin->key, $key );
}
// Metaboxes para el resto del tema
function gobcl_metaboxes( $meta_boxes ) {
$prefix = '_gobcl_'; // Prefix for all fields
$meta_boxes['page_titulo'] = array(
'id' => 'page_titulo',
'title' => 'Título páginas',
'desc' => 'field description (optional)',
'pages' => array('page'), // post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => 'Título Línea 1',
'id' => $prefix . 'titulo_1',
'type' => 'text_medium'
),
array(
'name' => 'Título Línea 2',
'id' => $prefix . 'titulo_2',
'type' => 'text_medium'
),
),
);
return $meta_boxes;
}
add_filter( 'cmb_meta_boxes', 'gobcl_metaboxes' );
add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 );
/**
* Initialize the metabox class.
*/
function cmb_initialize_cmb_meta_boxes() {
if ( ! class_exists( 'cmb_Meta_Box' ) )
require_once 'lib/metabox/init.php';
}
/**
* Helpers
*/
// Checkeamos existencia de par key => value en array multidimensional
function in_multiarray($array, $key, $val) {
foreach ($array as $item)
if (isset($item[$key]) && $item[$key] == $val)
return true;
return false;
}