forked from davidtcarson/frisco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
468 lines (402 loc) · 14.1 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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<?php
/**
* Frisco theme functions and definitions
*
* Because Frisco is a child theme of the BuddyPress default theme, the functions.php file from bp-default will do most of the heavy-lifting for us.
* The purpose of the Frisco functions.php file is to add some new functions and replace other functions from bp-default.
*
* DO NOT EDIT THIS FILE. You could edit this file, but any changes you make will be lost when you upgrade the theme in the future.
* Intead of editing this file, create a file called functions-custom.php in the Frisco theme folder and go to Frisco theme options in your dashboard to load the functions-custom.php file. See frisco_add_custom_functions() function down below.
*
* For more information on BuddyPress child themes, see http://codex.buddypress.org/theme-development/building-a-buddypress-child-theme/.
*
* @package Frisco
* @since 1.5
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// If BuddyPress is not activated, switch back to the default WP theme
if ( ! defined( 'BP_VERSION' ) )
switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
// Bail out if enough of BuddyPress isn't loaded
if ( ! function_exists( 'bp_is_active' ) )
return;
/**
* The bp_dtheme_setup() function is included conditionally in the BuddyPress default theme.
* The function was copied to this file and some things were removed because we don't need them. Ex. add_custom_background
*
* @since 1.5
*/
function bp_dtheme_setup() {
global $bp;
// Load the AJAX functions for the theme
include( get_template_directory() . '/_inc/ajax.php' );
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style();
// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'buddypress' ),
) );
if ( !is_admin() ) {
// Register buttons for the relevant component templates
// Friends button
if ( bp_is_active( 'friends' ) )
add_action( 'bp_member_header_actions', 'bp_add_friend_button', 5 );
// Activity button
if ( bp_is_active( 'activity' ) )
add_action( 'bp_member_header_actions', 'bp_send_public_message_button', 20 );
// Messages button
if ( bp_is_active( 'messages' ) )
add_action( 'bp_member_header_actions', 'bp_send_private_message_button', 20 );
// Group buttons
if ( bp_is_active( 'groups' ) ) {
add_action( 'bp_group_header_actions', 'bp_group_join_button', 5 );
add_action( 'bp_group_header_actions', 'bp_group_new_topic_button', 20 );
add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
}
// Blog button
if ( bp_is_active( 'blogs' ) )
add_action( 'bp_directory_blogs_actions', 'bp_blogs_visit_blog_button' );
}
}
add_action( 'after_setup_theme', 'bp_dtheme_setup' );
/**
* Load the Frisco theme options file.
* Frisco has some pre-loaded color and font options.
*
* @since 1.5
*/
require_once( get_stylesheet_directory() . '/theme-options.php' );
/**
* Add main CSS and Google Font CSS.
* Enqueue the bp-default main stylesheet, the Frisco main stylesheet and the Googlt font stylesheet.
*
* @since 1.5
*/
function bp_dtheme_enqueue_styles() {
// bp-default stylesheet
wp_enqueue_style( 'bp-default-main', get_template_directory_uri() . '/_inc/css/default.css', array(), bp_get_version() );
// frisco theme stylesheet
wp_enqueue_style( 'frisco-main', get_stylesheet_directory_uri() . '/style.css', array(), bp_get_version() );
// Google Font CSS
$options = get_option('frisco_theme_options');
wp_enqueue_style( 'frisco-fonts', 'http://fonts.googleapis.com/css?family=' . str_replace(" ", "+", $options['googlefont'] ) );
}
add_action( 'wp_print_styles', 'bp_dtheme_enqueue_styles' );
/**
* Add color choice stylesheet from theme options.
*
* @since 1.5
*/
add_action('wp_print_styles', 'frisco_add_colorcss');
function frisco_add_colorcss() {
// If theme options are not saved in the database
if( !get_option( 'frisco_theme_options' ) ) {
// Load default color stylesheet
wp_register_style('frisco-color-css', get_stylesheet_directory_uri() . '/css/default/color.css', array(), bp_get_version() );
} else {
// Load stylesheet for color choice
$options = get_option('frisco_theme_options');
wp_register_style('frisco-color-css', get_stylesheet_directory_uri() . '/css/' . $options['themecolor'] . '/color.css', array(), bp_get_version() );
}
wp_enqueue_style( 'frisco-color-css');
}
/**
* Add custom.css, if selected in theme options.
*
* @since 1.5
*/
add_action('wp_print_styles', 'frisco_add_customcss');
function frisco_add_customcss() {
$options = get_option('frisco_theme_options');
if ( $options['customcss'] == 1 ) {
// Load custom.css
wp_register_style('customcss', get_stylesheet_directory_uri() . '/custom.css', array(), bp_get_version() );
wp_enqueue_style( 'customcss');
} else {
// Do nothing
}
}
/**
* Load up functions-custom.php, if selected in theme options.
*
* @since 1.5
*/
add_action( 'after_setup_theme', 'frisco_add_custom_functions' );
function frisco_add_custom_functions() {
$options = get_option('frisco_theme_options');
if ( $options['customphp'] == 1 ) {
get_template_part('functions-custom');
}
}
/**
* Add Google font CSS to header.
*
* @since 1.5
*/
function frisco_add_google_font_css() {
$options = get_option('frisco_theme_options');
?>
<style type="text/css">
#header h1 a { font-family: "<?php echo $options['googlefont']; ?>","Helvetica Neue",Helvetica,Arial,sans-serif; }
</style>
<?php
}
add_action ( 'wp_head', 'frisco_add_google_font_css' );
/**
* Add viewport settings for better mobile access.
*
* @since 1.5
*/
function frisco_add_responsive() {
?>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<?php
}
add_action ( 'bp_head', 'frisco_add_responsive' );
/**
* Show friendly message upon theme activation.
*
* @since 1.5
*/
function bp_dtheme_show_notice() {
global $pagenow;
// Bail if Frisco theme was not just activated
if ( empty( $_GET['activated'] ) || ( 'themes.php' != $pagenow ) || !is_admin() )
return;
?>
<div id="message" class="updated fade">
<p><?php printf( __( 'Theme activated! This theme contains <a href="%s">a few options</a> and <a href="%s">sidebar widgets</a>.', 'buddypress' ), admin_url( 'themes.php?page=theme_options' ), admin_url( 'widgets.php' ) ) ?></p>
</div>
<style type="text/css">#message2, #message0 { display: none; }</style>
<?php
}
add_action( 'admin_notices', 'bp_dtheme_show_notice' );
/**
* Use a better image than default mystery man for users without Gravatar or custom avatar.
*
* @since 1.5
*/
function frisco_core_set_avatar_constants() {
define( 'BP_AVATAR_DEFAULT', get_stylesheet_directory_uri() . '/images/mystery-man.jpg' );
define( 'BP_AVATAR_DEFAULT_THUMB', get_stylesheet_directory_uri() . '/images/mystery-man-50.jpg' );
}
add_action( 'bp_init', 'frisco_core_set_avatar_constants', 2 );
/**
* Add extra divs to support full-width backgrounds.
*
* Because Frisco is a child theme, it uses most of the default template files.
* Using the default template files from bp-default is great because it's much better for forward compatibility.
* But this does limit what we can do. For example, Frisco has full-width backgrounds for different sections of the theme.
* These full-width backgrounds cannot be created with CSS alone - some custom HTML/Divs need to be included.
*
* For many of these extra divs, we'll use some actions below to hook into the bp-default template files and add them directly.
* Any template files that could not be customized adequately with actions below have been copied over to the Frisco theme and edited manually. Ex. /activity/index.php
*
* @since 1.5
*/
function frisco_div_bp_before_header() {
?>
<div id="bp-before-header" class="fullwidth">
<?php
}
add_action ( 'bp_before_header', 'frisco_div_bp_before_header' );
function frisco_div_bp_after_header() {
?>
</div>
<?php
}
add_action ( 'bp_after_header', 'frisco_div_bp_after_header' );
function frisco_div_bp_before_container() {
?>
<div id="bp-before-container" class="fullwidth">
<?php
}
add_action ( 'bp_before_container', 'frisco_div_bp_before_container' );
function frisco_div_bp_after_container() {
?>
</div>
<?php
}
add_action ( 'bp_after_container', 'frisco_div_bp_after_container' );
function frisco_div_bp_before_footer() {
?>
<div id="bp-before-footer" class="fullwidth">
<?php
}
add_action ( 'bp_before_footer', 'frisco_div_bp_before_footer' );
function frisco_div_bp_after_footer() {
?>
</div>
<?php
}
add_action ( 'bp_after_footer', 'frisco_div_bp_after_footer' );
function frisco_div_bp_before_activity_post_form() {
?>
<div id="bp-before-activity-post-form">
<?php
}
add_action ( 'bp_before_activity_post_form', 'frisco_div_bp_before_activity_post_form' );
function frisco_div_bp_after_activity_post_form() {
?>
</div>
<?php
}
add_action ( 'bp_after_activity_post_form', 'frisco_div_bp_after_activity_post_form' );
function frisco_div_bp_before_member_header() {
?>
<div id="bp-before-member-header">
<?php
}
add_action ( 'bp_before_member_header', 'frisco_div_bp_before_member_header' );
function frisco_div_bp_after_member_header() {
?>
</div>
<?php
}
add_action ( 'bp_after_member_header', 'frisco_div_bp_after_member_header' );
function frisco_div_bp_before_group_header() {
?>
<div id="bp-before-group-header">
<?php
}
add_action ( 'bp_before_group_header', 'frisco_div_bp_before_group_header' );
function frisco_div_bp_after_group_header() {
?>
</div>
<?php
}
add_action ( 'bp_after_group_header', 'frisco_div_bp_after_group_header' );
/**
* Add site credits by filtering exising text in footer.php from bp-default.
*
* @since 1.5
*/
add_filter('gettext', 'frisco_sitecredits', 20, 3);
/**
* Edit the default credits to add Frisco link. Remove it if you'd like or modify it to display whatever you want.
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function frisco_sitecredits( $translated_text, $untranslated_text, $domain ) {
$custom_field_text = 'Proudly powered by <a href="%1$s">WordPress</a> and <a href="%2$s">BuddyPress</a>.';
if ( $untranslated_text === $custom_field_text ) {
return 'Proudly powered by <a href="http://wordpress.org">WordPress</a>, <a href="http://buddypress.org">BuddyPress</a> and the <a href="http://friscotheme.com/">Frisco Theme</a>.';
}
return $translated_text;
}
/**
* Customize bp_message_get_notices() function
*
* Instead of down in the sidebar, the sitewide notice display is moved to just above the primary navigation.
*
* @since 1.6
*/
function frisco_bp_message_get_notices() {
global $userdata;
$notice = BP_Messages_Notice::get_active();
if ( empty( $notice ) )
return false;
$closed_notices = bp_get_user_meta( $userdata->ID, 'closed_notices', true );
if ( !$closed_notices )
$closed_notices = array();
if ( is_array($closed_notices) ) {
if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) {
?>
<div id="message" class="info notice frisco_notice" rel="n-<?php echo $notice->id ?>">
<p>
<strong><?php echo stripslashes( wp_filter_kses( $notice->subject ) ) ?></strong>
<?php echo stripslashes( wp_filter_kses( $notice->message) ) ?>
<a href="#" id="close-notice"><?php _e( 'x', 'friscotheme' ) ?></a>
</p>
</div>
<?php
}
}
}
if ( !function_exists( 'bp_get_version' ) ) :
/**
* If bp_get_version does not exist, create it.
*
* @since BuddyPress (1.6)
* @uses bp_get_version() To get the BuddyPress version
* @including this blank conditional function allows Frisco v1.6 to work with BuddyPress 1.5
*/
function bp_get_version() {
// Intentionally Blank
}
endif;
/**
* Include plus.php template if included in theme.
* If the theme contains no plus.php file then no template will be included.
*
* Included for forward compatibility and more options.
* @since 1.6
*/
get_template_part('plus');
/**
* Theme Customizer Support
*
* Included in WordPress 3.4+
* @since 1.6
*/
add_action( 'customize_register', 'frisco_customize_register' );
function frisco_customize_register($wp_customize) {
// Section
$wp_customize->add_section( 'frisco_theme_options_section', array(
'title' => __( 'Theme Options', 'friscotheme' ),
'priority' => 35,
'description' => __( 'Edit the color scheme or title font using the customizer. For more advanced customization, go to the Theme Options page.', 'friscotheme' ),
) );
// Color Setting
$wp_customize->add_setting( 'frisco_theme_options[themecolor]', array(
'default' => 'default',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
// Color Controls
$wp_customize->add_control( 'frisco_color_scheme', array(
'label' => __( 'Color Scheme', 'themename' ),
'section' => 'frisco_theme_options_section',
'settings' => 'frisco_theme_options[themecolor]',
'type' => 'radio',
'choices' => array(
'default' => 'Default (Blue)',
'green' => 'Green',
'orange' => 'Orange',
'yellow' => 'Yellow',
'grey' => 'Grey',
'purple' => 'Purple',
),
) );
// Title Font Setting
$wp_customize->add_setting( 'frisco_theme_options[googlefont]', array(
'default' => 'Lobster Two',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
// Title Font Controls
$wp_customize->add_control( 'frisco_title_font_choice', array(
'label' => 'Select a Google Font:',
'section' => 'frisco_theme_options_section',
'settings' => 'frisco_theme_options[googlefont]',
'type' => 'select',
'choices' => array(
'Lobster Two' => 'Lobster Two',
'Quattrocento' => 'Quattrocento',
'Droid Sans' => 'Droid Sans',
'PT Sans' => 'PT Sans',
'Yanone Kaffeesatz' => 'Yanone Kaffeesatz',
'Cabin' => 'Cabin',
'Black Ops One' => 'Black Ops One',
'Nixie One' => 'Nixie One',
'Bangers' => 'Bangers',
'Monofett' => 'Monofett',
),
) );
}
?>