Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
468 lines (402 sloc) 14.1 KB
<?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',
),
) );
}
?>