Wordpress me activa bien el pluguin, el widget me sale bien y lo puedo colocar pero después no me sale nada en la web
Código PHP:
<?php
/*
Plugin Name: Simple Top Reviewers
Plugin URI:
Description: Ranquin de rewviewers de tu sitio
Version: 1.0
Author: Joan Blanch
Author URI: http://www.boombrash.com/
License: GPL2
*/
/*
/**
* Add function to widgets_init that'll load our widget.
* @since 0.1
*/
add_action( 'widgets_init', 'SimpleTopReviewersInit' );
/**
* Register our widget.
* 'SimpleTopReviewers' is the widget class used below.
*
* @since 0.1
*/
function SimpleTopReviewersInit() {
register_widget( 'SimpleTopReviewers' );
}
/**
* SimpleTopReviwers class.
* This class handles everything that needs to be handled with the widget:
* the settings, form, display, and update. Nice!
*
* @since 0.1
*/
class SimpleTopReviewers extends WP_Widget {
/**
* Widget setup.
*/
function SimpleTopReviewers() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'example', 'description' => __('Lista de usuarios Reviewers de tu sitio') );
/* Widget control settings. */
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'Simple-Top-Reviewers' );
/* Create the widget. */
$this->WP_Widget( 'Simple-Top-Reviewers', __('SimpleTopReviewers'), $widget_ops, $control_ops );
}
/**
* Cómo mostrar el widget en la pantalla.
*/
function widget( $args, $instance ) {
extract( $args );
/* Our variables from the widget settings. */
$title = apply_filters('widget_title', $instance['title'] );
$name = $instance['excludeReviewers'];
$identifier = $instance['identifier'];
$limit = $instance['limit'];
$showReviewsLabel = $instance['show_reviews_label'];
/* Before widget (defined by themes). */
echo $before_widget;
/* Display the widget title if one was input (before and after defined by themes). */
if ( $title )
echo $before_title . $title . $after_title;
/* Process variables */
if ($instance['excludeReviewers'] != ""){
$excludedReviewers = trim($instance['excludeReviewers']);
$excludedReviewers = explode(",", $excludedReviewers);
}
else{
$excludedReviewers = array('');
}
$excludedEmailQuery = '';
for ($l=0; $l<count($excludedReviewers); $l++){
$excludedEmailQuery .= " AND user_email != '".trim($excludedReviewers[$l])."' \r";
}
$excludedNameQuery = '';
for ($m=0; $m<count($excludedReviewers); $m++){
$excludedNameQuery .= " AND user_nicename != '".trim($excludedReviewers[$m])."' \r";
}
//if ($identifier == 'name'){
$groupByQuery = 'GROUP BY user_email';
//}
//else{
//$groupByQuery = 'GROUP BY post_author_email';
//}
settype($limit, 'int');
if (($limit > 0) && (is_int($limit) == true)){
$limitQuery = 'LIMIT '.$limit;
}
else{
$limitQuery = '';
}
//}
/* MySQL query */
global $wpdb;
$Reviewers = $wpdb->get_results("
SELECT count(*) as qty, key1.id, key1.user_nicename, key1.user_email, key1.display_name
FROM $wpdb->users key1
INNER JOIN $wpdb->posts key2 ON key1.id = key2.post_author
WHERE key2.post_type='reviews'
AND key2.post_status='publish'
$excludedEmailQuery
$excludedNameQuery
$groupByQuery
ORDER BY qty DESC
$limitQuery
");
/* Display list */
?>
<!-- opening ul tag to contain the list -->
<ul>
<?php
if(is_array($Reviewers)) {
//only shows "comments" if "show comments label" is set to true
if($showReviewsLabel == true){
foreach ($Reviewers as $k) {
//only puts the "s" on comments if it is grammatically appropriate
if($k->qty != 1){
echo ('<li>'.$k->display_name.': '.$k->qty.' Opiniones</li>');
}
else{
echo ('<li>'.$k->display_name.': '.$k->qty.' Opiniones</li>');
}
} //end for loop
} // end if showCommentsLabel == on
//if "show comments label" is set to false, does not show "comments"
else{
foreach ($Reviewers as $w) {
echo ('<li>'.$w->display_name.': '.$w->qty);
} //end for loop
}
} //end if is array
?>
<!-- closing ul tag to contain the list -->
</ul>
<?php
/* After widget (defined by themes). */
echo $after_widget;
}
/**
* Update the widget settings.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags for title and name to remove HTML (important for text inputs). */
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['excludeReviewers'] = strip_tags( $new_instance['excludeReviewers'] );
$instance['limit'] = strip_tags( $new_instance['limit'] );
/* No need to strip tags for these inputs */
$instance['identifier'] = $new_instance['identifier'];
$instance['show_reviews_label'] = isset($new_instance['show_reviews_label']);
return $instance;
}
/**
* Displays the widget settings controls on the widget panel.
* Make use of the get_field_id() and get_field_name() function
* when creating your form elements. This handles the confusing stuff.
*/
function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'title' => __('Top Reviewers', 'example'), 'excludeReviewers' => __('', 'example'), 'identifier' => 'email', 'limit' => 5, 'show_reviews_label' => true );
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<!-- Widget Title: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>"/>
</p>
<!-- Define Commenters Select Box -->
<p>
<label for="<?php echo $this->get_field_id( 'identifier' ); ?>"><?php _e('Define comentarios:', 'example'); ?></label>
<select id="<?php echo $this->get_field_id( 'identifier' ); ?>" name="<?php echo $this->get_field_name( 'identifier' ); ?>">
<option <?php if ( 'email' == $instance['identifier'] ) echo 'selected="selected"'; ?>>email</option>
<option <?php if ( 'name' == $instance['identifier'] ) echo 'selected="selected"'; ?>>name</option>
</select>
</p>
<!-- Your Name: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'excludeReviewers' ); ?>"><?php _e('Usuarios para Excluir: (separated by comma)', 'jim, [email protected]'); ?></label>
<input id="<?php echo $this->get_field_id( 'excludeReviewers' ); ?>" name="<?php echo $this->get_field_name( 'excludeReviewers' ); ?>" value="<?php echo $instance['excludeReviewers']; ?>"/>
</p>
<!-- Limit -->
<p>
<label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e('# Num de usuarios: (leave blank to list all)', '5'); ?></label>
<input id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" value="<?php echo $instance['limit']; ?>" style="width:2em;" />
</p>
<!-- Show "comments label" Checkbox -->
<p>
<input class="checkbox" type="checkbox" <?php checked(isset( $instance['show_reviews_label']) ? $instance['show_reviews_label'] : 0 ); ?> id="<?php echo $this->get_field_id( 'show_reviews_label' ); ?>" name="<?php echo $this->get_field_name( 'show_reviews_label' ); ?>" />
<label for="<?php echo $this->get_field_id( 'show_reviews_label' ); ?>"><?php _e('Mostrar?', 'example'); ?></label>
</p>
<?php
}
}
?>