Page 1 sur 1

erreur code php dans fichier default-widget.php

Posté : 13 févr. 2010, 01:21
par laurent78
Bonsoir à tous
J'essaie de modifier mon code PHP pour mon blog afin que mes commentaires récents soient cachés pour les personnes non idendifiées sur mon site. Ne doivent être visibles que les commentaires soft pour les personnes sans login/mot de passe.
Voici mon code d'originie :
/**
 * Recent_Comments widget class
 *
 * @since 2.8.0
 */
class WP_Widget_Recent_Comments extends WP_Widget {

	function WP_Widget_Recent_Comments() {
		$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
		$this->WP_Widget('recent-comments', __('Recent Comments'), $widget_ops);
		$this->alt_option_name = 'widget_recent_comments';

		if ( is_active_widget(false, false, $this->id_base) )
			add_action( 'wp_head', array(&$this, 'recent_comments_style') );

		add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
		add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') );
	}

	function recent_comments_style() { ?>
	<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
<?php
	}

Et voici le code que je dois mettre à la place :
function wp_widget_recent_comments($args) {
global $wpdb, $comments, $comment, $current_user;
extract($args, EXTR_SKIP);
$options = get_option(’widget_recent_comments’);
$title = empty($options['title']) ? __(’Recent Comments’) : apply_filters(’widget_title’, $options['title']);
if ( !$number = (int) $options['number'] )
$number = 5;
else if ( $number < 1 )
$number = 1;
else if ( $number > 15 )
$number = 15;

if ( !$comments = wp_cache_get( ‘recent_comments’, ‘widget’ ) ) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = ‘1′ AND comment_post_ID NOT IN (SELECT post_id FROM " . $wpdb->prefix . "named_users WHERE (user_id <> " . $current_user->ID . " OR group_id NOT IN (SELECT group_id FROM " . $wpdb->prefix . "named_users_groups_relations WHERE user_id = " . $current_user->ID . "))) ORDER BY comment_date_gmt DESC LIMIT $number");
wp_cache_add( ‘recent_comments’, $comments, ‘widget’ );
}
?>

<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title; ?>
<ul id="recentcomments"><?php
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo ‘<li class="recentcomments">’ . sprintf(__(’%1$s on %2$s’), get_comment_author_link(), ‘<a href="’. get_comment_link($comment->comment_ID) . ‘">’ . get_the_title($comment->comment_post_ID) . ‘</a>’) . ‘</li>’;
endforeach; endif;?></ul>
<?php echo $after_widget; ?>
<?php
}
Je rencontre une erreur sur cette ligne :
$title = empty($options['title']) ? __(’Recent Comments’) : apply_filters(’widget_title’, $options['title']);
Merci beauoup pour votre aide, et j''espère avoir été clair et précis.

Laurent

Re: erreur code php dans fichier default-widget.php

Posté : 14 févr. 2010, 02:09
par @rthur
Bonjour,
Je rencontre une erreur sur cette ligne :
$title = empty($options['title']) ? __(’Recent Comments’) : apply_filters(’widget_title’, $options['title']);
Quelle erreur rencontres-tu?

Re: erreur code php dans fichier default-widget.php

Posté : 14 févr. 2010, 11:51
par Ryle
Tes apostrophes pour délimiter des chaines ont de drôles de têtes....

tantôt , tantot ... alors qu'elles devraient logiquement être droites : '

Re: erreur code php dans fichier default-widget.php

Posté : 14 févr. 2010, 13:45
par laurent78
Bonjour
Voici le message d'erreur que je rencontre après avoir uploadé mon fichier sur mon blog Wordpress 2.9.1 :

Parse error: syntax error, unexpected T_STRING in /homepages/14/d298932328/htdocs/wp-includes/default-widgets.php on line 607

Et dans mon fichier, la ligne 607 est :
$title = empty($options['title']) ? __(’Recent Comments’) : apply_filters(’widget_title’, $options['title']);
Merci de vos réponses et bonne journée

Laurent