Skip to content

Instantly share code, notes, and snippets.

@gioxx
Last active Oct 14, 2020
Embed
What would you like to do?
Disqus Recents Widget per WordPress, vedi https://gioxx.org/2014/01/10/disqus-recent-comments-per-wordpress/
<?php
/*
Plugin Name: Disqus Recents Widget
Plugin URI: https://public.gfsolone.com/wiki/doku.php?id=wordpress:disqusrecents
Description: Mostra gli ultimi commenti lasciati nel sistema Disqus installato sul tuo Wordpress.
Version: 0.8
Author: Gioxx
Author URI: https://gioxx.org
License: CC BY-NC-SA 4.0
*/
/*
Vedi dettaglio licenza di rilascio: https://creativecommons.org/licenses/by-nc-sa/4.0/deed.it
Basato su Codex Wordpress: https://codex.wordpress.org/Widgets_API
Grazie a: https://gist.github.com/flowcomm/4174893
-2013- Gioxx (dev@gfsolone.com)
Ult. mod. 21/2/18
0.8- corretti puntamenti immagini (HTTPS) e modificata versione licenza CC (4.0). Variata l'icona blog, messo a posto dettaglio estetico (un padding-right in più).
0.7- corretti puntamenti verso Disqus (HTTPS).
0.6- i contenuti vengono caricati da Disqus in HTTPS. Migliorato hint su DISQUS ID da inserire nel widget.
IL CONTENUTO DI QUESTO FILE PHP VIENE FORNITO AS-IS
*/
class DsqRecents_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
parent::__construct(
'dsqrecents_widget', // Base ID
'Disqus Recents Widget', // Name
array( 'description' => __( 'Mostra gli ultimi commenti recuperati dal sistema Disqus (vedi documentazione)', 'text_domain' ), ) // Args
);
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$dsqid = apply_filters( 'widget_dsqid', $instance['dsqid'] );
$dsqitems = apply_filters( 'widget_dsqid', $instance['dsqitems'] );
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
// echo __( 'Stringa debug, dovrebbe comparire nel widget', 'text_domain' );
?>
<!-- Blocco commenti Disqus -->
<div id="recentcomments" class="dsq-widget">
<script type="text/javascript" src="https://<?php echo $dsqid; ?>.disqus.com/recent_comments_widget.js?num_items=<?php echo $dsqitems; ?>&hide_avatars=0&avatar_size=32&excerpt_length=200"></script>
</div><img src="https://gioxx.org/wp-content/uploads/2018/02/cropped-ICON_path231-32x32.png" style="max-width: 16px; float: left; padding-right: 10px;" /><a href="https://public.gfsolone.com/wiki/doku.php?id=wordpress:disqusrecents" style="font-size: x-small; font-variant: small-caps;" />Disqus Recents Widget</a>
<?php
echo $after_widget;
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['dsqid'] = strip_tags( $new_instance['dsqid'] );
$instance['dsqitems'] = strip_tags( $new_instance['dsqitems'] );
return $instance;
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'Recent Comments', 'text_domain' );
}
if ( isset( $instance[ 'dsqid' ] ) ) {
$dsqid = $instance[ 'dsqid' ];
}
else {
$dsqid = __( 'gioxx', 'text_domain' );
}
if ( isset( $instance[ 'dsqitems' ] ) ) {
$dsqitems = $instance[ 'dsqitems' ];
}
else {
$dsqitems = __( '5', 'text_domain' );
}
?>
<p>
<!-- Titolo del widget -->
<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 ); ?>" />
<!-- ID DISQUS: ID.disqus.com -->
<label for="<?php echo $this->get_field_id( 'dsqid' ); ?>"><?php _e( 'Disqus ID (insert only first part of the URL, for example: <strong>UTENTE</strong>.disqus.com &rarr; utente):' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'dsqid' ); ?>" name="<?php echo $this->get_field_name( 'dsqid' ); ?>" type="text" value="<?php echo esc_attr( $dsqid ); ?>" />
<!-- Numero commenti da caricare -->
<label for="<?php echo $this->get_field_id( 'dsqitems' ); ?>"><?php _e( 'Items to load:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'dsqitems' ); ?>" name="<?php echo $this->get_field_name( 'dsqitems' ); ?>" type="text" value="<?php echo esc_attr( $dsqitems ); ?>" />
<br /><br />
<a href="https://public.gfsolone.com/wiki/doku.php?id=wordpress:disqusrecents">Help me!</a><br />
<a href="https://gfsolone.com"><img src="https://gioxx.org/wp-content/uploads/gfsolone.footer.png"></a>
</p>
<?php
}
} // class Widget terminata
// Registrazione del widget
add_action( 'widgets_init', create_function( '', 'register_widget( "dsqrecents_widget" );' ) );
?>
@albo82
Copy link

albo82 commented Oct 14, 2020

Hi Giovanni, thanks for your plugin/code!!!
I would like to remove the link from the name of the commenters and from the date ("2 day ago"), is it possible? How can i do that?
Thanks!!!

@gioxx
Copy link
Author

gioxx commented Oct 14, 2020

Ciao albo82, I think you can because Disqus changed the method to get the latest comments from his platform (take a look here: https://disqus.com/api/docs/posts/list/). I want to change my widget code in the near future and publish the new one to take the advantage to use json and not javascript anymore.
Stay tuned or try to code something to test new Disqus APIs (on a Wordpress test environment) ;-)

Bye!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment