0 ) $pt_width = $purplepastels_theme_options['pt_width'];
else $pt_width = 150;
if( isset($purplepastels_theme_options['pt_height']) && $purplepastels_theme_options['pt_height'] > 0 ) $pt_height = $purplepastels_theme_options['pt_height'];
else $pt_height = 150;
if( isset($purplepastels_theme_options['pt_crop']) && $purplepastels_theme_options['pt_crop'] == 'hard' ) add_image_size( 'custom', $pt_width, $pt_height, true );
else add_image_size( 'custom', $pt_width, $pt_height );
// Set up custom post excerpt
function purplepastels_excerpt_length() {
global $purplepastels_theme_options;
if( isset($purplepastels_theme_options['custom_excerpt']) && $purplepastels_theme_options['custom_excerpt'] > 0 ) return $purplepastels_theme_options['custom_excerpt'];
else return 100;
}
add_filter('excerpt_length', 'purplepastels_excerpt_length');
}
endif;
add_action( 'after_setup_theme', 'purplepastels_theme_setup' );
// add custom menu support
if( function_exists( 'register_nav_menu' ) && !function_exists( 'purplepastels_register_menus' )) :
function purplepastels_register_menus() {
register_nav_menu( 'toptabs', __( 'Top Tabs', 'purplepastels' ) );
}
add_action( 'init', 'purplepastels_register_menus' );
endif;
// Add accordion menu
if( !isset($purplepastels_theme_options['accordian']) || $purplepastels_theme_options['accordian'] == 'yes' && !is_admin() ) add_action('init', 'purplepastels_init_accordian');
// Output stylesheet links
if( !function_exists( 'purplepastels_stylesheets') ) :
function purplepastels_stylesheets() {
echo ' ' ."\n";
echo ' ' ."\n";
echo ' ' ."\n";
echo '' . "\n";
echo "\n";
}
endif;
add_action( 'wp_head', 'purplepastels_stylesheets' );
// Output designer meta tags
if( !function_exists( 'purplepastels_designer') ) :
function purplepastels_designer() {
?>
'Default Sidebar Upper',
'id' => 'default-upper',
'description' => __('Upper vertical sidebar','purplepastels'),
'before_widget' => '
',
'after_widget' => ' ',
'before_title' => '',
));
register_sidebar(array(
'name'=> 'Default Sidebar Lower',
'id' => 'default-lower',
'description' => __('Lower vertical sidebar','purplepastels'),
'before_widget' => '',
'after_widget' => ' ',
'before_title' => '',
));
register_sidebar(array(
'name'=> 'Archives Sidebar Upper',
'id' => 'archive-upper',
'description' => __('Upper vertical sidebar for archive pages only','purplepastels'),
'before_widget' => '',
'after_widget' => ' ',
'before_title' => '',
));
register_sidebar(array(
'name'=> 'Archives Sidebar Lower',
'id' => 'archive-lower',
'description' => __('Lower vertical sidebar for archive pages only','purplepastels'),
'before_widget' => '',
'after_widget' => ' ',
'before_title' => '',
));
register_sidebar(array(
'name'=> 'Alt Page Sidebar Upper',
'id' => 'alt-page-upper',
'description' => __('Upper vertical sidebar for the Alternative Page template','purplepastels'),
'before_widget' => '',
'after_widget' => ' ',
'before_title' => '',
));
register_sidebar(array(
'name'=> 'Alt Page Sidebar Lower',
'id' => 'alt-page-lower',
'description' => __('Lower vertical sidebar for the Alternative Page template','purplepastels'),
'before_widget' => '',
'after_widget' => ' ',
'before_title' => '',
));
register_sidebar(array(
'name'=> 'Widget Page Upper',
'id' => 'widget-page-upper',
'description' => __('Before page content','purplepastels'),
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
));
register_sidebar(array(
'name'=> 'Widget Page Lower',
'id' => 'widget-page-lower',
'description' => __('After page content','purplepastels'),
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
));
}
endif;
add_action( 'widgets_init', 'purplepastels_widgets_init' );
// Hide widget titles
if( !function_exists( 'purplepastels_widgettitles' ) ) :
function purplepastels_widgettitles() {
?>
' . __('*', 'purplepastels') . '';
$fields['author'] = '';
$fields['email'] = '';
$fields['url'] = '';
return $fields;
}
endif;
add_filter('comment_form_default_fields','purplepastels_theme_comment_fields');
// Custom comment form arguments
if( ! function_exists( 'purplepastels_theme_comment_form_args' ) ) :
function purplepastels_theme_comment_form_args($user_identity, $post_id, $req) {
global $purplepastels_theme_options;
$args = array(
'comment_notes_before' => '',
'must_log_in' => '' . sprintf( __( 'You must be logged in to post a comment. If you choose to login - or register - on this site, a non-tracking cookie will be stored on your computer but your email address will never be published or shared.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '
',
'logged_in_as' => '' . sprintf( __( 'Logged in as %s . Log out?
', 'purplepastels' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ),
'comment_field' => '',
'label_submit'=>'Submit Reply', 'purplepastels'
);
if(!isset($purplepastels_theme_options['display_kses']) || $purplepastels_theme_options['display_kses'] == 'yes') $args['comment_notes_after'] = '' . sprintf( __( 'You may use these HTML tags and attributes: %s', 'purplepastels' ), ' ' . allowed_tags() . '' ) . '
';
else $args['comment_notes_after'] = '';
return $args;
}
endif;
// Make sure we always have a post/page title
if( !function_exists( 'purplepastels_correct_missing_title' ) ) :
function purplepastels_correct_missing_title( $title ) {
if( $title == '' ) $title = __('No Title', 'purplepastels');
return $title;
}
endif;
add_filter( 'the_title', 'purplepastels_correct_missing_title' );
// Amend post password form
if( !function_exists ('purplepastels_password_form') ) :
function purplepastels_password_form() {
global $post;
$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
$output = '';
return $output;
}
endif;
add_filter('the_password_form','purplepastels_password_form');
// Amend password protected standard excerpt
if( !function_exists ('purplepastels_password_excerpt') ) :
function purplepastels_password_excerpt($output) {
global $post;
if( post_password_required($post) ) $output = '' . __('This is a password protected post.', 'purplepastels') . '
';
return $output;
}
endif;
add_filter('the_excerpt','purplepastels_password_excerpt');
// Display a - b of x posts
if( !function_exists( 'purplepastels_theme_postlist_info' ) ) :
function purplepastels_theme_postlist_info($my_tot_pages, $paged, $found_posts) {
if( $paged == '') $my_curr_page = 1;
else $my_curr_page = $paged;
$my_finish = $my_curr_page * get_option('posts_per_page');
if( $found_posts < $my_finish ) $my_finish = $found_posts;
if( $paged == '') $my_start = 1; // first page
elseif( $paged == $my_tot_pages ) $my_start = ($my_tot_pages-1) * get_option('posts_per_page') +1; // last page
else $my_start = 1 + $my_finish - get_option('posts_per_page');
if( $my_finish > 1 ) {
$format = __('Displaying %1$s - %2$s of %3$s entries.','purplepastels') ;
printf( $format, $my_start, $my_finish, $found_posts);
}
else _e('Displaying 1 entry.','purplepastels');
}
endif;
// Ouput attachment image size
if( !function_exists( 'purplepastels_attachment_image_size' ) ) :
function purplepastels_attachment_image_size($excerpt) {
global $post;
if( wp_attachment_is_image() ) {
$metadata = wp_get_attachment_metadata();
$excerpt .= ' ' . sprintf( __('Full size image: %1$s x %2$s', 'purplepastels'), $metadata['width'], $metadata['height'] );
}
return $excerpt;
}
endif;
add_filter('get_the_excerpt', 'purplepastels_attachment_image_size');
// WIDGETS
/* Register widgets */
function purplepastels_load_widgets() {
if( function_exists ( 'wp_login_form' ) ) register_widget( 'Login_Form_Widget' );
}
add_action( 'widgets_init', 'purplepastels_load_widgets' );
class Login_Form_Widget extends WP_Widget {
function Login_Form_Widget() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'login-form-widget', 'description' => __('Display a form to login or register on your blog', 'purplepastels') );
/* Widget control settings. */
$control_ops = array( 'id_base' => 'login-widget' );
/* Create the widget. */
$this->WP_Widget( 'login-widget', __('Login Form', 'purplepastels'), $widget_ops, $control_ops );
}
// Widget pre-display
function widget( $args, $instance ) {
extract( $args );
/* User-selected settings. */
$title = apply_filters('widget_title', $instance['title'] );
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
$form = wp_login_form(array('echo' => false));
echo $this->widget_strip_unwanted($form);
echo $after_widget;
}
// Widget strip tabindexing
function widget_strip_unwanted($form) {
$form = str_replace(' name="loginform"', '' , $form);
$form = str_replace(' tabindex="10"', '' , $form);
$form = str_replace(' tabindex="20"', '' , $form);
$form = str_replace(' tabindex="100"', '' , $form);
return $form;
}
// Widget save/update
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags (if needed) and update the widget settings. */
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
// Widget Admin form
function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'title' => __('Login', 'purplepastels') );
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
(.*?)#s", '', $css );
}
add_filter( 'gallery_style', 'purplepastels_remove_gallery_css' );
// Create decent attachment links
function purplepastels_attachment_link($id) {
// grab file extension
$bits = explode('.',get_attached_file($id));
$ext = '.'.$bits[count($bits)-1].' format';
// get the icon link
$icon_link = wp_get_attachment_link($id,'thumbnail',false,true);
// get the text link
$text_link = wp_get_attachment_link($id,'',false,false);
// get the filesize in kilobytes
if(@filesize(get_attached_file($id))) {
$filesize = ceil(filesize(get_attached_file($id))/1024).'K';
return $icon_link. ' '.$text_link .' (' .$ext .' ' . $filesize .') ';
}
else return $icon_link . ' ' . $text_link .' (' . $ext . ') ';
}
// Accordion menu setup
function purplepastels_init_accordian() {
wp_enqueue_script('accordian',
get_template_directory_uri() . '/library/accordian-menu.js',
array('jquery'),
'3.0.2'
);
}
// Thickbox setup
function purplepastels_thickbox_init() {
if (wp_attachment_is_image() ) add_thickbox();
}
function purplepastels_load_tb_fix() {
if( is_attachment() ) :?>
post_parent ) {
$children = wp_list_pages('title_li=&child_of='.$this_page->ID.'&echo=0');
if( $children ) {
$pagelist .= '' . $this_page->post_title . ' ';
$pagelist .= '';
$pagelist .= ' ';
}
}
elseif( $this_page->ancestors ) {
// get the top ID of this page. Page ids DESC so top level ID is the last one
$ancestor = end($this_page->ancestors);
$pagelist .= wp_list_pages('title_li=&include='.$ancestor.'&echo=0');
$pagelist = str_replace('', '', $pagelist);
$pagelist .= '' . wp_list_pages('title_li=&child_of='.$ancestor.'&echo=0') .' ';
}
return $pagelist;
}
// Get archive date
function purplepastels_get_archive_date() {
if (is_day()) $this_archive = get_the_time('j F Y');
elseif (is_month()) $this_archive = get_the_time('F Y');
else $this_archive = get_the_time('Y');
return $this_archive;
}
// get category & it's children as an array of ids
function purplepastels_get_cat_tree($parent) {
$term_objs = get_term_children( $parent, 'category' );
$term_objs[] =$parent;
return $term_objs;
}
/* purplepastels_enhanced_cat_list
* Echoes the wp_list_categories output with extra class applied to the topmost parent category.
* Relies on purplepastels_top_cats()
* @param string $curr_cat: Current Category ID
* @param string $catlist: Ouput from wp_list_categories
* @param string Optional $extra_class: Additonal class to be added to the li element. Defaults to 'current-cat-ancestor'.
*
**/
function purplepastels_enhanced_cat_list($curr_cat_id,$catlist, $extra_class='current-cat-ancestor') {
$top_cats = purplepastels_top_cats();
foreach( $top_cats as $top_cat) {
if( cat_is_ancestor_of($top_cat, $curr_cat_id) ) {
$cat_ancestor_class = 'cat-item-'. $top_cat;
$amended_class = $cat_ancestor_class . ' ' . $extra_class;
break;
}
else $cat_ancestor_class = '';
}
if( $cat_ancestor_class != '' && stristr( $catlist, $cat_ancestor_class) ) $new_catlist = str_replace($cat_ancestor_class, $amended_class, $catlist );
else $new_catlist = $catlist;
echo $new_catlist;
}
// Get ids for all top level (parent) categories
// Used by purplepastels_enhanced_cat_list
function purplepastels_top_cats() {
$toplevel = array();
$allcats = get_terms('category', 'orderby=name&hide_empty=0');
foreach( $allcats as $cat ) {
if( $cat->parent == 0) $toplevel[] = $cat->term_id;
}
return $toplevel;
}
// HEADER & BACKGROUND CUSTOMISATION
define('HEADER_IMAGE_WIDTH', apply_filters( 'purplepastels_header_image_width',960 ) );
define('HEADER_IMAGE_HEIGHT', apply_filters( 'purplepastels_header_image_height', 139 ) );
define('HEADER_IMAGE', apply_filters( 'purplepastels_header_image', get_stylesheet_directory_uri() . '/images/header.jpg') );
define('HEADER_TEXTCOLOR', apply_filters( 'purplepastels_header_textcolor','64468B') );
// Background customisation
// Add support for custom background
if( function_exists ('add_custom_background') ) add_custom_background($header_callback = 'purplepastels_custom_background_cb', $admin_header_callback = '', $admin_image_div_callback = 'purplepastels_admin_image_div_callback');
define ('BACKGROUND_COLOR', apply_filters( 'purplepastels_background_color','f4f1f5') );
define ('BACKGROUND_IMAGE', apply_filters( 'purplepastels_background_image', get_stylesheet_directory_uri() . '/images/left.jpg') );
define ('BACKGROUND_IMAGE_RIGHT', apply_filters( 'purplepastels_header_image_right', get_stylesheet_directory_uri() . '/images/right.jpg') );
/* Custom background callback for site display */
if( ! function_exists( 'purplepastels_custom_background_cb' ) ) :
function purplepastels_custom_background_cb() {
$background = get_background_image();
$color = get_background_color();
if( ! $background && ! $color )
return;
$style = $color ? "background-color: #$color;" : '';
if( $background ) {
$image = " background-image: url('$background');";
$repeat = get_theme_mod( 'background_repeat', 'no-repeat' );
if( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) $repeat = 'repeat';
$repeat = " background-repeat: $repeat;";
$position = get_theme_mod( 'background_position_x', 'left' );
if( ! in_array( $position, array( 'center', 'right', 'left' ) ) ) $position = 'left';
$position = " background-position: top $position;";
$attachment = get_theme_mod( 'background_attachment', 'fixed' );
if( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) ) $attachment = 'scroll';
$attachment = " background-attachment: $attachment;";
$style .= $image . $repeat . $position . $attachment;
if( $background != BACKGROUND_IMAGE ) $outer_style = 'background:transparent;';
else $outer_style = '';
}
else {
$style .= 'background-image:none;';
$outer_style = 'background-image:none;';
}
?>