-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
212 lines (180 loc) · 6.37 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
<?php
if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
define( 'GUTENBERG_SLUG', 'gym-theme' );
add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup ()
{
/** post thumbnail **/
add_theme_support( 'post-thumbnails' );
/** Gutenberg support **/
add_theme_support( 'align-wide' );
}
/** Crear categoría personalizada de bloques **/
add_filter( 'block_categories', 'gymTheme_categoria_personalizada', 10, 2 );
function gymTheme_categoria_personalizada ( $categories, $post )
{
$block_category = array(
'title' => esc_html__( 'Módulos del Tema' ),
'slug' => GUTENBERG_SLUG
);
$category_slugs = wp_list_pluck( $categories, 'slug' );
if ( !in_array( $block_category['slug'], $category_slugs, true ) ) {
$categories = array_merge(
$categories,
array(
array(
'title' => $block_category['title'], // Required
'slug' => $block_category['slug'], // Required
'icon' => null, // Slug of a WordPress Dashicon or custom SVG
//Si se hace un custom SVG se tiene que importar por React
),
)
);
}
return $categories;
}
/** Eliminamos la opcion del modo pantalla completa **/
add_action( 'enqueue_block_editor_assets', 'disable_fullScreen_default' );
function disable_fullScreen_default ()
{
$script = "window.onload = function() { const isFullscreenMode = wp.data.select( 'core/edit-post' ).isFeatureActive( 'fullscreenMode' ); if ( isFullscreenMode ) { wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'fullscreenMode' ); } }";
wp_add_inline_script( 'wp-blocks', $script );
}
/**Registrar bloques, scripts, CSS**/
add_action( 'init', 'gymTheme_registrar_bloques' );
function gymTheme_registrar_bloques ()
{
//Si gutemberg no existe, salir
if ( !function_exists( 'register_block_type' ) ) {
return;
}
//Registrar los bloques en el editor
wp_register_script(
'gymTheme-editor-script',//handle
get_template_directory_uri() . '/build/index.js',//Archivo con los bloques compilados
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), //Dependencias de gutemberg
filemtime( get_template_directory() . '/build/index.js' ) //Para que siempre nos traiga la ultima version y no haya problemas de cache
);
//Estilos para el editor (unicamente)
wp_register_style(
'gymTheme-editor-styles',
get_template_directory_uri() . '/css/editor.css',
array( 'wp-edit-blocks' ), //Dependencias
filemtime( get_template_directory() . '/css/editor.css' )
);
//Estilos para los bloques back y front
wp_register_style(
'gymTheme-frontend-styles',
get_template_directory_uri() . '/css/styles.css',
array( 'gymTheme-fonts' ), //Dependencias
filemtime( get_template_directory() . '/css/styles.css' )
);
wp_register_style(
'gymTheme-fonts',
'https://fonts.googleapis.com/css?family=Open+Sans%7CRaleway%3A400%2C700%2C900%7CStaatliches&amp;display=swap&amp;ver=1.0.0',
array(),
null
);
//Arreglo de bloques NO Dinamicos
$blocks = array(
// 'gymTheme/boxes', //Que tenga el mismo nombre que el bloque de la carpeta /src (recomendacion)
GUTENBERG_SLUG . '/hero',
GUTENBERG_SLUG . '/text',
GUTENBERG_SLUG . '/section-areas'
);
//Recorrer bloques y agregar scripts y styles
foreach ( $blocks as $block ) {
register_block_type(
$block,
array(
'editor_script' => 'gymTheme-editor-script', //Script principal para el editor
'editor_style' => 'gymTheme-editor-styles', // Estilo para el editor
'style' => 'gymTheme-frontend-styles' //Estilo para el frontend
)
);
}
wp_localize_script(
'gymTheme-editor-script',
'test',
[ 'can_see' => false ]
);
// /* Registrar bloques dinámicos*/
// register_block_type( 'gymTheme/menu', array(
// 'editor_script' => 'gymTheme-editor-script', //Script principal para el editor
// 'editor_style' => 'gymTheme-editor-styles', // Estilo para el editor
// 'style' => 'gymTheme-frontend-styles', //Estilo para el frontend
// // Si es un bloque dinámico creado por php hay que establecer aqui los attributos por defecto
// // Si en el admin se guardan los atributos por defecto estos no se van a enviar al lado servidor
// // https://github.com/WordPress/gutenberg/issues/6187
// 'attributes' => array(
// 'cantidadMostrar' => array(
// 'type' => 'number',
// 'default' => 4
// ),
// 'tituloBloque' => array(
// 'type' => 'string',
// 'default' => 'Título Bloque Server'
// )
// ),
// 'render_callback' => 'gymTheme_especialidades_front_end' // Función que hará la llamada a la BBDD
// ) );
}
add_action( 'wp_enqueue_scripts', 'gymTheme_enqueue_styles_scripts' );
function gymTheme_enqueue_styles_scripts ()
{
wp_enqueue_style(
'gymTheme-bootstrap',
get_template_directory_uri() . '/css/bootstrap.min.css',
array(),
null
);
wp_enqueue_script( 'gymTheme-bootstrap',
get_template_directory_uri() . '/js/bootstrap.bundle.min.js',
array( 'jquery' ),
'4.5.0',
true
);
wp_enqueue_script( 'gymTheme-scripts',
get_template_directory_uri() . '/js/scripts.js',
array( 'jquery' ),
'1.0.0',
true
);
}
add_action( 'init', 'gymThmeme_menus' );
function gymThmeme_menus ()
{
register_nav_menus( array(
'header-menu' => 'Header Menu',
) );
}
require_once 'inc/customizer.php';
require_once 'inc/BootstrapWalker.php';
function test_taxonomy ()
{
$labels = array(
'name' => _x( 'Genres', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Genres', 'textdomain' ),
'all_items' => __( 'All Genres', 'textdomain' ),
'parent_item' => __( 'Parent Genre', 'textdomain' ),
'parent_item_colon' => __( 'Parent Genre:', 'textdomain' ),
'edit_item' => __( 'Edit Genre', 'textdomain' ),
'update_item' => __( 'Update Genre', 'textdomain' ),
'add_new_item' => __( 'Add New Genre', 'textdomain' ),
'new_item_name' => __( 'New Genre Name', 'textdomain' ),
'menu_name' => __( 'Genre', 'textdomain' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_in_rest' => true,//Necesario para que aparezca en el panel de gutenberg
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
'radio' => true,
);
register_taxonomy( 'genre', array( 'post' ), $args );
}
add_action( 'init', 'test_taxonomy', 0 );