ID;
if ( ! $post_id ) $header_img = get_header_image();
if ( ! $header_img && is_singular() && has_post_thumbnail( $post_id ) ) {
$image_id = get_post_thumbnail_id( $post_id );
$image_meta = wp_get_attachment_metadata( $image_id );
if ( $image_meta && $image_meta['width'] >= HEADER_IMAGE_WIDTH && ! $blograzzi_settings['featured_img_header'] ) {
$image = wp_get_attachment_image_src( $image_id, 'post-thumbnail' );
$header_img = $image[0];
}
}
if ( ! $header_img ) $header_img = get_header_image();
return apply_filters( 'blograzzi_header_image', $header_img, $post_id );
}
endif;
/**
* Get the attachment ID from the source URL
*
* @package Blograzzi
* @since 1.9
*/
function blograzzi_get_attachment_id_from_src( $image_src ) {
global $wpdb;
$query = $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid='%s'", $image_src );
$id = $wpdb->get_var($query);
return $id;
}
/**
* Get the alt text for the header image
*
* @package Blograzzi
* @since 1.9
*/
function blograzzi_get_header_image_alt( $image_src ){
$image_id = blograzzi_get_attachment_id_from_src( $image_src );
if ( ! $image_id ) return;
$alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
return $alt;
}
/**
* Get the HTML tag for image
*
* @package Blograzzi
* @since 2.1
*/
function blograzzi_get_image_html( $image_src_or_id, $size = '' ){
global $blograzzi_settings;
if ( ! is_numeric( $image_src_or_id ) ) {
$image_id = blograzzi_get_attachment_id_from_src( $image_src_or_id );
if ( ! $image_id ) {
$html = '
';
return $html;
}
} else $image_id = $image_src_or_id;
$image = wp_get_attachment_image( $image_id, $size );
return $image;
}
/**
* This functions adds additional classes to the
element. The additional classes
* are added by filtering the WordPress body_class() function.
*/
function blograzzi_body_class( $classes ){
global $blograzzi_settings;
if ( $blograzzi_settings['slider_full_width'] ) $classes[] = 'full-width-slider';
if ( $blograzzi_settings['slider_position'] ) $classes[] = 'bottom-slider';
$column_mode = blograzzi_column_mode();
$classes[] = $column_mode;
// for easier CSS
if ( strpos( $column_mode, 'two_col' ) === 0 ){
$classes[] = 'two-columns';
} else if ( strpos( $column_mode, 'three_col' ) === 0 ){
$classes[] = 'three-columns';
}
if ( has_nav_menu( 'secondary-menu' ) ) $classes[] = 'have-secondary-menu';
if ( is_singular() ) $classes[] = 'singular';
// Prints the body class
return $classes;
}
add_filter( 'body_class', 'blograzzi_body_class' );
/**
* Add Social Media icons in top bar
*/
function blograzzi_top_bar_social(){
global $blograzzi_settings;
/* Loop through the registered custom social modia */
$social_profiles = $blograzzi_settings['social_profiles'];
if ( in_array( false, $social_profiles) ) return;
?>
$social_profile ) :
if ( ! empty( $social_profile['url'] ) || $social_profile['type'] == 'rss' ) :
$title = blograzzi_determine_social_medium_title( $social_profile );
$class = 'mysocial social-' . $social_profile['type'];
$id = 'social-id-' . $count;
$extra = $blograzzi_settings['social_media_new_window'] ? ' target="_blank"' : '';
$extra = apply_filters( 'blograzzi_social_media_attr', $extra, $title, $class, $id );
$url = ( $social_profile['type'] == 'rss' && empty( $social_profile['url'] ) ) ? get_bloginfo('rss2_url') : $social_profile['url'];
$icon_url = '';
$icon_name = '';
if ( $social_profile['type'] == 'custom' ) {
$icon_url = $social_profile['icon_url'];
$icon_name = $social_profile['icon_name'];
$class = 'mysocial social-custom';
}
?>
-
>
tag.
*
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @param int $size Size of the avatar image
* @param string $default URL to a default image to use if no avatar is available
* @param string $alt Alternate text to use in image tag. Defaults to blank
* @return string URL for the user's avatar
*
* @package Blograzzi
* @since 1.6
*/
function blograzzi_get_avatar_uri( $id_or_email, $size = '96', $default = '', $alt = false ) {
// Silently fails if < PHP 5
if ( ! function_exists( 'simplexml_load_string' ) ) return;
$avatar = get_avatar( $id_or_email, $size, $default, $alt );
if ( ! $avatar ) return false;
$avatar_xml = simplexml_load_string( $avatar );
$attr = $avatar_xml->attributes();
$src = $attr['src'];
return apply_filters( 'blograzzi_get_avatar_url', $src, $id_or_email, $size, $default, $alt );
}
endif;
function blograzzi_feed_link($output, $feed) {
global $blograzzi_settings;
if ( ( $feed == 'rss2' || $feed == 'rss' )
&& $blograzzi_settings['use_custom_rss_feed'] && ! empty( $blograzzi_settings['custom_rss_feed_url'] ) ) {
$output = $blograzzi_settings['custom_rss_feed_url'];
}
return $output;
}
add_filter( 'feed_link', 'blograzzi_feed_link', 1, 2 );
/**
* Displays a notice to logged in users if there is no widgets placed in the displayed sidebars
*/
function blograzzi_sidebar_notice( $sidebar_name = '' ){
$html = '';
$html .= sprintf( __( 'You haven\'t placed any widget into this widget area. Go to %1$s and place some widgets in the widget area called %2$s.', 'blograzzi' ), '' . __( 'WP Admin > Appearance > Widgets', 'blograzzi' ) . '', '' . $sidebar_name . '' ) . '
';
$html .= '' . __( "This notice will not be displayed to your site's visitors.", 'blograzzi' ) . '
';
echo '' . apply_filters( 'blograzzi_sidebar_notice', $html, $sidebar_name ) . '
';
}
/**
* Apply the correct column mode for static posts page as per its page template
*
* @package Blograzzi
* @since 1.9
*/
function blograzzi_posts_page_column(){
if ( ! is_home() ) return;
$home_page = get_option( 'page_for_posts' );
if ( ! $home_page ) return;
$template = get_post_meta( $home_page, '_wp_page_template', true );
if ( ! $template || $template == 'default' ) return;
global $blograzzi_settings;
switch ( $template ) {
case 'template-onecolumn.php': $blograzzi_settings['column_mode'] = 'one_column'; break;
case 'template-twocolumnsleft.php': $blograzzi_settings['column_mode'] = 'two_col_left'; break;
case 'template-twocolumnsright.php': $blograzzi_settings['column_mode'] = 'two_col_right'; break;
case 'template-threecolumnsleft.php': $blograzzi_settings['column_mode'] = 'three_col_left'; break;
case 'template-threecolumnscenter.php': $blograzzi_settings['column_mode'] = 'three_col_center'; break;
case 'template-threecolumnsright.php': $blograzzi_settings['column_mode'] = 'three_col_right'; break;
}
}
add_action( 'template_redirect', 'blograzzi_posts_page_column' );