Created
February 8, 2015 18:37
-
-
Save imath/5384d920d781d35e4444 to your computer and use it in GitHub Desktop.
WP Idea Stream Custom : Replace the author avatar by the first image found in the idea content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Exit if accessed directly | |
if ( ! defined( 'ABSPATH' ) ) exit; | |
/** | |
* Replace the author avatar by the first image found in the idea content | |
* if no image was found keep the avatar. | |
*/ | |
function first_idea_image_as_avatar( $avatar_link, $author, $avatar, $idea ) { | |
if ( empty( $idea->post_content ) ) { | |
return $avatar_link; | |
} | |
preg_match_all( '/\<img.+src\=(?:\"|\')(.+?)(?:\"|\')(?:.+?)\>/', $idea->post_content, $matches ); | |
if ( empty( $matches[1][0] ) ) { | |
return $avatar_link; | |
return $matches[1][0]; | |
} | |
$image = '<img src="' . esc_attr( $matches[1][0] ) . '" class="thumbnail thumbnail-96" height="96px" width="96px" />'; | |
return '<a href="' . esc_url( wp_idea_stream_ideas_get_idea_permalink( $idea ) ) . '" title="' . esc_attr( $idea->post_title ) . '">' . $image . '</a>'; | |
} | |
add_filter( 'wp_idea_stream_ideas_get_author_avatar', 'first_idea_image_as_avatar', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment