-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
388 lines (298 loc) · 12.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
<?php
/*
Author: Clau Carrillo
*/
// LOAD BONES CORE (if you remove this, the theme will break)
define( 'SITEURL', site_url() . '/' );
define( 'THEMEPATH', get_template_directory_uri() . '/' );
define( 'IMAGEPATH', get_template_directory_uri() . '/library/images/' );
define( 'ASSETPATH', get_template_directory_uri() . '/library/assets/' );
require_once( 'library/_include.php' );
/*********************
LAUNCH BONES
Let's get everything up and running.
*********************/
function ahoy() {
//Allow editor style.
// add_editor_style( get_stylesheet_directory_uri() . '/library/css/editor-style.css' );
// USE THIS TEMPLATE TO CREATE CUSTOM POST TYPES EASILY
require_once( 'library/custom-post-types.php' );
// launching operation cleanup
add_action( 'init', 'head_cleanup' );
// A better title
add_filter( 'wp_title', 'rw_title', 10, 3 );
// remove WP version from RSS
add_filter( 'the_generator', 'rss_version' );
// remove pesky injected css for recent comments widget
add_filter( 'wp_head', 'remove_wp_widget_recent_comments_style', 1 );
// clean up comment styles in the head
add_action( 'wp_head', 'remove_recent_comments_style', 1 );
// clean up gallery output in wp
add_filter( 'gallery_style', 'gallery_style' );
// enqueue base scripts and styles
add_action( 'wp_enqueue_scripts', 'scripts_and_styles', 999 );
// ie conditional wrapper
// launching this stuff after theme setup
theme_support();
// adding sidebars to Wordpress (these are created in functions.php)
add_action( 'widgets_init', 'register_sidebars' );
// cleaning up random code around images
add_filter( 'the_content', 'filter_ptags_on_images' );
// cleaning up excerpt
add_filter( 'excerpt_more', 'excerpt_more' );
} /* end bones ahoy */
// let's get this party started
add_action( 'after_setup_theme', 'ahoy' );
/************* OEMBED SIZE OPTIONS *************/
if ( ! isset( $content_width ) ) {
$content_width = 680;
}
/************* THUMBNAIL SIZE OPTIONS *************/
// Thumbnail sizes
if ( function_exists('add_image_size') ){
add_image_size( 'product-thumb', 230, 145, true );
add_image_size( 'product-page', 520, 346, true );
// cambiar el tamaño del thumbnail
update_option( 'thumbnail_size_w', 300 );
update_option( 'thumbnail_size_h', 224 );
update_option( 'thumbnail_crop', true );
// cambiar el tamaño del medium
update_option( 'medium_size_w', 520 );
update_option( 'medium_size_h', 520 );
update_option( 'medium_crop', true );
// cambiar el tamaño del large
update_option( 'large_size_w', 698 );
update_option( 'large_size_h', 492 );
update_option( 'large_crop', true );
}
/*
to add more sizes, simply copy a line from above
and change the dimensions & name. As long as you
upload a "featured image" as large as the biggest
set width or height, all the other sizes will be
auto-cropped.
To call a different size, simply change the text
inside the thumbnail function.
For example, to call the 300 x 100 sized image,
we would use the function:
<?php the_post_thumbnail( 'bones-thumb-300' ); ?>
for the 600 x 150 image:
<?php the_post_thumbnail( 'bones-thumb-600' ); ?>
You can change the names and dimensions to whatever
you like. Enjoy!
*/
// add_filter( 'image_size_names_choose', 'custom_image_sizes' );
// function custom_image_sizes( $sizes ) {
// return array_merge( $sizes, array(
// 'bones-thumb-600' => __('600px by 150px'),
// 'bones-thumb-300' => __('300px by 100px'),
// ) );
// }
/*
The function above adds the ability to use the dropdown menu to select
the new images sizes you have just created from within the media manager
when you add media to your content blocks. If you add more image sizes,
duplicate one of the lines in the array and name it according to your
new image size.
*/
/************* THEME CUSTOMIZE *********************/
/*
A good tutorial for creating your own Sections, Controls and Settings:
http://code.tutsplus.com/series/a-guide-to-the-wordpress-theme-customizer--wp-33722
Good articles on modifying the default options:
http://natko.com/changing-default-wordpress-theme-customization-api-sections/
http://code.tutsplus.com/tutorials/digging-into-the-theme-customizer-components--wp-27162
To do:
- Create a js for the postmessage transport method
- Create some sanitize functions to sanitize inputs
- Create some boilerplate Sections, Controls and Settings
*/
/*
This is a modification of a function found in the
twentythirteen theme where we can declare some
external fonts. If you're using Google Fonts, you
can replace these fonts, change it in your scss files
and be up and running in seconds.
*/
function fonts() {
wp_enqueue_style('font', 'http://fast.fonts.net/cssapi/ba4e46bd-824b-4f0c-9d91-ce97008001a4.css');
}
add_action('wp_enqueue_scripts', 'fonts');
add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
function getMarkersMap(){
$region = (isset($_POST['region']) ? $_POST['region'] : '');
if(isset($_POST['region']) && !empty($_POST['region'])){
$args = array(
'post_type' => 'sucursal',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'region',
'field' => 'slug',
'terms' => $region,
),
)
);
}
else{
$args = array(
'post_type' => 'sucursal',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1
);
}
$sucursales_query = new WP_Query( $args );
$sucursales = array();
if ( $sucursales_query->have_posts() ) {
while ( $sucursales_query->have_posts() ) {
$sucursales_query->the_post();
$lat = get_post_meta( $sucursales_query->post->ID, '_suc_lat', true);
$lon = get_post_meta( $sucursales_query->post->ID, '_suc_lon', true);
$content = get_the_content();
$title = get_the_title();
if($lat!='' && $lon != ''){
$tipo = 'centros-de-atencion-a-clientes';
if(has_term( 'casas-maxcom', 'tipo' )){
$tipo = 'casas-maxcom';
}
$sucursales[$sucursales_query->post->ID] = array();
$sucursales[$sucursales_query->post->ID]['lat'] = $lat;
$sucursales[$sucursales_query->post->ID]['lon'] = $lon;
$sucursales[$sucursales_query->post->ID]['content'] = $content;
$sucursales[$sucursales_query->post->ID]['title'] = $title;
$sucursales[$sucursales_query->post->ID]['tipo'] = $tipo;
}
}
}
echo json_encode($sucursales);
die();
}
add_action('wp_ajax_getMarkersMap', 'getMarkersMap');
add_action('wp_ajax_nopriv_getMarkersMap', 'getMarkersMap');
function getFormDataCliente() {
$post_id = 0;
$success = false;
if(isset($_POST['nombre'])){
$nombre = sanitize_text_field( $_POST["nombre"] );
// $apellido = sanitize_text_field( $_POST["apellido"] );
$email = sanitize_email( $_POST["email"] );
$lada = sanitize_email( $_POST["lada"] );
$telefono = sanitize_text_field( $_POST["telefono"] );
$horario = sanitize_text_field( $_POST["horario"] );
$cuenta = sanitize_text_field( $_POST["no_cuenta"] );
$asunto = sanitize_text_field( $_POST["asunto"] );
$mensaje = sanitize_text_field( $_POST["mensaje"] );
$formtype = 'ya-soy-cliente';
// if( $formtype == 'servicio'){
// $content = 'Nombre: '.$nombre.' '.$apellido.'<br />'.
// 'Email: '.$email.'<br />'.
// 'Empresa: '.$empresa.'<br />'.
// 'Teléfono: '.$telefono.'<br />'.
// 'Calle: '.$calle.'<br />'.
// 'Colonia: '.$colonia.'<br />'.
// 'Pais: '.$pais.'<br />'.
// 'Estado: '.$estado.'<br />'.
// 'Ciudad: '.$ciudad.'<br />'.
// 'Código Postal: '.$codigopostal.'<br />'.
// 'País: '.$pais.'<br />'.
// 'Mensaje: '.$mensaje;
// $to = 'serviciotecnico@nexttec.com.mx';
// }
// else{
// $content = 'Nombre: '.$nombre.' '.$apellido.'<br />'.
// 'Email: '.$email.'<br />'.
// 'Teléfono: '.$telefono.'<br />'.
// 'Mensaje: '.$mensaje;
// $to = 'ventas@nexttec.com.mx';
}
// $headers = "MIME-Version: 1.0\r\n";
// $headers.= "Content-type: text/html; charset=utf-8\r\n";
// $headers.= "From: Hifin Formulario <claudia@elmamut.com>";
// // $headers = 'From: My Name <myname@example.com>' . "\r\n";
// $subject = ' Formulario'.' '.$nombre.' '.$apellido.'-'.$empresa;
// wp_mail( $to, $subject, $content, $headers );
// $post = array(
// 'post_content' => $content,
// 'post_title' => $subject.' '.date( 'Y-m-d H:i:s'),
// 'post_status' => 'private',
// 'post_type' => 'enviosformulario'
// );
// $post_id = wp_insert_post( $post );
// if($post_id) $success= true;
// wp_set_object_terms( $post_id, array($type), 'formulario', true );
// }
// wp_send_json( array('id'=> $post_id, 'success'=> $success));
die();
}
add_action('wp_ajax_getFormDataCliente', 'getFormDataCliente');
add_action('wp_ajax_nopriv_getFormDataCliente', 'getFormDataCliente');
function getFormDataProspecto() {
$post_id = 0;
$success = false;
if(isset($_POST['nombre'])){
$nombre = sanitize_text_field( $_POST["nombre"] );
// $apellido = sanitize_text_field( $_POST["apellido"] );
$email = sanitize_email( $_POST["email"] );
$lada = sanitize_email( $_POST["lada"] );
$telefono = sanitize_text_field( $_POST["telefono"] );
$horario = sanitize_text_field( $_POST["horario"] );
$calle = sanitize_text_field( $_POST["calle"] );
$numext = sanitize_text_field( $_POST["ext"] );
$numint = sanitize_text_field( $_POST["int"] );
$entre = sanitize_text_field( $_POST["entre-calles"] );
$colonia = sanitize_text_field( $_POST["colonia"] );
$codigopostal= sanitize_text_field( $_POST["cp"] );
$delegacion = sanitize_text_field( $_POST["delegacion"] );
$entidad = sanitize_text_field( $_POST["entidad"] );
$mensaje = esc_textarea( $_POST["mensaje"] );
$formtype = 'quiero-ser-cliente';
// if( $formtype == 'servicio'){
// $content = 'Nombre: '.$nombre.' '.$apellido.'<br />'.
// 'Email: '.$email.'<br />'.
// 'Empresa: '.$empresa.'<br />'.
// 'Teléfono: '.$telefono.'<br />'.
// 'Calle: '.$calle.'<br />'.
// 'Colonia: '.$colonia.'<br />'.
// 'Pais: '.$pais.'<br />'.
// 'Estado: '.$estado.'<br />'.
// 'Ciudad: '.$ciudad.'<br />'.
// 'Código Postal: '.$codigopostal.'<br />'.
// 'País: '.$pais.'<br />'.
// 'Mensaje: '.$mensaje;
// $to = 'serviciotecnico@nexttec.com.mx';
// }
// else{
// $content = 'Nombre: '.$nombre.' '.$apellido.'<br />'.
// 'Email: '.$email.'<br />'.
// 'Teléfono: '.$telefono.'<br />'.
// 'Mensaje: '.$mensaje;
// $to = 'ventas@nexttec.com.mx';
}
// $headers = "MIME-Version: 1.0\r\n";
// $headers.= "Content-type: text/html; charset=utf-8\r\n";
// $headers.= "From: Hifin Formulario <claudia@elmamut.com>";
// // $headers = 'From: My Name <myname@example.com>' . "\r\n";
// $subject = ' Formulario'.' '.$nombre.' '.$apellido.'-'.$empresa;
// wp_mail( $to, $subject, $content, $headers );
// $post = array(
// 'post_content' => $content,
// 'post_title' => $subject.' '.date( 'Y-m-d H:i:s'),
// 'post_status' => 'private',
// 'post_type' => 'enviosformulario'
// );
// $post_id = wp_insert_post( $post );
// if($post_id) $success= true;
// wp_set_object_terms( $post_id, array($type), 'formulario', true );
// }
// wp_send_json( array('id'=> $post_id, 'success'=> $success));
die();
}
add_action('wp_ajax_getFormDataProspecto', 'getFormDataProspecto');
add_action('wp_ajax_nopriv_getFormDataProspecto', 'getFormDataProspecto');
/* DON'T DELETE THIS CLOSING TAG */ ?>