This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
620 lines (207 loc) · 8.69 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
<?php
require_once('_inc/__php-config.php');
require_once('_inc/__cpt.php');
require_once('_inc/__widgets.php');
require_once('_inc/__scripts.php');
require_once('_inc/__admin-styles.php');
require_once('_inc/__menus.php');
require_once('_inc/__customizer.php');
add_filter( 'posts_where', 'extend_wp_query_where', 10, 2 );
function extend_wp_query_where( $where, $wp_query ) {
if ( $extend_where = $wp_query->get( 'extend_where' ) ) {
$where .= " AND " . $extend_where;
}
return $where;
}
add_filter('show_admin_bar', '__return_false');
// add_filter( 'manage_assinantes_posts_columns', 'smashing_assinantes_columns' );
// function smashing_assinantes_columns( $columns ) {
// $columns = array(
// 'cb' => $columns['cb'],
// 'nome' => __( 'Nome' ),
// 'email' => __( 'E-mail' ),
// );
// return $columns;
// }
// add_action( 'manage_assinantes_posts_custom_column', 'smashing_assinantes_column', 10, 2);
// function smashing_assinantes_column( $column, $post_id ) {
// // Image column
// if ( 'email' === $column ) {
// echo get_field('email', $post_id);
// }
// if ( 'nome' === $column ) {
// echo get_the_title($post_id);
// }
// }
function add_class_to_all_menu_anchors( $atts ) {
$atts['class'] = 'nav-link';
return $atts;
}
function custom_pagination( $numpages = '', $pagerange = '', $page='' ) {
if (empty($pagerange)) {
$pagerange = 2;
}
if (empty($page)) {
$page = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => '%_%',
'format' => '?page=%#%',
'total' => $numpages,
'current' => max( 1, get_query_var('page') ),
'show_all' => False,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => false,
'prev_text' => '',
'next_text' => '',
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='nav-links'>";
echo $paginate_links;
echo "</nav>";
}
}
if (!is_admin()) {
function wpb_search_filter($query) {
if ($query->is_search) {
$query->set('post_type', array('produtos', 'post'));
}
return $query;
}
add_filter('pre_get_posts','wpb_search_filter');
}
function title_filter( $where, $wp_query )
{
global $wpdb;
if ( $search_term = $wp_query->get( 'post_title' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( like_escape( $search_term ) ) . '%\'';
}
return $where;
}
add_filter( 'posts_where', 'title_filter', 10, 2 );
// function wpse18703_posts_where( $where, &$wp_query )
// {
// global $wpdb;
// if ( $post_title = $wp_query->get( 'post_title' ) ) {
// $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $post_title ) ) . '%\'';
// }
// return $where;
// }
function my_post_queries( $query ) {
// do not alter the query on wp-admin pages and only alter it if it's the main query
if (!is_admin() && $query->is_main_query()){
// alter the query for the home and category pages
if(is_category() || is_archive() || is_search()){
$query->set('posts_per_page', 10);
}
}
}
add_action( 'pre_get_posts', 'my_post_queries' );
function is_login_page() {
return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
}
function hide_editor() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
if( !isset( $post_id ) ) return;
$template_file = get_post_meta($post_id, '_wp_page_template', true);
// add_post_type_support( 'page', 'excerpt' );
if($template_file == 'page-templates/home.php' || $template_file == 'page-templates/a-ype.php'){
remove_post_type_support('page', 'editor');
remove_post_type_support('page', 'excerpt');
}
if($template_file == 'page-templates/produtos.php' || $template_file == 'page-templates/guia-de-limpeza.php'){
remove_post_type_support('page', 'editor');
}
remove_post_type_support('page', 'thumbnail');
// remove_post_type_support('page', 'editor');
// remove_post_type_support('page', 'author');
// remove_post_type_support('page', 'comments');
// remove_post_type_support('page', 'revisions');
// remove_post_type_support('page', 'custom-fields');
}
add_filter('query_vars', 'add_my_var');
function add_my_var($public_query_vars) {
$public_query_vars[] = 'paged';
return $public_query_vars;
}
function get_custom_field_data($key, $echo = false) {
$value = get_post_meta($post->ID, $key, true);
if($echo == false) {
return $value;
} else {
echo $value;
}
}
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
function df_terms_clauses($clauses, $taxonomy, $args) {
if (!empty($args['post_type'])) {
global $wpdb;
$post_types = array();
foreach($args['post_type'] as $cpt) {
$post_types[] = "'".$cpt."'";
}
if(!empty($post_types)) {
$clauses['fields'] = 'DISTINCT '.str_replace('tt.*', 'tt.term_taxonomy_id, tt.term_id, tt.taxonomy, tt.description, tt.parent', $clauses['fields']).', COUNT(t.term_id) AS count';
$clauses['join'] .= ' INNER JOIN '.$wpdb->term_relationships.' AS r ON r.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN '.$wpdb->posts.' AS p ON p.ID = r.object_id';
$clauses['where'] .= ' AND p.post_type IN ('.implode(',', $post_types).')';
$clauses['orderby'] = 'GROUP BY t.term_id '.$clauses['orderby'];
}
}
return $clauses;
}
function sanitize( $input, $setting ) {
global $wp_customize;
$control = $wp_customize->get_control( $setting->id );
if ( array_key_exists( $input, $control->choices ) ) {
return $input;
} else {
return $setting->default;
}
}
function count_post_visits() {
if( is_single() ) {
global $post;
$views = get_post_meta( $post->ID, 'my_post_viewed', true );
if( $views == '' ) {
update_post_meta( $post->ID, 'my_post_viewed', '1' );
} else {
$views_no = intval( $views );
update_post_meta( $post->ID, 'my_post_viewed', ++$views_no );
}
}
}
function remove_thumbnail_support(){
remove_post_type_support('page','comments');
remove_post_type_support('page','revisions');
remove_post_type_support('post','comments');
remove_post_type_support('post','revisions');
}
add_action('init','remove_thumbnail_support');
add_theme_support( 'post-thumbnails' );
add_post_type_support( 'page', 'excerpt' );
add_action( 'wp_head', 'count_post_visits' );
add_action( 'init', 'menu' );
add_action( 'init', 'the_widgets_init' );
add_action( 'admin_menu', 'remove_menus' );
add_action( 'wp_enqueue_scripts', 'regScripts' );
add_filter( 'contextual_help', 'mytheme_remove_help_tabs', 999, 3 );
add_action( 'customize_register', 'remove_customizer_settings', 20 );
add_action( 'customize_register', 'customizer' );
add_filter('terms_clauses', 'df_terms_clauses', 10, 3);
add_filter('upload_mimes', 'cc_mime_types');
add_filter( 'nav_menu_link_attributes', 'add_class_to_all_menu_anchors', 10 );