This repository has been archived by the owner on Dec 31, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
209 lines (175 loc) · 6.79 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
<?php
/**
* @package WordPress
* @subpackage RVB
*/
global $post;
// Theme options
if(@file_exists(dirname(__FILE__) . '/inc/rvb_theme_options.php')) {
include_once dirname(__FILE__) . '/inc/rvb_theme_options.php';
}
// Custom user roles
if(@file_exists(dirname(__FILE__) . '/inc/rvb_user_roles.php')) {
include_once dirname(__FILE__) . '/inc/rvb_user_roles.php';
}
// Custom user meta
if(@file_exists(dirname(__FILE__) . '/inc/rvb_user_meta.php')) {
include_once dirname(__FILE__) . '/inc/rvb_user_meta.php';
}
// [user] shortcode
if(@file_exists(dirname(__FILE__) . '/inc/rvb_user_shortcode.php')) {
include_once dirname(__FILE__) . '/inc/rvb_user_shortcode.php';
}
// [userlist] shortcode
if(@file_exists(dirname(__FILE__) . '/inc/rvb_userlist_shortcode.php')) {
include_once dirname(__FILE__) . '/inc/rvb_userlist_shortcode.php';
}
// Custom campaign post type
if(@file_exists(dirname(__FILE__) . '/inc/rvb_campaign_post_type.php')) {
include_once dirname(__FILE__) . '/inc/rvb_campaign_post_type.php';
}
// Custom alarm post type
if(@file_exists(dirname(__FILE__) . '/inc/rvb_alarm_post_type.php')) {
include_once dirname(__FILE__) . '/inc/rvb_alarm_post_type.php';
}
// Walker class for generating smart submenus
if(@file_exists(dirname(__FILE__) . '/inc/rb_walker_page_selective_children.php')) {
include_once dirname(__FILE__) . '/inc/rb_walker_page_selective_children.php';
}
// StationMap widget
if(@file_exists(dirname(__FILE__) . '/inc/rvb_stationmap_widget.php')) {
include_once dirname(__FILE__) . '/inc/rvb_stationmap_widget.php';
}
// RecentAlarms widget
if(@file_exists(dirname(__FILE__) . '/inc/rvb_recentalarms_widget.php')) {
include_once dirname(__FILE__) . '/inc/rvb_recentalarms_widget.php';
}
// EO Agenda widget
if(@file_exists(dirname(__FILE__) . '/inc/rvb_eoagenda_widget.php')) {
include_once dirname(__FILE__) . '/inc/rvb_eoagenda_widget.php';
}
// Facebook LikeBox widget
if(@file_exists(dirname(__FILE__) . '/inc/rvb_fblikebox_widget.php')) {
include_once dirname(__FILE__) . '/inc/rvb_fblikebox_widget.php';
}
// Set up custom template for the image widget (if present)
if(@file_exists(dirname(__FILE__) . '/inc/rvb_sp_template_image_widget.php')) {
function rvb_sp_template_image_widget($template) {
return get_stylesheet_directory() . '/inc/rvb_sp_template_image_widget.php';
}
add_filter('sp_template_image-widget_widget.php', 'rvb_sp_template_image_widget');
}
/**
* Set the content width based on the theme's design and stylesheet.
*/
if (! isset($content_maxwidth))
$content_maxwidth = 730;
/**
* Sets up theme defaults and registers support for various WordPress features.
*/
function rvb_setup() {
// Add translation support
$locale = get_locale();
if(!empty($locale)) {
$mofile = dirname(__FILE__) . '/lang/' . $locale . '.mo';
if(@file_exists($mofile) && is_readable($mofile))
load_textdomain('rvb', $mofile);
}
// This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
}
// This theme uses wp_nav_menu() in four locations.
register_nav_menu( 'footer1', __( 'Footer Menu 1', 'rvb' ) );
register_nav_menu( 'footer2', __( 'Footer Menu 2', 'rvb' ) );
register_nav_menu( 'footer3', __( 'Footer Menu 3', 'rvb' ) );
// Add support for post formats
add_theme_support('post-formats', array('status'));
}
add_action('after_setup_theme', 'rvb_setup');
/**
* Register our sidebars and widgetized areas.
*/
function rvb_widgets_init() {
register_sidebar(array(
'name' => __('Primary Home Sidebar', 'rvb'),
'id' => 'sidebar-home',
'description' => __('This sidebar is displayed next to the main content on the home page', 'rvb'),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => __('Secondary Home Sidebar', 'rvb'),
'id' => 'sidebar-home2',
'description' => __('This sidebar is displayed next to the news summary on the home page', 'rvb'),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar( array(
'name' => __( 'Page Sidebar', 'rvb' ),
'id' => 'sidebar-page',
'description' => __( 'The page sidebar is displayed on all pages, above the main sidebar', 'rvb' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar( array(
'name' => __( 'Post Sidebar', 'rvb' ),
'id' => 'sidebar-post',
'description' => __( 'The post sidebar is displayed on all posts, above the main sidebar', 'rvb' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
}
add_action('widgets_init', 'rvb_widgets_init');
/**
* Customize excerpts
*/
function rvb_excerpt_length($length) {
return 64; // number of allowed words in excerpts
}
add_filter('excerpt_length', 'rvb_excerpt_length', 999);
function rvb_excerpt_more($more) {
return '…'; // the entire excerpt is already wrapped in a link
}
add_filter('excerpt_more', 'rvb_excerpt_more');
/**
* Add a custom logo to the admin header
*/
function rvb_admin_logo() {
echo '<style type="text/css"> #wp-admin-bar-wp-logo > .ab-item .ab-icon { background: url("'.get_bloginfo('stylesheet_directory').'/images/admin-ab-icon.png") center !important; } </style>';
}
add_action('admin_head', 'rvb_admin_logo');
/**
* A prettier excerpt template tag
* It cuts of at the end of the sentence preceding the cut-off character.
*/
function the_pretty_excerpt($length=512, $allowed_tags='') { // Max excerpt length is set in characters
global $post;
$text = $post->post_excerpt;
if ('' == $text) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
}
$text = strip_shortcodes($text); // optional, recommended
$text = strip_tags($text, $allowed_tags); // use ' $text = strip_tags($text,'<p><a>'); ' if you want to keep some tags
$text = substr($text, 0, $length);
$excerpt = reverse_strrchr($text, '.', 1);
if($excerpt) {
echo apply_filters('the_excerpt', $excerpt);
} else {
echo apply_filters('the_excerpt', $text);
}
}
// Returns the portion of haystack which goes until the last occurrence of needle
function reverse_strrchr($haystack, $needle, $trail) {
return strrpos($haystack, $needle) ? substr($haystack, 0, strrpos($haystack, $needle) + $trail) : false;
}