Software : Apache/2.4.6 (CentOS) PHP/7.4.33 Widgets
*/
add_action( 'widgets_init', 'jetpack_goodreads_widget_init' );
function jetpack_goodreads_widget_init() {
register_widget( 'WPCOM_Widget_Goodreads' );
}
/**
* Goodreads widget class
* Display a user's Goodreads shelf.
* Customize user_id, title, and shelf
*
*/
class WPCOM_Widget_Goodreads extends WP_Widget {
private $goodreads_widget_id = 0;
function __construct() {
parent::__construct(
'wpcom-goodreads',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'Goodreads', 'jetpack' ) ),
array(
'classname' => 'widget_goodreads',
'description' => __( 'Display your books from Goodreads', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
// For user input sanitization and display
$this->shelves = array(
'read' => _x( 'Read', 'past participle: books I have read', 'jetpack' ),
'currently-reading' => __( 'Currently Reading', 'jetpack' ),
'to-read' => _x( 'To Read', 'my list of books to read', 'jetpack' ),
);
if ( is_active_widget( '', '', 'wpcom-goodreads' ) || is_customize_preview() ) {
add_action( 'wp_print_styles', array( $this, 'enqueue_style' ) );
}
}
function enqueue_style() {
wp_enqueue_style( 'goodreads-widget', plugins_url( 'goodreads/css/goodreads.css', __FILE__ ) );
wp_style_add_data( 'goodreads-widget', 'rtl', 'replace' );
}
function widget( $args, $instance ) {
/** This action is documented in modules/widgets/gravatar-profile.php */
do_action( 'jetpack_stats_extra', 'widget_view', 'goodreads' );
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '' );
if ( empty( $instance['user_id'] ) || 'invalid' === $instance['user_id'] ) {
if ( current_user_can( 'edit_theme_options' ) ) {
echo $args['before_widget'];
echo '
' . sprintf(
__( 'You need to enter your numeric user ID for the Goodreads Widget to work correctly. Full instructions.', 'jetpack' ),
esc_url( admin_url( 'widgets.php' ) ),
'https://support.wordpress.com/widgets/goodreads-widget/#goodreads-user-id'
) . '