-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·302 lines (249 loc) · 9.29 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
<?php
/*
This file is part of THE ERUDITE.
THE ERUDITE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License v2 as published by the Free Software Foundation.
THE ERUDITE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details: http://www.gnu.org/licenses/gpl-2.0.html
*/
// Translate, if applicable
load_theme_textdomain('erudite', get_template_directory() . '/translation');
if ( ! isset( $content_width ) )
$content_width = 540;
// epigraphs
include_once "library/epigraph.php";
// my own filter for formatting
foreach ( array( 'wptexturize', 'convert_chars', 'wpautop' ) as $filter ) {
add_filter( 'erdt_formatting', $filter );
}
add_action('init', 'erdt_go_away_page_comments');
function erdt_go_away_page_comments() {
if ( ! erdt_get_option('allow_page_comments') )
remove_post_type_support('page', 'comments');
}
// Customizer integration
add_action( 'customize_register', 'erdt_customize_register' );
function erdt_customize_register( $wp_customize ) {
$wp_customize->get_setting('blogname')->transport='postMessage';
$wp_customize->get_setting('blogdescription')->transport='postMessage';
if ( $wp_customize->is_preview() && ! is_admin() ) {
add_action( 'wp_footer', 'erdt_customize_preview', 21 );
}
}
function erdt_customize_preview() {
?>
<script>
(function($){
wp.customize('blogname',function( value ) {
value.bind(function(to) {
$('#blog-title a').text( to );
});
});
wp.customize('blogdescription',function( value ) {
value.bind(function(to) {
$('#blog-description').text( to );
});
});
})(jQuery);
</script>
<?php
}
function erdt_js_options() {
$js = array(
'More' => __("<span>↓</span> Keep Reading", "erudite"),
'Less' => __('<span>↑</span> Put Away', 'erudite' ),
'Info' => __('↓ Further Information', 'erudite' ),
'MenuShow' => __('<span>↓</span> Show Menu', 'erudite' ),
'MenuHide' => __('<span>↑</span> Hide Menu', 'erudite' ),
'DisableKeepReading' => erdt_get_option( 'keepreading_disable' ),
'DisableHide' => erdt_get_option( 'hide_disable' )
);
return json_encode( $js );
}
// empty titles
add_filter( 'the_title', 'erdt_empty_title' );
function erdt_empty_title( $title ) {
if ( '' == $title )
$title = __('[No Title]', 'erudite');
return $title;
}
add_filter('mce_css', 'erudite_editor_style');
function erudite_editor_style($url) {
if ( erdt_get_option('editor_style_disable') )
return $url;
if ( !empty($url) )
$url .= ',';
// Change the path here if using sub-directory
$url .= trailingslashit( get_template_directory_uri() ) . 'css/editor-style.css';
return $url;
}
add_filter('body_class', 'erudite_body_class');
function erudite_body_class($classes) {
// for theme colors
if ( erdt_get_option('color_dark') )
$classes[] = 'dark';
// proper first-page class
if ( is_home() && !is_paged() )
$classes[] = "first-page";
// show/hide functionality
if ( ! erdt_get_option('hide_disable') )
$classes[] = "hiding";
// WP-Typography?
if ( class_exists('wpTypography') )
$classes[] = 'hypenation';
return $classes;
}
/*
* Helper function to return the theme option value. If no value has been saved, it returns $default.
* Needed because options are saved as serialized strings.
*
* This code allows the theme to work without errors if the Options Framework plugin has been disabled.
*/
if ( ! function_exists( 'of_get_option' ) ) {
add_action( 'admin_notices', 'erdt_prompt_options_framework' );
function of_get_option($name, $default = false) {
$optionsframework_settings = get_option('optionsframework');
// Gets the unique option id
$option_name = $optionsframework_settings['id'];
if ( get_option($option_name) ) {
$options = get_option($option_name);
}
else {
return of_get_option_fallback($name, $default);
}
return ( isset($options[$name]) ) ? $options[$name] : $default;
}
// If Options Framework hasn't been installed, fall back to defaults
function of_get_option_fallback($id, $default = false) {
include_once TEMPLATEPATH . '/options.php';
$options = optionsframework_options();
$found_option = array();
foreach ( $options as $opt ) {
if ( isset($opt['id'] ) && $opt['id'] === $id ) {
$found_option = $opt;
break;
}
}
return isset( $found_option['std'] ) ? $found_option['std'] : $default;
}
}
function erdt_prompt_options_framework() {
global $pagenow;
$pages = array( 'index.php', 'themes.php', 'plugins.php' );
if ( ! current_user_can( 'install_plugins' ) || ! in_array($pagenow, $pages ) ) {
return;
}
$base = is_multisite() ? network_admin_url('plugin-install.php') : admin_url('plugin-install.php');
$url = add_query_arg( array(
'tab' => 'search',
'type' => 'term',
's' => 'Options Framework'
), $base );
$text = sprintf( __('The Erudite now requires the <a href="%s">Options Framework</a> plugin if you want to change theme options. (If you had previous theme options set, you will need to re-enter them. Some options have been removed.)'), $url );
echo "<div class='updated'><p>{$text}</p></div>";
}
// generic theme option function. set second parameter to TRUE to add content formatting
function erdt_get_option( $id, $format = false ) {
$return = of_get_option( $id );
if ( empty( $return ) ) {
$return = false;
}
if ( $format ) {
$return = apply_filters( 'erdt_formatting', $return );
}
return $return;
}
function erdt_the_option( $id, $format = false ) {
echo erdt_get_option( $id, $format );
}
// filter the_excerpt to give a proper ellipsis.
add_filter('the_excerpt', 'erdt_custom_excerpt');
function erdt_custom_excerpt($text) {
return str_replace('[...]', '<span class="excerpt-more">…</span>', $text);
}
// custom comments loop for wp_list_comments
include "comments_custom.php";
add_action( 'wp_enqueue_scripts', 'erdt_frontend_scripts_and_styles' );
function erdt_frontend_scripts_and_styles() {
// grab theme version for happier script versioning
$themes = get_themes();
$current_theme = get_current_theme();
$ver = $themes[$current_theme]['Version'];
$disable_parent = is_child_theme() && erdt_get_option('disable_parent_css');
$template_url = trailingslashit(get_template_directory_uri());
if ( ! $disable_parent ) {
wp_enqueue_style('the-erudite', $template_url.'css/erudite.css');
}
if ( is_child_theme() ) {
wp_enqueue_style('the-erudite-child', get_bloginfo('stylesheet_url') );
}
wp_enqueue_script('erudite', $template_url.'js/common.js', array('jquery'), $ver, true);
}
if ( function_exists('add_theme_support') ) {
add_theme_support('automatic-feed-links');
}
if ( function_exists('register_nav_menus') ) {
register_nav_menus( array('header-menu' => __('Header Menu', 'erudite') ) );
}
// call wp_nav_menu, but fallback to old_erdt_globalnav otherwise
function erdt_globalnav() {
if ( function_exists('wp_nav_menu') ) {
$menu = wp_nav_menu(array(
'theme_location' => 'header-menu',
'fallback_cb' => 'old_erdt_globalnav',
'container' => 'ul',
'echo' => false
));
$menu = str_replace( array( "\r", "\n", "\t" ), '', trim($menu) );
if ( ! empty( $menu) ) {
echo '<div id="menu">' . $menu . "</div>\n";
}
}
else {
old_erdt_globalnav();
}
}
// Produces a list of pages in the header without whitespace
function old_erdt_globalnav() {
if ( erdt_get_option('category_nav') ) {
$menu = wp_list_categories('title_li=&echo=0');
} else {
$menu = wp_list_pages('title_li=&sort_column=menu_order&echo=0');
}
$menu = str_replace( array( "\r", "\n", "\t" ), '', trim($menu) );
$menu = '<ul>' . $menu . '</ul>';
echo '<div id="menu">' . $menu . "</div>\n";
}
add_filter('the_content', 'erdt_hr_helper', 0);
function erdt_hr_helper($content) {
return str_replace('<hr />', "<hr />\n\n", $content);
}
function erdt_get_author_posts_link() {
global $authordata;
return sprintf(
'<a href="%1$s" title="%2$s">%3$s</a>',
get_author_posts_url( $authordata->ID, $authordata->user_nicename ),
esc_attr( sprintf( __( 'Posts by %s', 'erudite' ), get_the_author() ) ),
get_the_author()
);
}
// Widgets plugin: intializes the plugin after the widgets above have passed snuff
function erdt_widgets_init() {
if ( !function_exists('register_sidebars') )
return;
// Formats the Sandbox widgets, adding readability-improving whitespace
$p = array(
'name' => "Erudite Footer %d",
'before_widget' => "\n\t\t\t" . '<li id="%1$s" class="widget %2$s">',
'after_widget' => "\n\t\t\t</li>\n",
'before_title' => "\n\t\t\t\t". '<h3 class="widgettitle">',
'after_title' => "</h3>\n"
);
// Table for how many? Two? This way, please.
register_sidebars( 3, $p );
}
// Runs our code at the end to check that everything needed has loaded
add_action( 'init', 'erdt_widgets_init' );
// Adds filters for the description/meta content in archives.php
add_filter( 'archive_meta', 'wptexturize' );
add_filter( 'archive_meta', 'convert_smilies' );
add_filter( 'archive_meta', 'convert_chars' );
add_filter( 'archive_meta', 'wpautop' );