Skip to content

Commit

Permalink
Merge pull request #519 from x-team/issue-518
Browse files Browse the repository at this point in the history
Fix for Show Avatars disabled, issue #518
  • Loading branch information
frankiejarrett committed May 11, 2014
2 parents 6d49dd8 + 6c01221 commit b10e5ca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
38 changes: 29 additions & 9 deletions includes/class-wp-stream-author.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class WP_Stream_Author {
function __construct( $user_id, $author_meta = array() ) {
$this->id = $user_id;
$this->meta = $author_meta;

if ( $this->id ) {
$this->user = new WP_User( $this->id );
}
Expand Down Expand Up @@ -91,10 +92,18 @@ function get_agent() {
}

/**
* @param int $size
* @return string
* Return a Gravatar image as an HTML element.
*
* This function will not return an avatar if "Show Avatars" is unchecked in Settings > Discussion.
*
* @param int $size (optional) Size of Gravatar to return (in pixels), max is 512, default is 80
* @return string An img HTML element
*/
function get_avatar_img( $size = 80 ) {
if ( ! get_option( 'show_avatars' ) ) {
return false;
}

if ( 0 === $this->id ) {
$url = WP_STREAM_URL . 'ui/stream-icons/wp-cli.png';
$avatar = sprintf( '<img alt="%1$s" src="%2$s" class="avatar avatar-%3$s photo" height="%3$s" width="%3$s">', esc_attr( $this->get_display_name() ), esc_url( $url ), esc_attr( $size ) );
Expand All @@ -111,12 +120,20 @@ function get_avatar_img( $size = 80 ) {
}

/**
* @param int $size
* @return string
* Return the URL of a Gravatar image.
*
* @param int $size (optional) Size of Gravatar to return (in pixels), max is 512, default is 80
* @return string Gravatar image URL
*/
function get_avatar_src( $size = 80 ) {
$img = $this->get_avatar_img( $size );
assert( preg_match( '/src=([\'"])(.*?)\1/', $img, $matches ) );

if ( ! $img ) {
return false;
}

preg_match( '/src=([\'"])(.*?)\1/', $img, $matches );

$src = html_entity_decode( $matches[2] );

return $src;
Expand All @@ -125,10 +142,13 @@ function get_avatar_src( $size = 80 ) {
/**
* Tries to find a label for the record's author_role.
*
* If the author_role exists, use the label associated with it
* Otherwise, if there is a user role label stored as Stream meta then use that
* Otherwise, if the user exists, use the label associated with their current role
* Otherwise, use the role slug as the label
* If the author_role exists, use the label associated with it.
*
* Otherwise, if there is a user role label stored as Stream meta then use that.
*
* Otherwise, if the user exists, use the label associated with their current role.
*
* Otherwise, use the role slug as the label.
*
* @return string|null
*/
Expand Down
21 changes: 11 additions & 10 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class WP_Stream_Settings {
* @return \WP_Stream_Settings
*/
public static function load() {

self::$option_key = self::get_option_key();
self::$options = self::get_options();

Expand All @@ -69,7 +68,6 @@ public static function load() {

// Ajax callback function to search IPs
add_action( 'wp_ajax_stream_get_ips', array( __CLASS__, 'get_ips' ) );

}

/**
Expand Down Expand Up @@ -126,8 +124,8 @@ public static function get_users(){
$author = new WP_Stream_Author( $user->ID );

$args = array(
'id' => $author->ID,
'text' => $author->display_name,
'id' => $author->ID,
'text' => $author->display_name,
);

$args['tooltip'] = esc_attr(
Expand Down Expand Up @@ -193,16 +191,15 @@ public static function get_ips(){
/**
* Filter the columns to search in a WP_User_Query search.
*
*
* @param array $search_columns Array of column names to be searched.
* @param string $search Text being searched.
* @param WP_User_Query $query current WP_User_Query instance.
*
*
* @return array
*/
public static function add_display_name_search_columns( $search_columns, $search, $query ){
$search_columns[] = 'display_name';

return $search_columns;
}

Expand Down Expand Up @@ -427,7 +424,6 @@ public static function get_defaults() {
$defaults
)
);

}

/**
Expand All @@ -436,7 +432,6 @@ public static function get_defaults() {
* @return void
*/
public static function register_settings() {

$sections = self::get_fields();

register_setting( self::$option_key, self::$option_key );
Expand Down Expand Up @@ -483,6 +478,7 @@ public static function updated_option_trigger_flush_rules( $old_value, $new_valu
if ( is_array( $new_value ) && is_array( $old_value ) ) {
$new_value = ( array_key_exists( 'general_private_feeds', $new_value ) ) ? $new_value['general_private_feeds'] : 0;
$old_value = ( array_key_exists( 'general_private_feeds', $old_value ) ) ? $old_value['general_private_feeds'] : 0;

if ( $new_value !== $old_value ) {
delete_option( 'rewrite_rules' );
}
Expand All @@ -496,8 +492,7 @@ public static function updated_option_trigger_flush_rules( $old_value, $new_valu
* @return string HTML to be displayed
*/
public static function render_field( $field ) {
$output = null;

$output = null;
$type = isset( $field['type'] ) ? $field['type'] : null;
$section = isset( $field['section'] ) ? $field['section'] : null;
$name = isset( $field['name'] ) ? $field['name'] : null;
Expand Down Expand Up @@ -777,11 +772,13 @@ public static function render_field( $field ) {
*/
public static function output_field( $field ) {
$method = 'output_' . $field['name'];

if ( method_exists( __CLASS__, $method ) ) {
return call_user_func( array( __CLASS__, $method ), $field );
}

$output = self::render_field( $field );

echo $output; // xss okay
}

Expand Down Expand Up @@ -827,6 +824,7 @@ public static function get_default_connectors() {
*/
public static function get_terms_labels( $column ) {
$return_labels = array();

if ( isset ( WP_Stream_Connectors::$term_labels[ 'stream_' . $column ] ) ) {
$return_labels = WP_Stream_Connectors::$term_labels[ 'stream_' . $column ];
ksort( $return_labels );
Expand Down Expand Up @@ -855,10 +853,13 @@ public static function get_active_connectors() {
public static function get_excluded_by_key( $column ) {
$option_name = 'exclude_' . $column;
$excluded_values = ( isset( self::$options[ $option_name ] ) ) ? self::$options[ $option_name ] : array();

if ( is_callable( $excluded_values ) ) {
$excluded_values = call_user_func( $excluded_values );
}

$excluded_values = wp_list_filter( $excluded_values, array( '__placeholder__' ), 'NOT' );

return $excluded_values;
}

Expand Down
2 changes: 1 addition & 1 deletion ui/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ jQuery(function($){
formatResult: function (object, container) {
var result = object.text;

if ('undefined' !== typeof object.icon) {
if ('undefined' !== typeof object.icon && object.icon) {
result = '<img src="' + object.icon + '" class="wp-stream-select2-icon">' + result;
// Add more info to the container
container.attr('title', object.tooltip);
Expand Down

0 comments on commit b10e5ca

Please sign in to comment.