/
functions.php
315 lines (275 loc) · 10.9 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
<?php
include 'templates/custom-admin-function.php';
include 'templates/custom-admin-cssLogin.php';
load_theme_textdomain('BlogramaFM', get_template_directory() . '/languages');
$locale = get_locale();
$locale_file = get_template_directory() . "/languages/$locale.php";
if (is_readable($locale_file))
require_once( $locale_file );
function blograma_noticias_taxonomy() {
$labels = array(
'name' => _x('Noticias', 'Taxonomy General Name', 'BlogramaFM'),
'singular_name' => _x('Noticia', 'Taxonomy Singular Name', 'BlogramaFM'),
'menu_name' => __('Taxonomia Noticia', 'BlogramaFM'),
'all_items' => __('All Items', 'BlogramaFM'),
'parent_item' => __('Parent Item', 'BlogramaFM'),
'parent_item_colon' => __('Parent Item:', 'BlogramaFM'),
'new_item_name' => __('New Item Name', 'BlogramaFM'),
'add_new_item' => __('Add New Item', 'BlogramaFM'),
'edit_item' => __('Edit Item', 'BlogramaFM'),
'update_item' => __('Update Item', 'BlogramaFM'),
'separate_items_with_commas' => __('Separate items with commas', 'BlogramaFM'),
'search_items' => __('Search Items', 'BlogramaFM'),
'add_or_remove_items' => __('Add or remove items', 'BlogramaFM'),
'choose_from_most_used' => __('Choose from the most used items', 'BlogramaFM'),
'not_found' => __('Not Found', 'BlogramaFM'),
);
$rewrite = array(
'slug' => 'noticias',
'with_front' => FALSE,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy('Noticias', array('post', 'page'), $args);
}
add_action('init', 'blograma_noticias_taxonomy', 0);
function blograma_add_noticias() {
$labels = array(
'name' => _x('Noticias', 'Post Type General Name', 'BlogramaFM'),
'singular_name' => _x('Noticias', 'Post Type Singular Name', 'BlogramaFM'),
'menu_name' => __('Noticias FM', 'BlogramaFM'),
'parent_item_colon' => __('Parent Item:', 'BlogramaFM'),
'add_new_item' => __('Add Nueva Noticia', 'BlogramaFM'),
'add_new' => __('Add New ', 'BlogramaFM'),
'all_items' => __('All Items', 'BlogramaFM'),
'view_item' => __('Ver Item', 'BlogramaFM'),
'edit_item' => __('Editar Item', 'BlogramaFM'),
'update_item' => __('Update Item', 'BlogramaFM'),
'search_items' => __('Search Item', 'BlogramaFM'),
'not_found' => __('Not found', 'BlogramaFM'),
'not_found_in_trash' => __('Not found in Trash', 'BlogramaFM'),
);
$args = array(
'label' => __('Noticias FM', 'BlogramaFM'),
'description' => __('Noticias', 'BlogramaFM'),
'labels' => $labels,
'singular_label' => __('Noticias'),
'public' => true,
'show_ui' => true,
'capability_type' => 'noticias',
'hierarchical' => false,
'rewrite' => array('slug' => 'noticias'),
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author', 'custom-fields', 'revisions', 'page-attributes', 'post-formats',),
'taxonomies' => array('category', 'post_tag'),
'hierarchical' => false,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 6,
'can_export' => true,
'hide_empty' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'category_name' => 'noticias'
);
register_post_type('noticias', $args);
}
add_action('init', 'blograma_add_noticias');
?><?php
// ----------------------------
// -- CUSTOM POST TYPE LIBROS --
// ----------------------------
function blograma_libros_taxonomy() {
$labels = array(
'name' => _x('Libros', 'Taxonomy General Name', 'BlogramaFM'),
'singular_name' => _x('Libro', 'Taxonomy Singular Name', 'BlogramaFM'),
'menu_name' => __('Taxonomia Libros', 'BlogramaFM'),
'all_items' => __('All Items', 'BlogramaFM'),
'parent_item' => __('Parent Item', 'BlogramaFM'),
'parent_item_colon' => __('Parent Item:', 'BlogramaFM'),
'new_item_name' => __('New Item Name', 'BlogramaFM'),
'add_new_item' => __('Add New Item', 'BlogramaFM'),
'edit_item' => __('Edit Item', 'BlogramaFM'),
'update_item' => __('Update Item', 'BlogramaFM'),
'separate_items_with_commas' => __('Separate items with commas', 'BlogramaFM'),
'search_items' => __('Search Items', 'BlogramaFM'),
'add_or_remove_items' => __('Add or remove items', 'BlogramaFM'),
'choose_from_most_used' => __('Elegir los items más utilizados', 'BlogramaFM'),
'not_found' => __('Not Found', 'BlogramaFM'),
);
$rewrite = array(
'slug' => 'libros',
'with_front' => FALSE,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy('Libros', array('post', 'page'), $args);
}
add_action('init', 'blograma_libros_taxonomy');
function blograma_add_libros() {
$labels = array(
'name' => _x('Libros', 'Post Type General Name', 'BlogramaFM'),
'singular_name' => _x('Libro', 'Post Type Singular Name', 'BlogramaFM'),
'menu_name' => __('Libros FM', 'BlogramaFM'),
'parent_item_colon' => __('Parent Item:', 'BlogramaFM'),
'add_new_item' => __('Add Nuevo Libro', 'BlogramaFM'),
'add_new' => __('Add New ', 'BlogramaFM'),
'all_items' => __('All Items', 'BlogramaFM'),
'view_item' => __('Ver Item', 'BlogramaFM'),
'edit_item' => __('Editar Item', 'BlogramaFM'),
'update_item' => __('Update Item', 'BlogramaFM'),
'search_items' => __('Search Item', 'BlogramaFM'),
'not_found' => __('Not found', 'BlogramaFM'),
'not_found_in_trash' => __('Not found in Trash', 'BlogramaFM'),
);
$args = array(
'label' => __('Libros', 'BlogramaFM'),
'description' => __('Libros', 'BlogramaFM'),
'labels' => $labels,
'singular_label' => __('Libros'),
'public' => true,
'show_ui' => true,
'capability_type' => 'libros',
'hierarchical' => false,
'rewrite' => 'libros',
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author', 'custom-fields', 'revisions', 'page-attributes', 'post-formats',),
'taxonomies' => array('category', 'post_tag'),
'hierarchical' => false,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'hide_empty' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'category_name' => 'libros',
);
register_post_type('libros', $args);
}
add_action('init', 'blograma_add_libros');
?><?php
function blograma_post_thumbnail_remove_class($output) {
$output = preg_replace('/class=".*?"/', '', $output);
return $output;
}
add_filter('post_thumbnail_html', 'blograma_post_thumbnail_remove_class');
?><?php
function string_limit_words($string, $word_limit) {
$words = explode(' ', $string, ($word_limit + 1));
if (count($words) > $word_limit) {
array_pop($words);
echo implode(' ', $words) . "...";
} else {
echo implode(' ', $words);
}
}
?><?php
function remove_thumbnail_dimensions($html) {
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
return $html;
}
add_filter('wp_get_attachment_link', 'remove_thumbnail_dimensions', 10);
?><?php
if (!is_admin())
add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
$googleScript = 'http' . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "" ) . '://code.jquery.com/jquery-1.11.1.min.js';
wp_register_script('jquery', $googleScript, false, '1.11.1', true);
wp_enqueue_script('jquery');
}
?><?php
function blograma_login_errors() {
return '<strong>Login erroneo</strong>: revisa tu usuari@ o password.';
}
add_filter('login_errors', 'blograma_login_errors');
function site_login_logo_url() {
return get_bloginfo('url');
}
add_filter('login_headerurl', 'site_login_logo_url');
function site_login_logo_url_title() {
return 'Mouse Hover Info - BlogramaFM';
}
add_filter('login_headertitle', 'site_login_logo_url_title');
?><?php
function strip_empty_classes ($menu) {
$menu=preg_replace('/ class = ""| class = "sub-menu"/', '', $menu);
return $menu;
}
add_filter('wp_nav_menu', 'strip_empty_classes');
?><?php
function cleanname ($v) {
$v=preg_replace('/[^a-zA-Z0-9s]/', '', $v);
$v=str_replace(' ', '-', $v);
$v=strtolower($v);
return $v;
}
function nav_class_filter ($var) {
return is_array($var)?array_intersect($var, array('current-menu-item', 'icon')):'';
}
add_filter('nav_menu_css_class', 'nav_class_filter', 100, 1);
function nav_id_filter ($id, $item) {
return 'nav-'.cleanname($item->title);
}
add_filter('nav_menu_item_id', 'nav_id_filter', 10, 2);
?><?php
add_filter('contextual_help', 'blograma_remove_help_tabs', 999, 3);
function blograma_remove_help_tabs ($old_help, $screen_id, $screen) {
$screen->remove_help_tabs();
return $old_help;
}
function clean_wp_header () {
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
remove_action('wp_head', 'locale_stylesheet');
remove_action('wp_head', 'noindex');
remove_action('wp_head', 'wp_print_styles');
remove_action('wp_head', 'wp_print_head_scripts');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
}
add_action('init', 'clean_wp_header');
?>
<?php
function the_post_thumbnail_remove_class($output) {
$output = preg_replace('/class = ".*?"/', '', $output);
return $output;
}
add_filter('post_thumbnail_html', 'the_post_thumbnail_remove_class');
?>