defaults = array(
'title' => __( 'Profile', $this->domain ),
'template' => '
- {avatar 100}
- {display_name}
- {description}
',
);
$this->WP_Widget( 'author-profile-widget-profile', __( 'Profile', $this->domain ), array(
'classname' => 'author-profile-widget-profile',
'description' => __( 'Author profile', $this->domain )
) );
}
/**
* form
* @param array $instance
*/
public function form( $instance ) {
$instance = $this->_parse_options( $instance );
?>
get_field_id( 'title' );
$title_name = $this->get_field_name( 'title' );
?>
get_field_id( 'template' );
$user_name = $this->get_field_name( 'template' );
?>
the_author_meta" field. e.g {user_login}', $this->domain ); ?>
domain ); ?>
_parse_options( $instance );
echo $args['before_widget'];
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
echo preg_replace_callback( '/\{(.+)\}/',
array( $this, '_parse_template' ),
$instance['template']
);
echo $args['after_widget'];
}
}
public function _parse_template( $matches ) {
$user_id = get_the_author_meta( 'ID' );
if ( is_author() ) {
global $author;
$user_id = $author;
}
if ( preg_match( '/^avatar ?(\d+)?$/', $matches[1], $reg ) ) {
$size = '';
if ( !empty( $reg[1] ) ) {
$size = $reg[1];
}
return get_avatar( $user_id, $size );
}
return get_the_author_meta( $matches[1], $user_id );
}
}