| 1 |
<?php |
| 2 |
|
| 3 |
if(!class_exists('WP_Widget_Recent_Comments')){ |
| 4 |
require_once( ABSPATH . '/wp-includes/default-widgets.php' ); |
| 5 |
} |
| 6 |
|
| 7 |
/* |
| 8 |
* obliged to rewrite the whole functionnality to have a language dependant cache key |
| 9 |
* code base is WP 3.9.1 |
| 10 |
* |
| 11 |
* @since 1.5 |
| 12 |
*/ |
| 13 |
class PLL_Widget_Recent_Comments extends WP_Widget_Recent_Comments { |
| 14 |
|
| 15 |
/* |
| 16 |
* displays the widget |
| 17 |
* modified version of the parent function to call to use a language dependant cache key |
| 18 |
* |
| 19 |
* @since 1.5 |
| 20 |
* |
| 21 |
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. |
| 22 |
* @param array $instance The settings for the particular instance of the widget |
| 23 |
*/ |
| 24 |
function widget( $args, $instance ) { |
| 25 |
global $comments, $comment; |
| 26 |
|
| 27 |
$cache = array(); |
| 28 |
if ( ! $this->is_preview() ) { |
| 29 |
$cache = wp_cache_get('widget_recent_comments', 'widget'); |
| 30 |
} |
| 31 |
if ( ! is_array( $cache ) ) { |
| 32 |
$cache = array(); |
| 33 |
} |
| 34 |
|
| 35 |
if ( ! isset( $args['widget_id'] ) ) |
| 36 |
$args['widget_id'] = $this->id; |
| 37 |
|
| 38 |
$lang = pll_current_language(); #added |
| 39 |
if ( isset( $cache[ $args['widget_id'] ] [$lang] ) ) { #modified# |
| 40 |
echo $cache[ $args['widget_id'] ] [$lang]; #modified# |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
extract($args, EXTR_SKIP); |
| 45 |
$output = ''; |
| 46 |
|
| 47 |
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' ); |
| 48 |
|
| 49 |
/** This filter is documented in wp-includes/default-widgets.php */ |
| 50 |
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
| 51 |
$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; |
| 52 |
if ( ! $number ) |
| 53 |
$number = 5; |
| 54 |
|
| 55 |
/** |
| 56 |
* Filter the arguments for the Recent Comments widget. |
| 57 |
* |
| 58 |
* @since 3.4.0 |
| 59 |
* |
| 60 |
* @see get_comments() |
| 61 |
* |
| 62 |
* @param array $comment_args An array of arguments used to retrieve the recent comments. |
| 63 |
*/ |
| 64 |
$comments = get_comments( apply_filters( 'widget_comments_args', array( |
| 65 |
'number' => $number, |
| 66 |
'status' => 'approve', |
| 67 |
'post_status' => 'publish' |
| 68 |
) ) ); |
| 69 |
|
| 70 |
$output .= $before_widget; |
| 71 |
if ( $title ) |
| 72 |
$output .= $before_title . $title . $after_title; |
| 73 |
|
| 74 |
$output .= '<ul id="recentcomments">'; |
| 75 |
if ( $comments ) { |
| 76 |
// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) |
| 77 |
$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); |
| 78 |
_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); |
| 79 |
|
| 80 |
foreach ( (array) $comments as $comment) { |
| 81 |
$output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; |
| 82 |
} |
| 83 |
} |
| 84 |
$output .= '</ul>'; |
| 85 |
$output .= $after_widget; |
| 86 |
|
| 87 |
echo $output; |
| 88 |
|
| 89 |
if ( ! $this->is_preview() ) { |
| 90 |
$cache[ $args['widget_id'] ] [$lang] = $output; #modified# |
| 91 |
wp_cache_set( 'widget_recent_comments', $cache, 'widget' ); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
/* |
| 96 |
* backward compatibility with WP < 3.9 |
| 97 |
* |
| 98 |
* @since 1.5 |
| 99 |
* |
| 100 |
* @return bool |
| 101 |
*/ |
| 102 |
function is_preview() { |
| 103 |
return version_compare($GLOBALS['wp_version'], '3.9', '<') ? false : parent::is_preview(); |
| 104 |
} |
| 105 |
} |
| 106 |
|