-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·264 lines (151 loc) · 5.8 KB
/
functions.php
File metadata and controls
executable file
·264 lines (151 loc) · 5.8 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
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
<?php
// DEFINIR LOS PATHS A LOS DIRECTORIOS DE JAVASCRIPT Y CSS ///////////////////////////
define( 'JSPATH', get_template_directory_uri() . '/js/' );
define( 'CSSPATH', get_template_directory_uri() . '/css/' );
define( 'THEMEPATH', get_template_directory_uri() . '/' );
define( 'SITEURL', site_url('/') );
// FRONT END SCRIPTS AND STYLES //////////////////////////////////////////////////////
add_action( 'wp_enqueue_scripts', function(){
// scripts
wp_enqueue_script( 'plugins', JSPATH.'plugins.js', array('jquery'), '1.0', true );
wp_enqueue_script( 'functions', JSPATH.'functions.js', array('plugins'), '1.0', true );
// localize scripts
wp_localize_script( 'functions', 'ajax_url', admin_url('admin-ajax.php') );
// styles
wp_enqueue_style( 'styles', get_stylesheet_uri() );
});
// ADMIN SCRIPTS AND STYLES //////////////////////////////////////////////////////////
add_action( 'admin_enqueue_scripts', function(){
// scripts
wp_enqueue_script( 'admin-js', JSPATH.'admin.js', array('jquery'), '1.0', true );
// localize scripts
wp_localize_script( 'admin-js', 'ajax_url', admin_url('admin-ajax.php') );
// styles
wp_enqueue_style( 'admin-css', CSSPATH.'admin.css' );
});
// FRONT PAGE DISPLAYS A STATIC PAGE /////////////////////////////////////////////////
/*add_action( 'after_setup_theme', function () {
$frontPage = get_page_by_path('home', OBJECT);
$blogPage = get_page_by_path('blog', OBJECT);
if ( $frontPage AND $blogPage ){
update_option('show_on_front', 'page');
update_option('page_on_front', $frontPage->ID);
update_option('page_for_posts', $blogPage->ID);
}
});*/
// REMOVE ADMIN BAR FOR NON ADMINS ///////////////////////////////////////////////////
add_filter( 'show_admin_bar', function($content){
return ( current_user_can('administrator') ) ? $content : false;
});
// CAMBIAR EL CONTENIDO DEL FOOTER EN EL DASHBOARD ///////////////////////////////////
add_filter( 'admin_footer_text', function() {
echo 'Creado por <a href="http://hacemoscodigo.com">Los Maquiladores</a>. ';
echo 'Powered by <a href="http://www.wordpress.org">WordPress</a>';
});
// POST THUMBNAILS SUPPORT ///////////////////////////////////////////////////////////
if ( function_exists('add_theme_support') ){
add_theme_support('post-thumbnails');
}
if ( function_exists('add_image_size') ){
// add_image_size( 'size_name', 200, 200, true );
// cambiar el tamaño del thumbnail
/*
update_option( 'thumbnail_size_h', 100 );
update_option( 'thumbnail_size_w', 200 );
update_option( 'thumbnail_crop', false );
*/
}
// POST TYPES, METABOXES, TAXONOMIES AND CUSTOM PAGES ////////////////////////////////
require_once('inc/post-types.php');
require_once('inc/metaboxes.php');
require_once('inc/taxonomies.php');
require_once('inc/pages.php');
// MODIFICAR EL MAIN QUERY ///////////////////////////////////////////////////////////
add_action( 'pre_get_posts', function($query){
if ( $query->is_main_query() and ! is_admin() ) {
}
return $query;
});
// THE EXECRPT FORMAT AND LENGTH /////////////////////////////////////////////////////
/*add_filter('excerpt_length', function($length){
return 20;
});*/
/*add_filter('excerpt_more', function(){
return ' »';
});*/
// REMOVE ACCENTS AND THE LETTER Ñ FROM FILE NAMES ///////////////////////////////////
add_filter( 'sanitize_file_name', function ($filename) {
$filename = str_replace('ñ', 'n', $filename);
return remove_accents($filename);
});
// HELPER METHODS AND FUNCTIONS //////////////////////////////////////////////////////
/**
* Print the <title> tag based on what is being viewed.
* @return string
*/
function print_title(){
global $page, $paged;
wp_title( '|', true, 'right' );
bloginfo( 'name' );
// Add a page number if necessary
if ( $paged >= 2 || $page >= 2 ){
echo ' | ' . sprintf( __( 'Página %s' ), max( $paged, $page ) );
}
}
/**
* Imprime una lista separada por commas de todos los terms asociados al post id especificado
* los terms pertenecen a la taxonomia especificada. Default: Category
*
* @param int $post_id
* @param string $taxonomy
* @return string
*/
function print_the_terms($post_id, $taxonomy = 'category'){
$terms = get_the_terms( $post_id, $taxonomy );
if ( $terms and ! is_wp_error($terms) ){
$names = wp_list_pluck($terms ,'name');
echo implode(', ', $names);
}
}
/**
* Regresa la url del attachment especificado
* @param int $post_id
* @param string $size
* @return string url de la imagen
*/
function attachment_image_url($post_id, $size){
$image_id = get_post_thumbnail_id($post_id);
$image_data = wp_get_attachment_image_src($image_id, $size, true);
echo isset($image_data[0]) ? $image_data[0] : '';
}
/*
* Echoes active if the page showing is associated with the parameter
* @param string $compare, Array $compare
* @param Bool $echo use FALSE to use with php, default is TRUE to echo value
* @return string
*/
function nav_is($compare = array(), $echo = TRUE){
$query = get_queried_object();
$inner_array = array();
if(gettype($compare) == 'string'){
$inner_array[] = $compare;
}else{
$inner_array = $compare;
}
foreach ($inner_array as $value) {
if( isset($query->slug) AND preg_match("/$value/i", $query->slug)
OR isset($query->name) AND preg_match("/$value/i", $query->name)
OR isset($query->rewrite) AND preg_match("/$value/i", $query->rewrite['slug'])
OR isset($query->post_name) AND preg_match("/$value/i", $query->post_name)
OR isset($query->post_title) AND preg_match("/$value/i", remove_accents(str_replace(' ', '-', $query->post_title) ) ) )
{
if($echo){
echo 'active';
}else{
return 'active';
}
return FALSE;
}
}
return FALSE;
}