Compare commits

..

No commits in common. "master" and "2020.0922" have entirely different histories.

4 changed files with 135 additions and 171 deletions

View File

@ -11,25 +11,17 @@ The plugin add also a slider in order to show user's profile. If you want change
3. Add the widget to your sidebar or the shortcode to your posts or pages.
# Changelog
* 2021.1013
* Add command for version number in css enqueue
* Update style
* 2021.1012 New style for show avatar
* 2021.1007 Best indentation and test new style
## 2020.0922
* 0.6 add author's info also in case Co-Authors Plus doesn't installed
* 0.5.3 add the correct lang files
* 0.5.2 fix error code in domain name in widget
* 0.5.1 fix error code in domain name for messages
* 0.5 support for translations
* 0.4 translation italian messages in english
* 0.3.1 test with wp 4.9.2
* 0.3 add profile link and css
* 0.2 creation of the widget to show authors' avatars
* 0.1 creation of the shortcode to add post's authors
0.6 add author's info also in case Co-Authors Plus doesn't installed<br/>
0.5.3 add the correct lang files<br/>
0.5.2 fix error code in domain name in widget<br/>
0.5.1 fix error code in domain name for messages<br/>
0.5 support for translations<br/>
0.4 translation italian messages in english<br/>
0.3.1 test with wp 4.9.2<br/>
0.3 add profile link and css<br/>
0.2 creation of the widget to show authors' avatars<br/>
0.1 creation of the shortcode to add post's authors
# Screenshot
![Screenshot](assets/screenshot-1.jpg)
<div align="center"><em>The result of the widget in a multiple authors post</em></div>
<div align="center"><img src="https://github.com/ulaulaman/widget-for-co-authors/blob/master/assets/screenshot-1.jpg?raw=true" /><br/>
<em>The result of the widget in a multiple authors post</em></div>

View File

@ -9,28 +9,3 @@
.read-more-state:checked ~ .read-more-trigger_closed {
display: none;
}
.avatar {
display: block;
padding: 3px;
margin-left: auto;
margin-right: auto;
vertical-align: baseline;
font: 11px/1.4em Arial, sans-serif;
text-align: center;
vertical-align: baseline;
}
.avatarimg {
vertical-align:middle;
margin-bottom: 3px;
width:92%;
}
.right {
float:right;
}
.left {
float:left;
}

View File

@ -24,18 +24,13 @@ The plugin add also a slider in order to show user's profile. If you want change
1. The result of the widget in a multiple authors post (italian language)
== Changelog ==
* 2021.1013
* Add command for version number in css enqueue
* Update style
* 2021.1012 New style for show avatar
* 2021.1007 Best indentation and test new style
* 0.6 add author's info also in case Co-Authors Plus doesn't installed
* 0.5.3 add the correct lang files
* 0.5.2 fix error code in domain name in widget
* 0.5.1 fix error code in domain name for messages
* 0.5 support for translations
* 0.4 translation italian messages in english
* 0.3.1 test with wp 4.9.2
* 0.3 add profile link and css
* 0.2 creation of the widget to show authors' avatars
* 0.1 creation of the shortcode to add post's authors
0.6 add author's info also in case Co-Authors Plus doesn't installed
0.5.3 add the correct lang files
0.5.2 fix error code in domain name in widget
0.5.1 fix error code in domain name for messages
0.5 support for translations
0.4 translation italian messages in english
0.3.1 test with wp 4.9.2
0.3 add profile link and css
0.2 creation of the widget to show authors' avatars
0.1 creation of the shortcode to add post's authors

View File

@ -2,154 +2,156 @@
/*
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.
Version: 2021.1012
Version: 2020.0922
Author: Gianluigi Filippelli
Author URI: http://dropseaofulaula.blogspot.it/
Plugin URI: https://gitea.it/ulaulaman/widget-for-co-authors-dev
Gitea Plugin URI: https://gitea.it/ulaulaman/widget-for-co-authors-dev
Plugin URI: https://github.com/ulaulaman/widget-for-co-authors
License: GPLv2 or later
*/
/* ------------------------------------------------------ */
# ---------------------------------------------------------
// Load translations
add_action( 'plugins_loaded', 'caw_load_translations' );
add_action('plugins_loaded', 'caw_load_translations');
function caw_load_translations() {
load_plugin_textdomain( 'widget-for-co-authors', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
load_plugin_textdomain( 'widget-for-co-authors', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
}
// Shortcode to show authors
add_shortcode( 'blog-post-coauthors', 'blog_post_coauthors' );
# Shortcode to show authors
add_shortcode('blog-post-coauthors', 'blog_post_coauthors');
function blog_post_coauthors() {
return coauthors_posts_links(", ", " & ", null, null, false);
}
// Widget to show authors' avatars
# Widget to show authors' avatars
function blog_avatars() {
$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;
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">
<div class="avatar">
<div class="avatarimg left" style="width:50%;"><?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>
</div>
</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;
$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;
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">
<div class="avatar">
<div class="avatarimg left"><?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>
</div>
</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>
<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>+ <?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;
?>
<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 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></p>
<p class="read-more-target">
<?php echo get_the_author_meta( 'description' ); ?>
</p>
</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
}
}
function blog_enqueue() {
wp_register_style( 'blog-spoiler-style', plugins_url('/blog-spoiler.css', __FILE__), rand(111,9999), '1' );
wp_enqueue_style( 'blog-spoiler-style' );
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' );
// Shortcode authors' avatars
# Shortcode authors' avatars
add_shortcode('blog-coauthors-avatars', 'blog_coauthors_avatars');
function blog_coauthors_avatars() {
return blog_avatars();
return blog_avatars();
}
// Widget register
function blog_load_widget() {
register_widget( 'blog_widget' );
register_widget( 'blog_widget' );
}
add_action( 'widgets_init', 'blog_load_widget' );
// Widget load
class blog_widget extends WP_Widget {
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' ), ) );
}
function __construct() {
parent::__construct(
// 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'];
}
// 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' ), )
);
}
// 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'];
}
// Widget backend
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
} else {
$title = __( 'Written by', 'widget-for-co-authors' );
}
// 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
}
// Widget update
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
// Widget backend
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'Written by', 'widget-for-co-authors' );
}
// 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
}
// Widget update
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
/* ------------------------------------------------------ */
?>