-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
223 lines (178 loc) · 6.45 KB
/
Copy pathfunctions.php
File metadata and controls
223 lines (178 loc) · 6.45 KB
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
<?php
/**
* @package leowps-starter
* @author Leonardo Pereira <leonardo@leodesigner.com.br>
*/
?><?php
require_once get_stylesheet_directory() . '/config/init.php';
if (!function_exists('leowps_starter_setup')):
function leowps_starter_setup() {
load_theme_textdomain('leowps-starter');
/* Suportes necessários para o funcionamento do tema */
// adiciona o título da página automaticamente
add_theme_support('title-tag');
// suporte para adicionar imagem destacada em posts/páginas
add_theme_support('post-thumbnails');
// suporte para adicionar links do feed automaticamente ao header
add_theme_support('automatic-feed-links');
// suporte para tags html5 nos elementos de formulário, pesquisa e galeria
add_theme_support('html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
));
/**
* suporte para diferentes tipos de formato para os posts
* @link https://codex.wordpress.org/Post_Formats
*/
add_theme_support('post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat',
));
// suporte para adicionar logo personalizado ao tema
add_theme_support('custom-logo', array(
'height' => 82,
'width' => 400,
'flex-height' => true,
'flex-width' => true,
));
// suporte para adicionar e atualizar widgets em tempo real
add_theme_support('customize-selective-refresh-widgets');
// registro do menu principal do tema
register_nav_menus(array(
'primary' => esc_html__('Menu Principal', 'leowps-starter'),
));
}
add_action('after_setup_theme', 'leowps_starter_setup');
endif;
/**
* Inclusão dos scripts e estilos utilizados no tema
*/
if (!function_exists('leowps_starter_scripts')):
function leowps_starter_scripts() {
wp_deregister_script('jquery');
wp_enqueue_style('bootstrap', get_bloginfo('template_url') . '/dist/css/bootstrap.css', array(), '4.0', 'all');
wp_enqueue_style('font-awesome', get_bloginfo('template_url') . '/dist/css/font-awesome/css/font-awesome.min.css', array(), '4.7.0', 'all');
wp_enqueue_style('main', get_bloginfo('template_url') . '/dist/css/style.min.css', array(), '1.0', 'all');
wp_enqueue_script('jquery', get_bloginfo('template_url') . '/dist/js/jquery.js', '', '', true);
wp_enqueue_script('bootstrap', get_bloginfo('template_url') . '/dist/js/bootstrap.min.js', '', '', true);
wp_enqueue_script('main', get_bloginfo('template_url') . '/dist/js/main.min.js', array(), '1.0', 'all');
}
add_action('wp_enqueue_scripts', 'leowps_starter_scripts');
endif;
/**
* Funções para limpar o código gerado pelo Wordpress
* Essa função é importante por segurança
*/
if (!function_exists('leowps_starter_cleaner')):
function leowps_starter_cleaner() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
}
add_action('after_setup_theme', 'leowps_starter_cleaner');
endif;
/**
* Função para remover a barra admin do Wordpress
* Troque 'false' por 'true' para ativar a barra admin
*/
if (!function_exists('leowps_starter_remove_admin')):
function leowps_starter_remove_admin() {
return false;
}
add_filter('show_admin_bar', 'leowps_starter_remove_admin');
endif;
/**
* Registro da barra lateral do tema
* @link https://developer.wordpress.org/reference/functions/register_sidebar/
*/
if (!function_exists('leowps_starter_widgets_init')):
function leowps_starter_widgets_init() {
/**
* @since 1.0
*/
register_sidebar(array(
'name' => __('Barra Lateral', 'leowps-starter'),
'id' => 'custom-sidebar',
'description' => __('Os widgets adicionados aqui serão mostrados na barra lateral do site', 'leowps-starter'),
'before_widget' => '<article id="%1$s" class="custom-widget %2$s"><div class="widget-content">',
'after_widget' => '</div></article>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
}
add_action('widgets_init', 'leowps_starter_widgets_init');
endif;
/**
* Comentários Personalizados
*/
if (!function_exists('leowps_starter_comments')):
function leowps_starter_comments($comment, $args, $depth) {
$comment_id = (int) $comment->comment_ID;
$user_avatar = get_avatar($comment, 160);
$user_name = get_comment_author();
$dt = get_comment_date('d/m/Y H:i');
$content = get_comment_text();
$reply = get_comment_reply_link(array(
'replay_text' => 'Responder',
'respond_id' => 'responder',
'depth' => $depth,
'max_depth' => $args['max_depth']
));
$html = sprintf(
'<div class="comment-item" id="comment-%1$s">'
. '<span class="comment-avatar">'
. '%2$s'
. '</span>'
. '<div class="comment-content" id="comment-%1$s">'
. '<span class="comment-info">'
. '<strong class="comment-author">%3$s</strong>'
. '<span class="comment-date">%4$s</span>'
. '</span>'
. '<p>'
. '%5$s'
. '<span class="comment-reply">'
. '%6$s'
. '<span>'
. '</p>'
. '</div>'
. '</div>', $comment_id, $user_avatar, $user_name, $dt, $content, $reply
);
echo $html;
}
endif;
/**
* Adicionar classe personalizada do Bootstrap ao link do menu principal
*/
function leowps_starter_custom_li($classes, $item, $args) {
$classes[] = 'nav-item';
return $classes;
}
add_filter('nav_menu_css_class', 'leowps_starter_custom_li', 1, 3);
function leowps_starter_custom_link($ulclass) {
return preg_replace('/<a /', '<a class="nav-link"', $ulclass);
}
add_filter('wp_nav_menu', 'leowps_starter_custom_link');
/**
* Resumo personalizado para os posts
*/
function leowps_starter_excerpt($length) {
return 20;
}
add_filter('excerpt_length', 'leowps_starter_excerpt', 999);