-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions2.php
654 lines (548 loc) · 18.9 KB
/
functions2.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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
<?php
/**
* Odin functions and definitions.
*
* Sets up the theme and provides some helper functions, which are used in the
* theme as custom template tags. Others are attached to action and filter
* hooks in WordPress to change core functionality.
*
* For more information on hooks, actions, and filters,
* see http://codex.wordpress.org/Plugin_API
*
* @package Odin
* @since 2.2.0
*/
/**
* Sets content width.
*/
if ( ! isset( $content_width ) ) {
$content_width = 600;
}
/**
* Odin Classes.
*/
require_once get_template_directory() . '/core/classes/class-bootstrap-nav.php';
require_once get_template_directory() . '/core/classes/class-shortcodes.php';
require_once get_template_directory() . '/core/classes/class-thumbnail-resizer.php';
require_once get_template_directory() . '/core/classes/class-theme-options.php';
require_once get_template_directory() . '/core/classes/class-options-helper.php';
require_once get_template_directory() . '/core/classes/class-post-type.php';
require_once get_template_directory() . '/core/classes/class-taxonomy.php';
// require_once get_template_directory() . '/core/classes/class-metabox.php';
// require_once get_template_directory() . '/core/classes/abstracts/abstract-front-end-form.php';
// require_once get_template_directory() . '/core/classes/class-contact-form.php';
// require_once get_template_directory() . '/core/classes/class-post-form.php';
// require_once get_template_directory() . '/core/classes/class-user-meta.php';
/**
* Odin Widgets.
*/
require_once get_template_directory() . '/core/classes/widgets/class-widget-like-box.php';
if ( ! function_exists( 'odin_setup_features' ) ) {
/**
* Setup theme features.
*
* @since 2.2.0
*
* @return void
*/
function odin_setup_features() {
/**
* Add support for multiple languages.
*/
load_theme_textdomain( 'odin', get_template_directory() . '/languages' );
/**
* Register nav menus.
*/
register_nav_menus(
array(
'main-menu' => __( 'Main Menu', 'odin' )
)
);
/*
* Add post_thumbnails suport.
*/
add_theme_support( 'post-thumbnails' );
/**
* Add feed link.
*/
add_theme_support( 'automatic-feed-links' );
/**
* Support Custom Header.
*/
$default = array(
'width' => 0,
'height' => 0,
'flex-height' => false,
'flex-width' => false,
'header-text' => false,
'default-image' => '',
'uploads' => true,
);
add_theme_support( 'custom-header', $default );
/**
* Support Custom Background.
*/
$defaults = array(
'default-color' => '',
'default-image' => '',
);
add_theme_support( 'custom-background', $defaults );
/**
* Support Custom Editor Style.
*/
add_editor_style( 'assets/css/editor-style.css' );
/**
* Add support for infinite scroll.
*/
add_theme_support(
'infinite-scroll',
array(
'type' => 'scroll',
'footer_widgets' => false,
'container' => 'content',
'wrapper' => false,
'render' => false,
'posts_per_page' => get_option( 'posts_per_page' )
)
);
/**
* Add support for Post Formats.
*/
// add_theme_support( 'post-formats', array(
// 'aside',
// 'gallery',
// 'link',
// 'image',
// 'quote',
// 'status',
// 'video',
// 'audio',
// 'chat'
// ) );
/**
* Support The Excerpt on pages.
*/
// add_post_type_support( 'page', 'excerpt' );
}
}
add_action( 'after_setup_theme', 'odin_setup_features' );
/**
* Register widget areas.
*
* @since 2.2.0
*
* @return void
*/
function odin_widgets_init() {
register_sidebar(
array(
'name' => __( 'Main Sidebar', 'odin' ),
'id' => 'main-sidebar',
'description' => __( 'Site Main Sidebar', 'odin' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widgettitle widget-title">',
'after_title' => '</h3>',
)
);
}
add_action( 'widgets_init', 'odin_widgets_init' );
/**
* Flush Rewrite Rules for new CPTs and Taxonomies.
*
* @since 2.2.0
*
* @return void
*/
function odin_flush_rewrite() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'odin_flush_rewrite' );
/**
* Load site scripts.
*
* @since 2.2.0
*
* @return void
*/
function odin_enqueue_scripts() {
$template_url = get_template_directory_uri();
// Loads Odin main stylesheet.
wp_enqueue_style( 'odin-style', get_stylesheet_uri(), array(), null, 'all' );
// jQuery.
wp_enqueue_script( 'jquery' );
// Bootstrap.
wp_enqueue_script( 'bootstrap', $template_url . '/assets/js/libs/bootstrap.min.js', array(), null, true );
// General scripts.
// FitVids.
wp_enqueue_script( 'fitvids', $template_url . '/assets/js/libs/jquery.fitvids.js', array(), null, true );
// Main jQuery.
wp_enqueue_script( 'odin-main', $template_url . '/assets/js/main.js', array(), null, true );
// Grunt main file with Bootstrap, FitVids and others libs.
// wp_enqueue_script( 'odin-main-min', $template_url . '/assets/js/main.min.js', array(), null, true );
// Load Thread comments WordPress script.
if ( is_singular() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'odin_enqueue_scripts', 1 );
/**
* Odin custom stylesheet URI.
*
* @since 2.2.0
*
* @param string $uri Default URI.
* @param string $dir Stylesheet directory URI.
*
* @return string New URI.
*/
function odin_stylesheet_uri( $uri, $dir ) {
return $dir . '/assets/css/style.css';
}
add_filter( 'stylesheet_uri', 'odin_stylesheet_uri', 10, 2 );
/**
* Core Helpers.
*/
require_once get_template_directory() . '/core/helpers.php';
/**
* WP Custom Admin.
*/
require_once get_template_directory() . '/inc/admin.php';
/**
* Comments loop.
*/
require_once get_template_directory() . '/inc/comments-loop.php';
/**
* WP optimize functions.
*/
require_once get_template_directory() . '/inc/optimize.php';
/**
* WP Custom Admin.
*/
require_once get_template_directory() . '/inc/plugins-support.php';
/**
* Custom template tags.
*/
require_once get_template_directory() . '/inc/template-tags.php';
////////////////////////////////////////////////////////////////
////////////////Opcoes do tema////////////////
////////////////////////////////////////////////////////////////
$odin_theme_options = new Odin_Theme_Options(
'opcoes', // Slug/ID da página (Obrigatório)
__( 'Opções do tema', 'thea' ), // Titulo da página (Obrigatório)
'manage_options' // Nível de permissão (Opcional) [padrão é manage_options]
);
$odin_theme_options->set_tabs(
array(
array(
'id' => 'config', // ID da aba e nome da entrada no banco de dados.
'title' => __( 'Configurações', 'thea' ), // Título da aba.
),
array(
'id' => 'socials', // ID da aba e nome da entrada no banco de dados.
'title' => __( 'Social', 'thea' ), // Título da aba.
),
)
);
$odin_theme_options->set_fields(
array(
'config_section' => array(
'tab' => 'config', // Sessão da aba odin_general
'title' => __( 'Imagem de fundo', 'thea' ),
'fields' => array(
array(
'id' => 'bgimg', // Obrigatório
'label' => __( 'Imagem de fundo', 'thea' ), // Obrigatório
'type' => 'image', // Obrigatório
'default' => '', // Opcional (deve ser o id de uma imagem em mídia)
'description' => __( 'escolha aqui a imagem para o fundo do site', 'thea' ), // Opcional
),
// opção de cor
array(
'id' => 'cor', // Obrigatório
'label' => __( 'Cor principal', 'odin' ), // Obrigatório
'type' => 'color', // Obrigatório
// 'attributes' => array(), // Opcional (atributos para input HTML/HTML5)
'default' => '#ffffff', // Opcional (cor em hexadecimal)
'description' => __( 'Escolha a cor principal do site, ela ira afetar os escritos, a faixa do título, a linha do rodapé e os icones.', 'odin' ), // Opcional
),
array(
'id' => 'contato', // Obrigatório
'label' => __( 'Texto do formulario de contato', 'odin' ), // Obrigatório
'type' => 'text', // Obrigatório
// 'attributes' => array(), // Opcional (atributos para input HTML/HTML5)
)
)
),
'socials_section' => array(
'tab' => 'socials', // Sessão da aba odin_general
'title' => __( 'Redes Sociais', 'odin' ),
'fields' => array(
array(
'id' => 'facebook',
'label' => __( 'Facebook', 'odin' ),
'type' => 'text',
'default' => '',
),
array(
'id' => 'instagram',
'label' => __( 'Instagram', 'odin' ),
'type' => 'text'
),
)
),
)
);
function coloca_http($endereco){
$http = substr ($endereco, 0 , 4);
if ($http == 'http'){
return $endereco;
}
else {
return 'http://'.$endereco;
}
}
////////////////////////////////////////////////////////////////
////////////////Opcoes do tema////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////cor de hex para rgba////////////////
////////////////////////////////////////////////////////////////
function hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
$rgb = $r.','. $g.','.$b;
//return implode(",", $rgb); // returns the rgb values separated by commas
return $rgb; // returns an array with the rgb values
}
////////////////////////////////////////////////////////////////
////////////////cor de hex para rgba////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////font-awesome////////////////
////////////////////////////////////////////////////////////////
add_action('admin_init', 'prefix_enqueue_awesome');
add_action( 'wp_enqueue_scripts', 'prefix_enqueue_awesome' );
/**
* Register and load font awesome CSS files using a CDN.
*
* @link http://www.bootstrapcdn.com/#fontawesome
* @author FAT Media
*/
function prefix_enqueue_awesome() {
wp_enqueue_style( 'prefix-font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css', array(), '4.0.3' );
}
////////////////////////////////////////////////////////////////
////////////////font-awesome////////////////
////////////////////////////////////////////////////////////////
////////google-fonts
function load_fonts() {
wp_register_style('googleFonts', 'http://fonts.googleapis.com/css?family=Roboto:300');
wp_enqueue_style( 'googleFonts');
}
add_action('wp_print_styles', 'load_fonts');
//////////////////////google-fonts//////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////Custom post types////////////////
////////////////////////////////////////////////////////////////
////////////////Janela////////////////
function janela_cpt(){
$janela = new Odin_Post_Type(
'Janela', // Nome (Singular) do Post Type.
'janelas' // Slug do Post Type.
);
$janela->set_labels(
array(
'menu_name' => __( 'Janelas', 'odin' ),
'all_items' => __('Todas as Janelas', 'odin'),
'add_new_item' => __('Adicionar nova', 'odin'),
'add_new' => __('Adicionar nova', 'odin'),
'all_items'=> __('Janelas', 'odin'),
'view_item'=> __('Janelas', 'odin'),
'search_items'=> __('Janelas', 'odin'),
'new_item'=> __('Janelas', 'odin'),
'edit_item'=> __('Janelas', 'odin'),
'singular_name'=> __('Janela', 'odin'),
'name'=> __('Janelas', 'odin'),
)
);
$janela->set_arguments(
array(
'taxonomies' => array('post_tag'),
'description' => __( 'Coisas que vejo, leio, visito, pesquiso. Coisas com as quais me encanto. Ou me espanto...' ),
'menu_icon' => 'dashicons-screenoptions',
'supports' => array( 'title', 'editor', 'thumbnail' ),
)
);
}
add_action( 'init', 'janela_cpt', 1 );
////////////////Projetos////////////////
////////////////Projetos////////////////
function projetos_cpt(){
$projetos = new Odin_Post_Type(
'Projeto', // Nome (Singular) do Post Type.
'projetos' // Slug do Post Type.
);
$projetos->set_labels(
array(
'menu_name' => __( 'Projetos', 'odin' ),
'all_items' => __('Todos os projetos', 'odin'),
'add_new_item' => __('Adicionar novo', 'odin'),
'add_new' => __('Adicionar novo', 'odin')
)
);
$projetos->set_arguments(
array(
'taxonomies' => array('post_tag'),
'menu_icon' => 'dashicons-screenoptions',
'supports' => array( 'title', 'editor', 'thumbnail' ),
'description' => __( 'Jardins, parques, praças, sítios... Conhecer o lugar, entender o que o cliente quer, do que gosta e do que precisa. Aí então, compor e propor uma paisagem nova!' ),
)
);
}
add_action( 'init', 'projetos_cpt', 1 );
////////////////Viagens////////////////
////////////////Viagens////////////////
function viagem_cpt(){
$viagem = new Odin_Post_Type(
'Viagens', // Nome (Singular) do Post Type.
'viagens' // Slug do Post Type.
);
$viagem->set_labels(
array(
'menu_name' => __( 'viagens', 'odin' ),
'all_items' => __('Todas as viagens', 'odin'),
'add_new_item' => __('Adicionar nova', 'odin'),
'add_new' => __('Adicionar nova', 'odin')
)
);
$viagem->set_arguments(
array(
'taxonomies' => array('post_tag'),
'menu_icon' => 'dashicons-admin-site',
'supports' => array( 'title', 'editor', 'thumbnail' ),
'description' => __( 'Descobertas de outras paisagens. Umas próximas, outras distantes. Umas incríveis, outras estonteantes.' ),
)
);
}
add_action( 'init', 'viagem_cpt', 1 );
////////////////Meu Jardim////////////////
////////////////Meu Jardim////////////////
function jardim_cpt(){
$jardin = new Odin_Post_Type(
'Meu Jardim', // Nome (Singular) do Post Type.
'jardins' // Slug do Post Type.
);
$jardin->set_labels(
array(
'name'=> __('Meus Jardins', 'odin'),
'menu_name' => __( 'Jardins', 'odin' ),
'all_items' => __('Todos os Jardins', 'odin'),
'add_new_item' => __('Adicionar novo', 'odin'),
'add_new' => __('Adicionar novo', 'odin'),
'singular_name'=> __('Meu Jardim', 'odin'),
'edit_item' => __('Meu Jardim', 'odin'),
)
);
$jardin->set_arguments(
array(
'taxonomies' => array('post_tag'),
'menu_icon' => 'dashicons-screenoptions',
'supports' => array( 'title', 'editor', 'thumbnail' ),
'description' => __( 'O lugar onde faço minhas experiências, planto sementes vindas de longe, podo, adubo, transplanto e por aí afora. Criando uma paisagem rica em cores, formas, texturas e perfumes. Entrem! Sintam-se em casa!' ),
)
);
}
add_action( 'init', 'jardim_cpt', 1 );
////////////////Janela////////////////
///////muda icone
function fontawesome_icon_dashboard() {
echo '<style type="text/css" media="screen">
.menu-icon-projetos .dashicons-before:before {
content: "\f040";
font-family: "FontAwesome" !important;
font-size: 18px !important;
</style>';
echo '<style type="text/css" media="screen">
.menu-icon-viagem .dashicons-before:before {
content: "\f072";
font-family: "FontAwesome" !important;
font-size: 18px !important;
</style>';
echo '<style type="text/css" media="screen">
.menu-icon-meu_jardim .dashicons-before:before {
content: "\f06c";
font-family: "FontAwesome" !important;
font-size: 18px !important;
</style>';
}
add_action('admin_head', 'fontawesome_icon_dashboard');
///////muda icone
////////////////////////////////////////////////////////////////
////////////////Custom post types////////////////
////////////////////////////////////////////////////////////////
///////////////////////tyamanho do excerpt///////////////////
///////////////////////tyamanho do excerpt///////////////////
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
///////////////////////tyamanho do excerpt///////////////////
///////////////////////tyamanho do excerpt///////////////////
///////////////////formulario de contato/////////////////////
//[foobar]
function contato_shortcode( ){
$form = scf_html();
return $form;
}
add_shortcode( 'formulario_contato', 'contato_shortcode' );
// add editor the privilege to edit theme
// get the the role object
$role_object = get_role( 'editor' );
// add $cap capability to this role object
$role_object->add_cap( 'manage_options' );
$role_object->remove_cap('edit_theme_options');
/////////////////////////////////////////////////////////////
////////////////////ocultando coisas no admin///////////////
/////////////////////////////////////////////////////////////
if( current_user_can('editor') && !current_user_can('administrator')) {
add_action( 'admin_menu', 'my_remove_menu_pages' );
}
function my_remove_menu_pages() {
remove_menu_page('tools.php');
remove_menu_page('options-general.php');
remove_menu_page('edit-comments.php');
remove_menu_page('edit.php');
remove_menu_page('upload.php');
remove_menu_page('index.php');
// remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
remove_submenu_page( 'themes.php', 'customize.php' ); // hide the theme selection submenu
remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the theme selection submenu
remove_submenu_page( 'themes.php', 'nav-menus.php' ); // hide the theme selection submenu
}
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('updates'); // Remove the updates link
$wp_admin_bar->remove_menu('comments'); // Remove the comments link
$wp_admin_bar->remove_menu('new-content'); // Remove the content link
$wp_admin_bar->remove_menu('w3tc');
$wp_admin_bar->remove_menu('search'); // If you use w3 total cache remove the performance link
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
add_image_size( 'janelas', '400', '240', true );
add_image_size( 'viagens', '150', '150', true );
/////////////////////////////////////////////////////////////
////////////////////ocultando coisas no admin///////////////
/////////////////////////////////////////////////////////////
update_option( 'thumbnail_size_w', 300 );
update_option( 'thumbnail_size_h', 300 );
update_option( 'thumbnail_crop', 1 );