-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
511 lines (445 loc) · 16.4 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
<?php
// Register Custom Navigation Walker
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
//require get_template_directory() . "/vendor/autoload.php";
function loadFiles(){
wp_deregister_script('jquery');
wp_enqueue_script('jquery', 'https://code.jquery.com/jquery-1.12.4.min.js', array(), '1.12.4', true);
wp_enqueue_script('bootstrap.js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js', 'jquery', '1.0', true);
wp_enqueue_script('flexisel.js', get_theme_file_uri('/js/jquery.flexisel.js'), 'jquery', '1.0', true);
wp_enqueue_script('script.js', get_theme_file_uri('/js/script.js'), 'jquery', '1.0', true);
// wp_enqueue_script('popper.js', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js', 'jquery', '1.0', true);
wp_enqueue_style('estilo', get_template_directory_uri() . '/estilo.css?v=20220420');
wp_dequeue_style('wp-block-library');
wp_localize_script(
'script.js',
'wpAjax',
array('ajaxUrl' => admin_url('admin-ajax.php'))
);
// INSERE A MÁSCARA DE CPF "00000-000"
wp_enqueue_script('jquery_mask', 'https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js');
}
@ini_set('upload_max_size', '64M');
@ini_set('post_max_size', '64M');
@ini_set('max_execution_time', '300');
add_action('wp_enqueue_scripts', 'loadFiles');
function escoteirosFeatures(){
register_nav_menu('MovimentoEscoteiro', 'Movimento Escoteiro');
register_nav_menu('OQueFazemos', 'O que fazemos');
register_nav_menu('Informacoes', 'Informações');
register_nav_menu('FaleConosco', 'Fale Conosco');
add_theme_support('custom-logo', ['width' => '275']);
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
}
add_action('after_setup_theme', 'escoteirosFeatures');
function logo_size_change(){
remove_theme_support( 'custom-logo' );
add_theme_support( 'custom-logo', array(
'height' => 100,
'width' => 400,
'flex-height' => true,
'flex-width' => true,
) );
}
add_action( 'after_setup_theme', 'logo_size_change', 11 );
// CUSTOM SIZE IMAGES
function pw_add_image_sizes(){
add_image_size('pw-mini', 50, 50, false);
add_image_size('pw-mega', 300, 300, false);
add_image_size('pw-banner', 1110, 700, false);
}
add_action('init', 'pw_add_image_sizes');
function pw_show_image_sizes($sizes){
$sizes['pw-mini'] = __('Custom mini');
$sizes['pw-mega'] = __('Custom Mega');
$sizes['pw-banner'] = __('Custom Banner');
return $sizes;
}
add_filter('image_size_names_choose', 'pw_show_image_sizes');
//NEW FILE FORMATS
function my_myme_types($mime_types){
$mime_types['eps'] = 'application/postscript';
return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);
function add_additional_class_on_li($classes, $item, $args){
if ($args->add_li_class) {
$classes[] = $args->add_li_class;
}
return $classes;
}
add_filter('nav_menu_css_class', 'add_additional_class_on_li', 1, 3);
if (function_exists('acf_add_options_page')){
acf_add_options_page(array(
'page_title' => 'Configurações Gerais',
'menu_title' => 'Configurações Gerais',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
define('WPSL_MARKER_URI', dirname(get_bloginfo('stylesheet_url')) . '/wpsl-markers/');
add_filter('wpsl_admin_marker_dir', 'custom_admin_marker_dir');
function custom_admin_marker_dir(){
$admin_marker_dir = get_stylesheet_directory() . '/wpsl-markers/';
return $admin_marker_dir;
}
function escoteiros_custom_search_input($search){
$search = isset($_GET['cep']) ? esc_attr($_GET['cep']) : '';
return $search;
}
add_filter('wpsl_search_input', 'escoteiros_custom_search_input', 999, 1);
add_filter('get_the_archive_title', 'rvfa_product_archive_title');
function rvfa_product_archive_title($title){
if (is_post_type_archive('especialidade')) $title = 'Especialidades';
if (is_post_type_archive('materia')) $title = 'Matérias';
if (is_post_type_archive('noticia')) $title = 'Notícias';
if (is_post_type_archive('evento')) $title = 'Eventos';
if (is_post_type_archive('projeto')) $title = 'Projetos Institucionais';
if (is_post_type_archive('download')) $title = 'Downloads';
if (is_post_type_archive('relatorio')) $title = 'Relatórios';
if (is_post_type_archive('convenio')) $title = 'Convênios';
return $title;
}
function custom_menu_order($menu_ord){
if (!$menu_ord) return true;
return array(
'index.php', // this represents the dashboard link
'edit.php?post_type=page',
'edit.php?post_type=noticias',
'edit.php?post_type=materia',
'edit.php?post_type=evento',
'edit.php?post_type=diretoria-conselho',
'edit.php?post_type=relatorio',
'edit.php?post_type=especialidade',
'edit.php?post_type=download',
'edit.php?post_type=projeto',
'edit.php?post_type=convenio',
'edit.php?post_type=wpsl_stores',
'edit.php', // this is the default POST admin menu
);
}
add_filter('custom_menu_order', 'custom_menu_order');
add_filter('menu_order', 'custom_menu_order');
add_action('wp_ajax_nopriv_filter', 'filter_ajax');
add_action('wp_ajax_filter', 'filter_ajax');
function filter_ajax()
{
$category = $_POST['category'];
$taxonomy = $_POST['taxonomy'];
$pagina = $_POST['page'];
$tipoPost = $_POST['tipo'];
if (isset($_GET["item"])) {
var_dump($_GET["item"]);
die;
}
if ($tipoPost == "download" && $category == ""){
?>
<script>
$(document).ready(function() {
$("#emptyContainer").hide();
$("#firstPageContainer").show();
})
</script>
<?php
} else {
?>
<script>
$(document).ready(function() {
$("#emptyContainer").show();
$("#firstPageContainer").hide();
})
</script>
<?php
}
if ($category) {
switch ($tipoPost) {
case "evento":
if ($category == "eventos-passados") {
$dataAtualPre = explode("-", date('Y-m-d'));
$dataAtual = $dataAtualPre[0] . "-" . $dataAtualPre[1] . "-" . $dataAtualPre[2];
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
'meta_query' => array(
'key' => 'data_fim_evento',
'compare' => '<',
'value' => $dataAtual,
'type' => 'DATE',
),
'meta_key' => 'data_evento',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
} else {
$dataAtualPre = explode("-", date('Y-m-d'));
$dataAtual = $dataAtualPre[0] . $dataAtualPre[1] . $dataAtualPre[2];
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $category
)
),
'meta_query' => array(
'key' => 'data_evento',
'compare' => '>=',
'value' => $dataAtual,
'type' => 'numeric',
),
'meta_key' => 'data_evento',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
}
break;
case "especialidade":
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $category
)
),
'orderby' => 'post_title',
'order' => 'ASC',
);
break;
case 'download':
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $category
)
),
'orderby' => 'date',
'order' => 'DESC'
);
break;
default:
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $category
)
),
);
}
} else {
if ($tipoPost == "especialidade"){
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
'orderby' => 'post_title',
'order' => 'ASC',
);
} else if ($tipoPost == "noticias"){
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
'orderby' => 'post_date',
'order' => 'DESC',
);
} else if ($tipoPost == "evento"){
$dataAtualPre = explode("-", date('Y-m-d'));
$dataAtual = $dataAtualPre[0] . $dataAtualPre[1] . $dataAtualPre[2];
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
'meta_query' => array(
'key' => 'data_fim_evento',
'compare' => '>=',
'value' => $dataAtual,
'type' => 'numeric',
),
'meta_key' => 'data_evento',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
} else if ($tipoPost == "download") {
$args = array();
} else
$args = array(
'post_type' => $tipoPost,
'paged' => $pagina,
);
}
$query = new WP_Query($args);
if ($tipoPost == "noticias" && $category != "") {
?>
<script>
$("#noticiasDestaque").hide();
</script>
<?php
}
if ($tipoPost == "noticias" && $category == "") {
?>
<script>
$("#noticiasDestaque").show();
</script>
<?php
}
if ($query->have_posts()) :
$cont = 0;
while ($query->have_posts()) :
$query->the_post();
if ($tipoPost == 'evento') {
include('include-card-eventos.php');
}
if ($tipoPost == 'projeto'){
include('include-card-projetos.php');
}
if ($tipoPost == 'noticias' && $category == "") {
$taxonomies = get_taxonomies('', 'names');
$eDestaque = false;
$arrayTax = wp_get_post_terms(get_the_ID(), $taxonomies);
foreach ($arrayTax as $tax) {
if ($tax->name == "Destaque") {
$eDestaque = true;
}
}
if ($cont < 6 && $eDestaque) {
$cont++;
} else
include('include-card-noticias.php');
} else if ($tipoPost == 'noticias' && $category != "") {
include('include-card-noticias.php');
}
if ($tipoPost == 'download') {
include('include-card-download.php');
}
if ($tipoPost == 'especialidade'){
include('include-card-especialidade.php');
}
?>
<span class="pages" data-max-page="<?php echo $query->max_num_pages; ?>"></span>
<?php
endwhile;
endif;
wp_reset_postdata();
die();
}
// APRESENTA O CARROSEL DE DEPOIMENTOS 1 A 1 NO MOBILE
function wp_mobile_carrousel(){
if(is_front_page()):
?>
<script type="text/javascript">
$(document).ready(function() {
if (screen.width < 780){
$(".carouselMobile").show();
$(".carouselDesktop").hide();
$(".destaquesMobile").show();
$(".destaquesDesktop").hide();
}
});
</script>
<?php
endif;
}
add_action('wp_head', 'wp_mobile_carrousel');
// EXCLUI O BREADCRUMB DE ÁREA DE ESPECIALIDADE
function my_breadcrumb_title_swapper($term, $id, $type, $taxonomy){
if ("Area" != $taxonomy){
return $term;
}
}
add_filter('bcn_pick_post_term', 'my_breadcrumb_title_swapper', 3, 10);
function projetos_register_post_type(){
register_post_type(
'projeto',
array(
'labels' => array(
'name' => __('Portfólio'),
'singular_name' => __('portfolios')
),
'public' => true,
'has_archive' => true,
'rewrite' => array(
'slug' => 'portfolio'
)
)
);
} // end example_register_post_type
add_filter('login_errors', function($error){ return null; });
//add_filter('login_errors', '__return_false');
add_action('init', 'projetos_register_post_type');
add_filter('projetos-type_post_type_args', '_my_rewrite_slug'); // Here replace "your-post-type" with the actual post type, e.g., "cherry_services", "cherry-projects"
function _my_rewrite_slug($args){
$args['rewrite']['slug'] = 'portfolio'; // Replace "our-services" with your preferable slug
return $args;
}
#region seguranca
// remove version from head
remove_action('wp_head', 'wp_generator');
// remove version from rss
add_filter('the_generator', '__return_empty_string');
// remove version from scripts and styles
function ueb_remove_version_scripts_styles($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'ueb_remove_version_scripts_styles', 9999);
add_filter('script_loader_src', 'ueb_remove_version_scripts_styles', 9999);
function ueb_template_redirect(){
if(is_author() || is_attachment()){
wp_safe_redirect(home_url());
exit();
}
}
add_action('template_redirect', 'ueb_template_redirect');
function ueb_desabilida_comentarios_midia( $open, $post_id ) {
$post = get_post( $post_id );
if( $post->post_type == 'attachment' ) {
return false;
}
return $open;
}
add_filter('comments_open', 'ueb_desabilida_comentarios_midia', 10, 2);
#endregion
function ueb_remover_bar_itens($wp_admin_bar){
$wp_admin_bar->remove_node('comments');
$wp_admin_bar->remove_node('new-post');
}
add_action('admin_bar_menu', 'ueb_remover_bar_itens', 999);
function ueb_remover_menus(){
remove_menu_page( 'edit.php' );
remove_menu_page( 'edit-comments.php');
//if(wp_get_environment_type() !== 'development'){
// remove_menu_page('edit.php?post_type=acf-field-group');
//}
}
add_action('admin_menu', 'ueb_remover_menus');
/*function ueb_config_acf(){
if(wp_get_environment_type() !== 'development'){
add_filter('acf/settings/show_admin', '__return_false');
}
}
add_action('acf/init', 'ueb_config_acf');*/
add_filter( 'ure_role_additional_options', 'add_prohibit_access_to_admin_option', 10, 1 );
function add_prohibit_access_to_admin_option($items) {
$item = URE_Role_Additional_Options::create_item( 'prohibit_admin_access', esc_html__('Prohibit access to admin', 'user-role-editor'), 'init', 'prohibit_access_to_admin' );
$items[$item->id] = $item;
return $items;
}
function prohibit_access_to_admin() {
if ( is_admin() && !wp_doing_ajax() ) {
wp_redirect( get_home_url() );
}
}