-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
357 lines (325 loc) · 12.5 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
<?php
/**
* Functions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
* @link https://developer.wordpress.org/reference/functions/add_theme_support/
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
* @link https://developer.wordpress.org/themes/functionality/post-formats/
*
* @package ekiline
*/
/**
* Theme setup
*/
function ekiline_setup() {
// Traducciones // Translations can be filed in the /languages/ directory.
load_theme_textdomain( 'ekiline', get_template_directory() . '/languages' );
// Lector RSS // Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Metadatos: Titulo. // Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// Permitir miniaturas // Enable support for Post Thumbnails on posts and pages.
add_theme_support( 'post-thumbnails' );
// Permitir uso de HTML5 en formularios y marcado simple. // Switch default core markup for search form, comment form, and comments.
$html_def = array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style' );
add_theme_support( 'html5', $html_def );
// Formatos de entradas // Enable support for Post Formats.
$post_def = array( 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' );
add_theme_support( 'post-formats', $post_def );
// Color e imagen de fondo // Set up the WordPress core custom background feature.
// Reference: https://developer.wordpress.org/reference/functions/add_theme_support/?
$back_def = array(
'default-image' => '',
'default-color' => 'ffffff',
'wp-head-callback' => 'ekiline_custom_background_cb',
);
add_theme_support( 'custom-background', $back_def );
// Actualizacion de widgets en el personalizador // Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Menú, Ekiline solo necesita uno: ekiline_navbar_menu( 'primary' ) // This theme uses ekiline_navbar_menu( 'primary' ) as one location.
register_nav_menus(
array(
'primary' => esc_html__( 'Primary Menu', 'ekiline' ),
)
);
// Nuevo soporte logotipo.
$logo_args = array(
'height' => 50,
'width' => 200,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
'unlink-homepage-logo' => false,
);
add_theme_support( 'custom-logo', $logo_args );
}
add_action( 'after_setup_theme', 'ekiline_setup' );
/**
* Establecer el ancho de objetos (imagenes).
*
* @link https://codex.wordpress.org/Content_Width#Adding_Theme_Support
* @link https://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes
* @link https://wycks.wordpress.com/2013/02/14/why-the-content_width-wordpress-global-kinda-sucks/
*
* Heredar la medida de /wp-admin/options-media.php.
*/
if ( ! isset( $content_width ) ) {
$content_width = '';
}
/**
* Registrar widgets y sus areas // Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function ekiline_widgets_init() {
// Sidebar izquierdo y derecho. Default sidebar and right.
register_sidebar(
array(
'name' => esc_html__( 'Left sidebar', 'ekiline' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Right sidebar', 'ekiline' ),
'id' => 'sidebar-2',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
// Sidebar entre contenido y footer. Sidebar between content and footer.
register_sidebar(
array(
'name' => esc_html__( 'Bottom aside', 'ekiline' ),
'id' => 'footer-w2',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
)
);
// Widgets en footer. Footer widgets.
register_sidebar(
array(
'name' => esc_html__( 'Footer', 'ekiline' ),
'id' => 'footer-w1',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
)
);
// Widgets antes de todo el contenido. Widgets at top of content.
register_sidebar(
array(
'name' => esc_html__( 'Top before all content', 'ekiline' ),
'id' => 'toppage-w1',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<p class="widget-title">',
'after_title' => '</p>',
)
);
// Widgets antes y despues del contenido. Widgets before and after content.
register_sidebar(
array(
'name' => esc_html__( 'In page top content', 'ekiline' ),
'id' => 'content-w1',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<p class="lead font-weight-bold widget-title">',
'after_title' => '</p>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'In page bottom content', 'ekiline' ),
'id' => 'content-w2',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<p class="lead font-weight-bold widget-title">',
'after_title' => '</p>',
)
);
// Widgets en el navbar. Widgets in navbar.
register_sidebar(
array(
'name' => esc_html__( 'In navbar', 'ekiline' ),
'id' => 'navbar-w1',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<label class="widget-title screen-reader-text">',
'after_title' => '</label>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'In navbar menu', 'ekiline' ),
'id' => 'navbar-w2',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<label class="widget-title screen-reader-text">',
'after_title' => '</label>',
)
);
}
add_action( 'widgets_init', 'ekiline_widgets_init' );
/**
* Compatibilidad para wp_body_open
* Compatibility wp_body_open
*/
if ( ! function_exists( 'wp_body_open' ) ) {
/**
* Asegurar su uso WordPress anteriores a v 5.2.
*/
function wp_body_open() {
do_action( 'wp_body_open' );
}
}
/**
* Agregar a wp_body_open, area de widgets superior
* Add widget area at top of page.
*/
function ekiline_top_page_widget_area() {
dynamic_sidebar( 'toppage-w1' );
}
add_action( 'wp_body_open', 'ekiline_top_page_widget_area', 1 );
/**
* Funcion: Obtener contenido entre 2 strings.
* Se ocupo en los estilos, y puede ser necesario posteriormente.
* Ej: ekiline_get_string_between( $data, '[ekiline-atfcss-start]', '[ekiline-atfcss-end]' );
*
* @param string $string contenido.
* @param string $start elemento de abertura.
* @param string $end elemento de cierre.
*/
function ekiline_get_string_between( $string, $start, $end ) {
// Verificar la existencia de strings.
$find_start = strpos( $string, $start );
$find_end = strpos( $string, $end );
// Extraer el contenido.
if ( false !== $find_start && false !== $find_end ) {
$extract = explode( $start, $string );
$extract = explode( $end, $extract[1] );
return $extract[0];
}
}
/**
* Estilos css, above the fold.
* Obtener los estilos de un css e imprimirlos en el head,
* debe aparecer al principio de cualquier css (0).
*/
function ekiline_above_fold_styles() {
// Estilos.
$file = get_template_directory_uri() . '/assets/css/style-atf.css';
$file = wp_remote_get( $file );
$data = wp_remote_retrieve_body( $file );
// Quitar comentarios.
$data = preg_replace( '#/\*.*?\*/#s', '', $data );
// Quitar saltos de linea y convertir en un string.
$data = wp_strip_all_tags( $data, true );
wp_register_style( 'ekiline-atf', false, '', '2.0', 'all' );
wp_enqueue_style( 'ekiline-atf' );
if ( $data ) {
wp_add_inline_style( 'ekiline-atf', $data );
}
}
add_action( 'wp_enqueue_scripts', 'ekiline_above_fold_styles', 0 );
/**
* Estilos CSS // Javascript // Js con argumentos
*
* @link https://developer.wordpress.org/reference/functions/wp_enqueue_style/
* @link https://developer.wordpress.org/reference/functions/wp_enqueue_script/
* @link https://developer.wordpress.org/reference/functions/wp_script_add_data/
* @link https://developer.wordpress.org/resource/dashicons/
*/
function ekiline_scripts() {
// Estilos.
wp_enqueue_style( 'bootstrap-style', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '5', 'all' );
wp_enqueue_style( 'ekiline-style', get_stylesheet_uri(), array( 'bootstrap-style' ), '5', 'all' );
wp_enqueue_style( 'dashicons' );
// Scripts.
wp_enqueue_script( 'bootstrap-script', get_template_directory_uri() . '/assets/js/bootstrap.bundle.min.js', array(), '5', true );
wp_enqueue_script( 'ekiline-layout', get_template_directory_uri() . '/assets/js/ekiline.js', array( 'bootstrap-script' ), '20151226', true );
// Comentarios.
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// 2022 Mejora, organizar todos los estilos css y js, acorde al tema.
wp_styles()->add_data( 'ekiline-style', 'before', array() );
wp_scripts()->add_data( 'ekiline-layout', 'before', array() );
}
add_action( 'wp_enqueue_scripts', 'ekiline_scripts', 1 );
/**
* Ekiline ocupa varios modulos con estilos en linea, se agrupan en una sola cadena
* https://digwp.com/2009/09/wordpress-action-hooks/
* A) Dependiente de un estilo realizado como variable
* B) Invasivo, directo con etiqueta en head
* cada nuevo estilo en linea se agrega con: add_action( 'group_inline_css', 'new_style', 0/100 );
*/
function ekiline_group_inline_css_stored() {
ob_start(); // inicia captura de datos.
do_action( 'group_inline_css' ); // accion predeterminada.
$stored_value = ob_get_contents(); // capturar los datos en una variable.
ob_end_clean(); // finalizar la captura.
// Quitar comentarios.
$stored_value = preg_replace( '#/\*.*?\*/#s', '', $stored_value );
// Quitar saltos de linea y convertir en un string.
$stored_value = wp_strip_all_tags( $stored_value, true );
return $stored_value; // variable.
}
/**
* En caso de declarar como dependencia ocupar:
* function ekiline_inline_css_handled() {
* wp_add_inline_style( 'ekiline-style', ekiline_group_inline_css_stored() );
* }
* add_action( 'wp_enqueue_scripts', 'ekiline_inline_css_handled' );
*/
function ekiline_inline_css_tag() {
$type_attr = current_theme_supports( 'html5', 'style' ) ? ' ' : ' type="text/css" ';
// Se declaran como estilo unico en linea.
printf(
'<style%1$sid="ekiline-style-inline-css">%2$s</style>' . "\n",
wp_kses_post( $type_attr ),
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_strip_all_tags( ekiline_group_inline_css_stored() )
);
}
add_action( 'wp_head', 'ekiline_inline_css_tag', 100 );
/* Ekiline adiciones */
require get_template_directory() . '/inc/class-ekiline-nav-menu.php';
require get_template_directory() . '/inc/class-ekiline-control-multiple-select.php';
require get_template_directory() . '/inc/class-ekiline-basic-breadcrumb.php';
/* Ekiline modificadores de tema */
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/theme-customcolors.php';
require get_template_directory() . '/inc/theme-navbars.php';
require get_template_directory() . '/inc/theme-layout.php';
require get_template_directory() . '/inc/theme-elements.php';
require get_template_directory() . '/inc/theme-meta.php';
require get_template_directory() . '/inc/theme-customheader.php';
/* Ekiline optimizacion */
require get_template_directory() . '/inc/theme-optimizescripts.php';
/* Ekiline Block Editor */
require get_template_directory() . '/inc/theme-blockeditor.php';
/* Ekiline info admin */
require get_template_directory() . '/inc/info.php';
/* Ekiline Compatibilidad */
require get_template_directory() . '/inc/setup-jetpack.php';
require get_template_directory() . '/inc/setup-woocommerce.php';