2021-10-08 21:44:56 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Plugin Name: Co-Authors Widget Dev
|
|
|
|
Description: The plugin add a widget and a shortcode in order to show authors of an article. It is compatible with Co-Authors Plus.
|
2021-10-12 15:01:10 +02:00
|
|
|
Version: 2021.1012
|
2021-10-08 21:44:56 +02:00
|
|
|
Author: Gianluigi Filippelli
|
|
|
|
Author URI: http://dropseaofulaula.blogspot.it/
|
2021-10-08 22:27:40 +02:00
|
|
|
Plugin URI: https://gitea.it/ulaulaman/widget-for-co-authors-dev
|
|
|
|
Gitea Plugin URI: https://gitea.it/ulaulaman/widget-for-co-authors-dev
|
2021-10-08 21:44:56 +02:00
|
|
|
License: GPLv2 or later
|
|
|
|
*/
|
2021-10-08 22:27:40 +02:00
|
|
|
|
2021-10-08 21:44:56 +02:00
|
|
|
// Load translations
|
2021-10-08 22:27:40 +02:00
|
|
|
add_action( 'plugins_loaded', 'caw_load_translations' );
|
2021-10-08 21:44:56 +02:00
|
|
|
function caw_load_translations() {
|
2021-10-08 22:27:40 +02:00
|
|
|
load_plugin_textdomain( 'widget-for-co-authors', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
|
2021-10-08 21:44:56 +02:00
|
|
|
}
|
|
|
|
|
2021-10-08 22:27:40 +02:00
|
|
|
// Shortcode to show authors
|
|
|
|
add_shortcode( 'blog-post-coauthors', 'blog_post_coauthors' );
|
2021-10-08 21:44:56 +02:00
|
|
|
function blog_post_coauthors() {
|
|
|
|
return coauthors_posts_links(", ", " & ", null, null, false);
|
|
|
|
}
|
|
|
|
|
2021-10-08 22:27:40 +02:00
|
|
|
// Widget to show authors' avatars
|
2021-10-08 22:41:20 +02:00
|
|
|
function blog_avatars() {
|
2021-10-08 22:27:40 +02:00
|
|
|
$show_profile = __( 'Show profile', 'widget-for-co-authors' );
|
|
|
|
$hide_profile = __( 'Hide profile', 'widget-for-co-authors' );
|
|
|
|
|
|
|
|
if ( function_exists( 'get_coauthors' ) ) {
|
|
|
|
$coauthors = get_coauthors();
|
|
|
|
$user_posts = get_author_posts_url( $coauthor->ID, $coauthor->user_nicename );
|
|
|
|
|
|
|
|
$i = 0;
|
2021-10-08 22:33:21 +02:00
|
|
|
foreach ( $coauthors as $coauthor ) {
|
2021-10-08 22:27:40 +02:00
|
|
|
$i++;
|
|
|
|
|
|
|
|
?>
|
|
|
|
<div class="block-item-text">
|
|
|
|
<input type="checkbox" hidden class="read-more-state" id="<?php echo $i; ?>" />
|
|
|
|
<div class="read-more-wrap">
|
2021-10-12 15:01:10 +02:00
|
|
|
<div class="avatar right"><?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></div><span class="read-more-target"><?php echo $coauthor->description; ?></span>
|
2021-10-08 22:27:40 +02:00
|
|
|
</div>
|
|
|
|
<label for="<?php echo $i; ?>" class="read-more-trigger_closed">
|
|
|
|
<strong>+ <?php printf( $show_profile ); ?></strong>
|
|
|
|
</label>
|
|
|
|
<label for="<?php echo $i; ?>" class="read-more-trigger_opened">
|
|
|
|
<strong>- <?php printf( $hide_profile ); ?></strong>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$i = 0;
|
2021-10-08 21:44:56 +02:00
|
|
|
?>
|
2021-10-08 22:27:40 +02:00
|
|
|
<div class="block-item-text">
|
|
|
|
<input type="checkbox" hidden class="read-more-state" id="<?php echo $i; ?>" />
|
|
|
|
<div class="read-more-wrap">
|
2021-10-12 15:01:10 +02:00
|
|
|
<div class="avatar right"><?php echo get_avatar( get_the_author_meta( 'user_email' ), 65 ); ?><a href="<?php echo get_the_author_meta( 'user_url' ); ?>"><?php echo get_the_author_meta( 'display_name' ); ?></a></div><span class="read-more-target"><?php echo get_the_author_meta( 'description' ); ?></span>
|
2021-10-08 22:27:40 +02:00
|
|
|
</div>
|
|
|
|
<label for="<?php echo $i; ?>" class="read-more-trigger_closed">
|
|
|
|
<strong>+ <?php printf( $show_profile ); ?></strong>
|
|
|
|
</label>
|
|
|
|
<label for="<?php echo $i; ?>" class="read-more-trigger_opened">
|
|
|
|
<strong>- <?php printf( $hide_profile ); ?></strong>
|
|
|
|
</label>
|
|
|
|
</div>
|
2021-10-08 21:44:56 +02:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function blog_enqueue() {
|
2021-10-08 22:27:40 +02:00
|
|
|
wp_register_style( 'blog-spoiler-style', plugins_url('/blog-spoiler.css', __FILE__) );
|
|
|
|
wp_enqueue_style( 'blog-spoiler-style' );
|
2021-10-08 21:44:56 +02:00
|
|
|
}
|
|
|
|
add_action( 'wp_enqueue_scripts', 'blog_enqueue' );
|
|
|
|
|
2021-10-08 22:27:40 +02:00
|
|
|
// Shortcode authors' avatars
|
2021-10-08 21:44:56 +02:00
|
|
|
add_shortcode('blog-coauthors-avatars', 'blog_coauthors_avatars');
|
|
|
|
function blog_coauthors_avatars() {
|
2021-10-08 22:27:40 +02:00
|
|
|
return blog_avatars();
|
2021-10-08 21:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Widget register
|
|
|
|
function blog_load_widget() {
|
2021-10-08 22:27:40 +02:00
|
|
|
register_widget( 'blog_widget' );
|
2021-10-08 21:44:56 +02:00
|
|
|
}
|
|
|
|
add_action( 'widgets_init', 'blog_load_widget' );
|
|
|
|
|
|
|
|
// Widget load
|
|
|
|
class blog_widget extends WP_Widget {
|
|
|
|
|
2021-10-08 22:27:40 +02:00
|
|
|
function __construct() {
|
|
|
|
parent::__construct(
|
|
|
|
|
|
|
|
// Widget ID
|
|
|
|
'blog_widget',
|
|
|
|
|
|
|
|
// Widget name in UI
|
|
|
|
__('Authors', 'widget-for-co-authors'),
|
|
|
|
|
|
|
|
// Widget description
|
|
|
|
array( 'description' => __( 'Show avatars and names of the authors', 'widget-for-co-authors' ), ) );
|
|
|
|
}
|
2021-10-08 21:44:56 +02:00
|
|
|
|
2021-10-08 22:27:40 +02:00
|
|
|
// Widget front-end
|
|
|
|
public function widget( $args, $instance ) {
|
|
|
|
$title = apply_filters( 'widget_title', $instance['title'] );
|
|
|
|
|
|
|
|
// before and after
|
|
|
|
echo $args['before_widget'];
|
|
|
|
if ( ! empty( $title ) )
|
|
|
|
echo $args['before_title'] . $title . $args['after_title'];
|
|
|
|
|
|
|
|
// output
|
|
|
|
blog_avatars();
|
|
|
|
echo $args['after_widget'];
|
|
|
|
}
|
2021-10-08 21:44:56 +02:00
|
|
|
|
2021-10-08 22:27:40 +02:00
|
|
|
// Widget backend
|
|
|
|
public function form( $instance ) {
|
|
|
|
if ( isset( $instance[ 'title' ] ) ) {
|
|
|
|
$title = $instance[ 'title' ];
|
|
|
|
} else {
|
|
|
|
$title = __( 'Written by', 'widget-for-co-authors' );
|
|
|
|
}
|
2021-10-08 21:44:56 +02:00
|
|
|
|
2021-10-08 22:27:40 +02:00
|
|
|
// Widget form
|
|
|
|
?>
|
|
|
|
<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
|
|
|
|
}
|
2021-10-08 21:44:56 +02:00
|
|
|
|
2021-10-08 22:27:40 +02:00
|
|
|
// Widget update
|
|
|
|
public function update( $new_instance, $old_instance ) {
|
|
|
|
$instance = array();
|
|
|
|
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
|
|
|
return $instance;
|
|
|
|
}
|
2021-10-08 21:44:56 +02:00
|
|
|
}
|
2021-10-08 22:27:40 +02:00
|
|
|
|
2021-10-08 21:44:56 +02:00
|
|
|
?>
|