diff --git a/wpu_comments_rating.php b/wpu_comments_rating.php index cd2df3d..24d749e 100644 --- a/wpu_comments_rating.php +++ b/wpu_comments_rating.php @@ -4,7 +4,7 @@ Plugin URI: https://github.com/WordPressUtilities/wpu_comments_rating Update URI: https://github.com/WordPressUtilities/wpu_comments_rating Description: Allow users to rate in comments. -Version: 0.1.2 +Version: 0.2.0 Author: Darklg Author URI: https://darklg.me/ Text Domain: wpu_comments_rating @@ -22,7 +22,7 @@ } class WPUCommentsRating { - private $plugin_version = '0.1.2'; + private $plugin_version = '0.2.0'; private $plugin_settings = array( 'id' => 'wpu_comments_rating', 'name' => 'WPU Comments Rating' @@ -69,6 +69,15 @@ public function __construct() { # Display rating in comments add_filter('comment_text', array($this, 'comment_text'), 10, 3); + + /* Edit rating in comment page */ + add_action('add_meta_boxes_comment', array(&$this, 'add_meta_boxes_comment')); + add_action('edit_comment', function ($comment_id) { + if (!isset($_POST['rating']) || !ctype_digit($_POST['rating']) || $_POST['rating'] < 1 || $_POST['rating'] > $this->max_rating) { + return; + } + update_comment_meta($comment_id, 'wpu_comment_rating', intval($_POST['rating'])); + }, 10, 2); } public function plugins_loaded() { @@ -271,6 +280,24 @@ public function comments_get_rating_html($note) { return $html; } + public function add_meta_boxes_comment($comment) { + add_meta_box('wpu_comment_rating', __('Rating', 'wpu_comments_rating'), array(&$this, 'wpu_comment_rating'), null, 'normal', 'high'); + } + + public function wpu_comment_rating($comment) { + $rating = get_comment_meta($comment->comment_ID, 'wpu_comment_rating', true); + echo '
'; + } + } $WPUCommentsRating = new WPUCommentsRating();