2017-12-04 16:18:23 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Plugin Name: Co-Authors Widget
|
2018-01-23 16:23:59 +01:00
|
|
|
Description: The plugin add a widget and a shortcode in order to show authors of an article. It is compatible with Co-Authors Plus.
|
|
|
|
Version: 0.3.1
|
2017-12-04 16:18:23 +01:00
|
|
|
Author: Gianluigi Filippelli
|
|
|
|
Author URI: http://dropseaofulaula.blogspot.it/
|
2017-12-04 16:22:55 +01:00
|
|
|
Plugin URI: https://github.com/ulaulaman/co-authors-widget
|
2018-01-23 16:23:59 +01:00
|
|
|
License: GPLv2 or later
|
2017-12-04 16:18:23 +01:00
|
|
|
*/
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
# ---------------------------------------------------------
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
# Shortcode to show authors
|
2017-12-04 16:18:23 +01:00
|
|
|
add_shortcode('blog-post-coauthors', 'blog_post_coauthors');
|
|
|
|
function blog_post_coauthors() {
|
|
|
|
return coauthors_posts_links(", ", " e ", null, null, false);
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
# Widget to show authors' avatars
|
2017-12-04 16:18:23 +01:00
|
|
|
function blog_avatars() {
|
|
|
|
if ( function_exists( 'get_coauthors' ) ) {
|
|
|
|
$coauthors = get_coauthors();
|
|
|
|
$user_posts = get_author_posts_url( $coauthor->ID, $coauthor->user_nicename );
|
|
|
|
$i = 0;
|
|
|
|
foreach ( $coauthors as $coauthor ) {
|
|
|
|
$i++;
|
|
|
|
?>
|
|
|
|
<div class="block-item-text">
|
|
|
|
<input type="checkbox" hidden class="read-more-state" id="<?php echo $i; ?>">
|
|
|
|
<div class="read-more-wrap">
|
|
|
|
<p><?php echo coauthors_get_avatar( $coauthor, 65 ); ?>
|
|
|
|
<a href=<?php echo get_author_posts_url( $coauthor->ID, $coauthor->user_nicename ); ?>><?php echo $coauthor->display_name; ?></a></p>
|
|
|
|
<p class="read-more-target">
|
|
|
|
<?php echo $coauthor->description; ?>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<label for="<?php echo $i; ?>" class="read-more-trigger_closed">
|
|
|
|
<strong>+ Mostra profilo</strong>
|
|
|
|
</label>
|
|
|
|
<label for="<?php echo $i; ?>" class="read-more-trigger_opened">
|
|
|
|
<strong>- Nascondi profilo</strong>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
//
|
|
|
|
} else {
|
|
|
|
|
|
|
|
?>
|
|
|
|
<p><?php echo get_avatar( get_the_author_meta( 'user_email' ), 65 ); ?>
|
|
|
|
<a href=<?php echo get_author_posts_url( $coauthor->ID, $coauthor->user_nicename ); ?>><?php echo $coauthor->display_name; ?></a></p>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function blog_enqueue() {
|
|
|
|
wp_register_style( 'blog-spoiler-style', plugins_url('/blog-spoiler.css', __FILE__) );
|
|
|
|
wp_enqueue_style( 'blog-spoiler-style' );
|
|
|
|
}
|
|
|
|
add_action( 'wp_enqueue_scripts', 'blog_enqueue' );
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
# Shortcode authors' avatars
|
2017-12-04 16:18:23 +01:00
|
|
|
add_shortcode('blog-coauthors-avatars', 'blog_coauthors_avatars');
|
|
|
|
function blog_coauthors_avatars() {
|
|
|
|
return blog_avatars();
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// Widget register
|
2017-12-04 16:18:23 +01:00
|
|
|
function blog_load_widget() {
|
|
|
|
register_widget( 'blog_widget' );
|
|
|
|
}
|
|
|
|
add_action( 'widgets_init', 'blog_load_widget' );
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// Widget load
|
2017-12-04 16:18:23 +01:00
|
|
|
class blog_widget extends WP_Widget {
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
parent::__construct(
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// Widget ID
|
2017-12-04 16:18:23 +01:00
|
|
|
'blog_widget',
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// Widget name in UI
|
2017-12-04 16:18:23 +01:00
|
|
|
__('Autori Blog', 'blog_widget_domain'),
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// Widget description
|
2017-12-04 16:18:23 +01:00
|
|
|
array( 'description' => __( 'Widget per mostrare avatar e nomi degli autori', 'blog_widget_domain' ), )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// Widget front-end
|
2017-12-04 16:18:23 +01:00
|
|
|
public function widget( $args, $instance ) {
|
|
|
|
$title = apply_filters( 'widget_title', $instance['title'] );
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// before and after
|
2017-12-04 16:18:23 +01:00
|
|
|
echo $args['before_widget'];
|
|
|
|
if ( ! empty( $title ) )
|
|
|
|
echo $args['before_title'] . $title . $args['after_title'];
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// output
|
2017-12-04 16:18:23 +01:00
|
|
|
blog_avatars();
|
|
|
|
echo $args['after_widget'];
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// Widget backend
|
2017-12-04 16:18:23 +01:00
|
|
|
public function form( $instance ) {
|
|
|
|
if ( isset( $instance[ 'title' ] ) ) {
|
|
|
|
$title = $instance[ 'title' ];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$title = __( 'Articolo di', 'blog_widget_domain' );
|
|
|
|
}
|
2018-01-23 16:23:59 +01:00
|
|
|
|
|
|
|
// Widget form
|
2017-12-04 16:18:23 +01:00
|
|
|
?>
|
|
|
|
<p>
|
|
|
|
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
|
|
|
|
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
|
|
|
|
</p>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:23:59 +01:00
|
|
|
// Widget update
|
2017-12-04 16:18:23 +01:00
|
|
|
public function update( $new_instance, $old_instance ) {
|
|
|
|
$instance = array();
|
|
|
|
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
?>
|