This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
312 lines (253 loc) · 8 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
<?php
require_once dirname(__FILE__) . '/includes/template-modules.php';
require_once dirname(__FILE__) . '/includes/widgets.php';
/**
* Setup pdx theme.
*/
function pdx_setup() {
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain( 'pdx', TEMPLATEPATH . '/languages' );
$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) ) {
require_once( $locale_file );
}
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'pdx' ),
) );
}
add_action('after_setup_theme', 'pdx_setup');
/**
* Remove wrapping <div> from around page menu.
*/
function pdx_page_menu( $menu, $args ) {
$menu = preg_replace('|^<div.+?>(.+)</div>$|', '\\1', $menu);
return $menu;
}
add_filter('wp_page_menu', 'pdx_page_menu', 10, 2);
/**
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*
* To override this in a child theme, remove the filter and optionally add
* your own function tied to the wp_page_menu_args filter hook.
*
* @since pdx 1.0
*/
function pdx_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'pdx_page_menu_args' );
/**
* Build HTML page <title>.
*/
function pdx_title() {
$sep = apply_filters('pdx_title_separator', '—');
$location = ( is_front_page() || is_home() ) ? '' : 'right';
$location = apply_filters('pdx_title_sep_location', $location);
echo wp_title($sep, false, $location);
}
/**
* Customize wp_title based on the type of page. Include page number if applicable as well as the blog name.
*/
function pdx_filter_title($title, $sep, $seplocation) {
global $paged, $page;
if ( is_category() ) {
$title .= sprintf( __('Category Archives %s ', 'pdx'), $sep);
} else if ( is_tag() ) {
$title .= sprintf( __('Tag Archives %s ', 'pdx'), $sep);
} else if ( is_archive() ) {
$title .= sprintf( __('Archives %s ', 'pdx'), $sep);
}
if ( is_front_page() && $title == '' ) {
$title = get_bloginfo('description');
if ( $seplocation == 'right' ) {
$title .= " $sep ";
} else {
$title = " $sep " . $title;
}
}
// add page number
if ( $paged >= 2 || $page >= 2 ) {
if ( $seplocation == 'right' ) {
$title .= sprintf( __('Page %s', 'pdx'), max($paged, $page) ) . " $sep ";
} else {
$title .= " $sep " . sprintf( __('Page %s', 'pdx'), max($paged, $page) );
}
}
// add blog name
if ( $seplocation == 'right') {
$title .= get_bloginfo('name');
} else {
$title = get_bloginfo('name') . $title;
}
return $title;
}
add_filter('wp_title', 'pdx_filter_title', 10, 3);
/**
* Use blog description as title for home page.
*/
function pdx_single_post_title($title, $post) {
if ( is_home() ) {
$title = get_bloginfo('description');
}
return $title;
}
add_filter('single_post_title', 'pdx_single_post_title', 10, 2);
/**
* Generate page title for archive pages.
*/
function pdx_archive_page_title() {
if ( have_posts() ) {
the_post();
}
if ( is_category() ) {
$template = __( 'Category Archives: %s', 'pdx' );
$value = single_cat_title( '', false);
} else if ( is_tag() ) {
$template = __( 'Tag Archives: %s', 'pdx' );
$value = single_tag_title( '', false);
} else if ( is_author() ) {
$template = __( 'Author Archives: %s', 'pdx' );
$value = get_the_author();
} else if ( is_day() ) {
$template = __( 'Daily Archives: %s', 'pdx' );
$value = get_the_date();
} else if ( is_month() ) {
$template = __( 'Monthly Archives: %s', 'pdx' );
$value = get_the_date('F Y');
} else if ( is_year() ) {
$template = __( 'Yearly Archives: %s', 'pdx' );
$value = get_the_date('Y');
} else {
$template = null;
$title = __( 'Blog Archives', 'pdx' );
}
if ( $template ) {
$title = sprintf( $template, '<span>' . $value . '</span>' );
}
rewind_posts();
return apply_filters('pdx_archive_page_title', $title);
}
/**
* Generate page description for archive pages.
*/
function pdx_archive_page_description() {
if ( is_category() || is_tag() || is_tax() ) {
$description = term_description();
} else if ( is_author() ) {
$description = get_the_author_meta( 'description' );
} else {
$description = '';
}
return apply_filters('pdx_archive_page_description', $description);
}
function pdx_comments_title() {
comments_number(
sprintf(__('No Responses to %s', 'pdx'), '<em>' . get_the_title() . '</em>'),
sprintf(__('One Response to %s', 'pdx'), '<em>' . get_the_title() . '</em>'),
sprintf(__('%% Responses to %s', 'pdx'), '<em>' . get_the_title() . '</em>')
);
}
function pdx_list_comments() {
wp_list_comments(
array( 'style' => 'div', 'callback' => 'pdx_comment_start', 'end-callback' => 'pdx_comment_end')
);
}
/**
* Cleanup a few core WordPress things.
*/
function pdx_cleanup_wp() {
// remove 'capital_P_dangit'
foreach ( array( 'the_content', 'the_title', 'comment_text' ) as $filter ) {
remove_filter( $filter, 'capital_P_dangit', 11 );
}
// remove the default styles that are packaged with the Recent Comments widget.
global $wp_widget_factory;
remove_action( 'wp_head',
array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
// remove rpc related links if not necessary
if ( !get_option('enable_xmlrpc') ) {
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');
}
// remove adjacent links for pages
if ( is_page() ) {
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
}
}
add_action('wp', 'pdx_cleanup_wp', 99);
/**
* Start 'comment' template module.
*/
function pdx_comment_start( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
$GLOBALS['comment_args'] = $args;
$GLOBALS['comment_depth'] = $depth;
get_template_module('comment');
}
/**
* End 'comment' template module.
*/
function pdx_comment_end( $comment, $args, $depth ) {
?>
</article>
<?php
}
/**
* pdx javascript
*/
function pdx_js() {
$offload_js = !WP_DEBUG;
$offload_js = apply_filters('pdx_offload_js', $offload_js);
if ( $offload_js ) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js',
false, '1.4.2');
wp_register_script('modernizr', 'http://cachedcommons.org/cache/modernizr/1.5.0/javascripts/modernizr-min.js',
false, '1.5', true);
} else {
// do something ?
}
wp_enqueue_script('modernizr');
}
add_action('wp', 'pdx_js', 5);
/**
* Add the default stylesheet. Try to use last modified time to stylesheet URI to ensure freshness.
*
* @see http://markjaquith.wordpress.com/2009/05/04/force-css-changes-to-go-live-immediately/
*/
function pdx_add_style() {
$stylesheet = get_stylesheet_uri();
$version = false;
$stylesheet_dir_uri = get_stylesheet_directory_uri();
$stylesheet_dir = get_stylesheet_directory();
if ( strstr($stylesheet, $stylesheet_dir_uri) ) {
$file = preg_replace('|' . $stylesheet_dir_uri . '|', $stylesheet_dir, $stylesheet);
$version = filemtime( $file );
}
wp_enqueue_style('style', $stylesheet, array(), $version);
}
add_action('wp_head', 'pdx_add_style', 5);
/**
* Add 'no-js' class to html element if modernizr is present.
*/
function pdx_modernizr_no_js($attributes) {
$modernizr = apply_filters('include_modernizr', false);
if ( $modernizr || wp_script_is('modernizr', 'queue') ) {
$attributes .= ' class="no-js"';
}
return $attributes;
}
add_filter('language_attributes', 'pdx_modernizr_no_js');
/**
* Handle 'safe_email' shortcode which converts email address into spambot-safe link.
*/
function pdx_safe_email($atts, $content=null) {
return '<a href="mailto:' . antispambot($content) . '">' . antispambot($content) . '</a>';
}
add_shortcode('safe_email', 'pdx_safe_email');