function enp_popular_comments_save($btn_slug, $post_types, $args) { // all comments by btn slug (combines pages, posts, etc. anywhere the button is shown) $comment_args = array('fields' => 'ids', 'status' => 'approve', 'number' => 20); $args = array_merge($comment_args, $args); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); $popular_comments = enp_build_popular_array($btn_slug, $comments, 'comment'); update_option('enp_button_popular_' . $btn_slug . '_comments', $popular_comments); // Loop through all the passed post_types and // save all comments by post type // ex: enp_button_popular_respect_page_comments foreach ($post_types as $key => $value) { // check if the button type is active if ($value === '1' && $key !== 'comment') { // build the arguments $post_type_args = array('post_type' => $key); $post_type_args = array_merge($args, $post_type_args); // generate the query $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($post_type_args); // build the array of popular ids and counts $popular_comments = enp_build_popular_array($btn_slug, $comments, 'comment'); // save the array update_option('enp_button_popular_' . $btn_slug . '_' . $key . '_comments', $popular_comments); } } }
/** * Get a list of comments. * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function get_items($request) { $prepared_args = array('comment__in' => $request['include'], 'comment__not_in' => $request['exclude'], 'number' => $request['per_page'], 'post_id' => $request['post'] ? $request['post'] : '', 'parent' => isset($request['parent']) ? $request['parent'] : '', 'search' => $request['search'], 'offset' => $request['offset'], 'orderby' => $this->normalize_query_param($request['orderby']), 'order' => $request['order'], 'status' => 'approve', 'type' => 'comment', 'no_found_rows' => false); if (empty($request['offset'])) { $prepared_args['offset'] = $prepared_args['number'] * (absint($request['page']) - 1); } if (current_user_can('edit_posts')) { $protected_args = array('user_id' => $request['author'] ? $request['author'] : '', 'status' => $request['status'], 'type' => isset($request['type']) ? $request['type'] : '', 'author_email' => isset($request['author_email']) ? $request['author_email'] : '', 'karma' => isset($request['karma']) ? $request['karma'] : '', 'post_author' => isset($request['post_author']) ? $request['post_author'] : '', 'post_name' => isset($request['post_slug']) ? $request['post_slug'] : '', 'post_parent' => isset($request['post_parent']) ? $request['post_parent'] : '', 'post_status' => isset($request['post_status']) ? $request['post_status'] : '', 'post_type' => isset($request['post_type']) ? $request['post_type'] : ''); $prepared_args = array_merge($prepared_args, $protected_args); } /** * Filter arguments, before passing to WP_Comment_Query, when querying comments via the REST API. * * @see https://developer.wordpress.org/reference/classes/wp_comment_query/ * * @param array $prepared_args Array of arguments for WP_Comment_Query. * @param WP_REST_Request $request The current request. */ $prepared_args = apply_filters('rest_comment_query', $prepared_args, $request); $query = new WP_Comment_Query(); $query_result = $query->query($prepared_args); $comments = array(); foreach ($query_result as $comment) { $post = get_post($comment->comment_post_ID); if (!$this->check_read_post_permission($post) || !$this->check_read_permission($comment)) { continue; } $data = $this->prepare_item_for_response($comment, $request); $comments[] = $this->prepare_response_for_collection($data); } $total_comments = (int) $query->found_comments; $max_pages = (int) $query->max_num_pages; if ($total_comments < 1) { // Out-of-bounds, run the query again without LIMIT for total count unset($prepared_args['number']); unset($prepared_args['offset']); $query = new WP_Comment_Query(); $prepared_args['count'] = true; $total_comments = $query->query($prepared_args); $max_pages = ceil($total_comments / $request['per_page']); } $response = rest_ensure_response($comments); $response->header('X-WP-Total', $total_comments); $response->header('X-WP-TotalPages', $max_pages); $base = add_query_arg($request->get_query_params(), rest_url('/wp/v2/comments')); if ($request['page'] > 1) { $prev_page = $request['page'] - 1; if ($prev_page > $max_pages) { $prev_page = $max_pages; } $prev_link = add_query_arg('page', $prev_page, $base); $response->link_header('prev', $prev_link); } if ($max_pages > $request['page']) { $next_page = $request['page'] + 1; $next_link = add_query_arg('page', $next_page, $base); $response->link_header('next', $next_link); } return $response; }
function cases_display_todo_comments() { if (!is_singular('cases')) { return; } if (!shortcode_exists('cp_todo_comments')) { return; } global $post; $args = array('post_id' => $post->ID, 'meta_query' => array(array('key' => 'cp_control', 'value' => 'yes')), 'meta_key' => 'cp_control_order', 'orderby' => 'meta_value_num', 'order' => 'ASC'); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); if (empty($comments)) { return; } ?> <section id="case_todo_comments_wrapper" class="cases-box"> <header class="cases-box-header"> <h1>Комментарии на контроле</h1> <hr> </header> <article class="cases-box-content"> <?php echo do_shortcode('[cp_todo_comments]'); ?> </article> </section> <?php }
/** * Get a list of reactions. * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function get_items($request) { $prepared_args = array('post__in' => $request['post'], 'type' => 'reaction'); /** * Filter arguments, before passing to WP_Comment_Query, when querying reactions via the REST API. * * @see https://developer.wordpress.org/reference/classes/wp_comment_query/ * * @param array $prepared_args Array of arguments for WP_Comment_Query. * @param WP_REST_Request $request The current request. */ $prepared_args = apply_filters('rest_reaction_query', $prepared_args, $request); $query = new WP_Comment_Query(); $query_result = $query->query($prepared_args); $reactions_count = array(); foreach ($query_result as $reaction) { if (empty($reactions_count[$reaction->comment_content])) { $reactions_count[$reaction->comment_content] = array('count' => 0, 'post_id' => $reaction->comment_post_ID); } $reactions_count[$reaction->comment_content]++; } $reactions = array(); foreach ($reactions_count as $emoji => $data) { $reaction = array('emoji' => $emoji, 'count' => $data['count'], 'post_id' => $data['post_id']); $data = $this->prepare_item_for_response($reaction, $request); $reactions[] = $this->prepare_response_for_collection($data); } $total_reactions = (int) $query->found_comments; $reaction_groups = count($reactions); $response = rest_ensure_response($reactions); $response->header('X-WP-Total', $total_reactions); $response->header('X-WP-TotalGroups', $reaction_groups); return $response; }
/** * Get comment for all post by user * @param string $user_id [description] * @return [type] [description] */ function hackgov_get_comments($user_id = '') { if (empty($user_id)) { $user_id = get_current_user_id(); } $args = array('post_author__in' => $user_id, 'post_status' => 'publish'); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); return $comments; }
public static function getTrackingObject() { $hash = md5(network_site_url() . '-' . $_SERVER['REMOTE_ADDR']); global $blog_id, $wpdb; $pts = array(); foreach (get_post_types(array('public' => true)) as $pt) { $count = wp_count_posts($pt); $pts[$pt] = $count->publish; } $comments_count = wp_count_comments(); $theme_data = wp_get_theme(); $theme = array('version' => $theme_data->Version, 'name' => $theme_data->Name, 'author' => $theme_data->Author, 'template' => $theme_data->Template); if (!function_exists('get_plugin_data')) { require_once ABSPATH . 'wp-admin/includes/admin.php'; } $plugins = array(); foreach (get_option('active_plugins', array()) as $plugin_path) { $plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path); $slug = str_replace('/' . basename($plugin_path), '', $plugin_path); $plugins[$slug] = array('version' => $plugin_info['Version'], 'name' => $plugin_info['Name'], 'plugin_uri' => $plugin_info['PluginURI'], 'author' => $plugin_info['AuthorName'], 'author_uri' => $plugin_info['AuthorURI']); } if (is_multisite()) { foreach (get_option('active_sitewide_plugins', array()) as $plugin_path) { $plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path); $slug = str_replace('/' . basename($plugin_path), '', $plugin_path); $plugins[$slug] = array('version' => $plugin_info['Version'], 'name' => $plugin_info['Name'], 'plugin_uri' => $plugin_info['PluginURI'], 'author' => $plugin_info['AuthorName'], 'author_uri' => $plugin_info['AuthorURI']); } } $version = explode('.', PHP_VERSION); $version = array('major' => $version[0], 'minor' => $version[0] . '.' . $version[1], 'release' => PHP_VERSION); $user_query = new WP_User_Query(array('blog_id' => $blog_id, 'count_total' => true)); $comments_query = new WP_Comment_Query(); $data = array('_id' => $hash, 'localhost' => $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ? 1 : 0, 'php' => $version, 'site' => array('hash' => $hash, 'version' => get_bloginfo('version'), 'multisite' => is_multisite(), 'users' => $user_query->get_total(), 'lang' => get_locale(), 'wp_debug' => defined('WP_DEBUG') ? WP_DEBUG ? true : false : false, 'memory' => WP_MEMORY_LIMIT), 'pts' => $pts, 'comments' => array('total' => $comments_count->total_comments, 'approved' => $comments_count->approved, 'spam' => $comments_count->spam, 'pings' => $comments_query->query(array('count' => true, 'type' => 'pingback'))), 'options' => apply_filters('redux/tracking/options', array()), 'theme' => $theme, 'redux' => array('mode' => ReduxFramework::$_is_plugin ? 'plugin' : 'theme', 'version' => ReduxFramework::$_version, 'demo_mode' => get_option('ReduxFrameworkPlugin')), 'developer' => apply_filters('redux/tracking/developer', array()), 'plugins' => $plugins); $parts = explode(' ', $_SERVER['SERVER_SOFTWARE']); $software = array(); foreach ($parts as $part) { if ($part[0] == "(") { continue; } if (strpos($part, '/') !== false) { $chunk = explode("/", $part); $software[strtolower($chunk[0])] = $chunk[1]; } } $software['full'] = $_SERVER['SERVER_SOFTWARE']; $data['environment'] = $software; if (function_exists('mysql_get_server_info')) { $data['environment']['mysql'] = mysql_get_server_info(); } if (empty($data['developer'])) { unset($data['developer']); } return $data; }
/** @see WP_Widget::widget -- do not rename this */ function widget($args, $instance) { extract($args); //Our variables from the widget settings. $title = apply_filters('widget_title', $instance['title']); $width = $instance['width']; $number = $instance['number']; echo '<div class="' . $width . '"> <div class="dash-widget">' . $before_widget; // Display the widget title if ($title) { echo $before_title . $title . $after_title; } $unit_comments = vibe_get_option('unit_comments'); if (isset($unit_comments) && is_numeric($unit_comments)) { $link = get_permalink($unit_comments); } else { $link = '#'; } echo '<div id="vibe-tabs-notes_discussion" class="tabs tabbable"> <a href="' . $link . '" class="view_all_notes">' . __('SEE ALL', 'wplms-dashboard') . '</a> <ul class="nav nav-tabs clearfix"> <li><a href="#tab-notes" data-toggle="tab">' . __('My Notes', 'wplms-dashboard') . '</a></li> <li><a href="#tab-discussion" data-toggle="tab">' . __('My Discussions', 'wplms-dashboard') . '</a></li> </ul><div class="tab-content">'; echo '<div id="tab-notes" class="tab-pane">'; $user_id = get_current_user_id(); $args = apply_filters('wplms_notes_dicussion_dashboard_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'type' => 'note', 'user_id' => $user_id)); echo '<div id="notes_query">' . json_encode($args) . '</div> <div id="notes_discussions">'; $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); // Comment Loop $vibe_notes_discussions = new vibe_notes_discussions(); $vibe_notes_discussions->comments_loop($comments); echo '</div></div>'; echo '<div id="tab-discussion" class="tab-pane">'; $args = apply_filters('wplms_notes_dicussion_dashboard_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'type' => 'public', 'user_id' => $user_id)); echo '<div id="notes_query">' . json_encode($args) . '</div> <div id="notes_discussions">'; $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); // Comment Loop $vibe_notes_discussions = new vibe_notes_discussions(); $vibe_notes_discussions->comments_loop($comments); echo '</div></div>'; echo '</div></div>'; echo $after_widget . ' </div> </div>'; }
function custom_recent_comments($amount = 5, $avatar_size = 35) { $comments_query = new WP_Comment_Query(); $comments = $comments_query->query(array('number' => $amount)); $comm = ''; if ($comments) { foreach ($comments as $comment) { $comm .= '<li><div class="recent-avatar">' . get_avatar($comment->comment_author_email, $avatar_size); $comm .= '</div><div class="recent-text"><p><a class="recent-author" href="' . get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">'; $comm .= get_comment_author($comment->comment_ID) . '</a> la:<br /> '; $comm .= '<a href="' . get_permalink($comment->comment_post_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a></p></div></li>'; } } else { $comm .= 'No comments.'; } echo $comm; }
public function find($args = array(), &$found = null) { //add filter for before/after handling, hopefully more complex date querying //will exist by wp3.7 if (isset($args['before']) || isset($args['after'])) { add_filter('comments_clauses', array(__CLASS__, '_filter_comments_clauses_handleDateRange'), 10, 2); } //setup paging if (empty($args['per_page'])) { $number = get_option('comments_per_page'); if ($number < 1) { $number = \Voce\Thermal\v1\MAX_COMMENTS_PER_PAGE; } } if (isset($args['offset'])) { $offset = $args['offset']; } elseif (isset($args['paged'])) { $offset = (absint($args['paged']) - 1) * $number; } else { $offset = 0; } //normalize search arg if (isset($args['s'])) { $args['search'] = $args['s']; unset($args['s']); } //allow 'in' arg if (!empty($args['in'])) { add_filter('comments_clauses', array(__CLASS__, '_filter_comments_clauses_handleInArg'), 10, 2); } //status handling if (empty($args['status'])) { $args['status'] = 'approve'; } //make sure count isn't set to true $args['count'] = false; $wp_comments = new \WP_Comment_Query(); $comments = $wp_comments->query($args); if (!empty($args['include_found'])) { $args['count'] = true; //@todo - counts don't cache in core $found = $wp_comments->query($args); } return $comments; }
public function init(&$existing_meta_keys = array()) { if (!self::$is_active) { return; } global $wp_version; if (version_compare($wp_version, '4.2.0', '>=')) { $commentsQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true)); $comments = $commentsQuery->get_comments(); } else { $comments = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true)); } if (!empty($comments)) { foreach ($comments as $comment) { $comment_meta = get_comment_meta($comment->comment_ID, ''); if (!empty($comment_meta)) { foreach ($comment_meta as $record_meta_key => $record_meta_value) { if (!in_array($record_meta_key, $existing_meta_keys)) { $to_add = true; foreach ($this->default_fields as $default_value) { if ($record_meta_key == $default_value['name'] || $record_meta_key == $default_value['type']) { $to_add = false; break; } } if ($to_add) { foreach ($this->advanced_fields as $advanced_value) { if ($record_meta_key == $advanced_value['name'] || $record_meta_key == $advanced_value['type']) { $to_add = false; break; } } } if ($to_add) { $existing_meta_keys[] = $record_meta_key; } } } } } } }
/** * Outputs the content of the widget. * * @param array args The array of form elements * @param array instance The current instance of the widget */ public function widget($args, $instance) { $cache = wp_cache_get('featured_comments_widget', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } $title = apply_filters('widget_title', $instance['title']); $output = ''; if (empty($instance['number']) || $instance['number'] < 1) { $intance['number'] = 5; } $query_args = apply_filters('featured_comments_query', array('number' => $instance['number'], 'status' => 'approve', 'post_status' => 'publish', 'meta_query' => array(array('key' => 'featured', 'value' => '1')))); $query = new WP_Comment_Query(); $comments = $query->query($query_args); if ($comments) { $output = $args['before_widget']; if ($title) { $output .= $args['before_title'] . $title . $args['after_title']; } $output .= '<ul id="featured-comments">'; if ($comments) { foreach ((array) $comments as $comment) { $output .= '<li class="featured-comments">'; $output .= sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link($comment->comment_ID), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>'); $output .= '</li>'; } } $output .= '</ul>'; } $output .= $args['after_widget']; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('featured_comments_widget', $cache, 'widget'); }
/** * Get a list of comments. * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function get_items($request) { $prepared_args = $this->prepare_items_query($request); $query = new WP_Comment_Query(); $query_result = $query->query($prepared_args); $comments = array(); foreach ($query_result as $comment) { $post = get_post($comment->comment_post_ID); if (!$this->check_read_post_permission($post) || !$this->check_read_permission($comment)) { continue; } $data = $this->prepare_item_for_response($comment, $request); $comments[] = $this->prepare_response_for_collection($data); } $response = rest_ensure_response($comments); unset($prepared_args['number']); unset($prepared_args['offset']); $query = new WP_Comment_Query(); $prepared_args['count'] = true; $total_comments = $query->query($prepared_args); $response->header('X-WP-Total', (int) $total_comments); $max_pages = ceil($total_comments / $request['per_page']); $response->header('X-WP-TotalPages', (int) $max_pages); $base = add_query_arg($request->get_query_params(), rest_url('/wp/v2/comments')); if ($request['page'] > 1) { $prev_page = $request['page'] - 1; if ($prev_page > $max_pages) { $prev_page = $max_pages; } $prev_link = add_query_arg('page', $prev_page, $base); $response->link_header('prev', $prev_link); } if ($max_pages > $request['page']) { $next_page = $request['page'] + 1; $next_link = add_query_arg('page', $next_page, $base); $response->link_header('next', $next_link); } return $response; }
/** * Load the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment template from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * Will not try to get the comments if the post has none. * * @since 1.5.0 * * @global WP_Query $wp_query * @global WP_Post $post * @global wpdb $wpdb * @global int $id * @global WP_Comment $comment * @global string $user_login * @global int $user_ID * @global string $user_identity * @global bool $overridden_cpage * @global bool $withcomments * * @param string $file Optional. The file to load. Default '/comments.php'. * @param bool $separate_comments Optional. Whether to separate the comments by comment type. * Default false. */ function comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments) || empty($post)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /* * Comment author information fetched from the comment cookies. */ $commenter = wp_get_current_commenter(); /* * The name of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */ $comment_author = $commenter['comment_author']; /* * The email address of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */ $comment_author_email = $commenter['comment_author_email']; /* * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); $comment_args = array('orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve', 'post_id' => $post->ID, 'no_found_rows' => false, 'update_comment_meta_cache' => false); if (get_option('thread_comments')) { $comment_args['hierarchical'] = 'threaded'; } else { $comment_args['hierarchical'] = false; } if ($user_ID) { $comment_args['include_unapproved'] = array($user_ID); } elseif (!empty($comment_author_email)) { $comment_args['include_unapproved'] = array($comment_author_email); } $per_page = 0; if (get_option('page_comments')) { $per_page = (int) get_query_var('comments_per_page'); if (0 === $per_page) { $per_page = (int) get_option('comments_per_page'); } $comment_args['number'] = $per_page; $page = (int) get_query_var('cpage'); if ($page) { $comment_args['offset'] = ($page - 1) * $per_page; } elseif ('oldest' === get_option('default_comments_page')) { $comment_args['offset'] = 0; } else { // If fetching the first page of 'newest', we need a top-level comment count. $top_level_query = new WP_Comment_Query(); $top_level_args = array('count' => true, 'orderby' => false, 'post_id' => $post->ID, 'status' => 'approve'); if ($comment_args['hierarchical']) { $top_level_args['parent'] = 0; } if (isset($comment_args['include_unapproved'])) { $top_level_args['include_unapproved'] = $comment_args['include_unapproved']; } $top_level_count = $top_level_query->query($top_level_args); $comment_args['offset'] = (ceil($top_level_count / $per_page) - 1) * $per_page; } } /** * Filters the arguments used to query comments in comments_template(). * * @since 4.5.0 * * @see WP_Comment_Query::__construct() * * @param array $comment_args { * Array of WP_Comment_Query arguments. * * @type string|array $orderby Field(s) to order by. * @type string $order Order of results. Accepts 'ASC' or 'DESC'. * @type string $status Comment status. * @type array $include_unapproved Array of IDs or email addresses whose unapproved comments * will be included in results. * @type int $post_id ID of the post. * @type bool $no_found_rows Whether to refrain from querying for found rows. * @type bool $update_comment_meta_cache Whether to prime cache for comment meta. * @type bool|string $hierarchical Whether to query for comments hierarchically. * @type int $offset Comment offset. * @type int $number Number of comments to fetch. * } */ $comment_args = apply_filters('comments_template_query_args', $comment_args); $comment_query = new WP_Comment_Query($comment_args); $_comments = $comment_query->comments; // Trees must be flattened before they're passed to the walker. if ($comment_args['hierarchical']) { $comments_flat = array(); foreach ($_comments as $_comment) { $comments_flat[] = $_comment; $comment_children = $_comment->get_children(array('format' => 'flat', 'status' => $comment_args['status'], 'orderby' => $comment_args['orderby'])); foreach ($comment_children as $comment_child) { $comments_flat[] = $comment_child; } } } else { $comments_flat = $_comments; } /** * Filter the comments array. * * @since 2.1.0 * * @param array $comments Array of comments supplied to the comments template. * @param int $post_ID Post ID. */ $wp_query->comments = apply_filters('comments_array', $comments_flat, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); $wp_query->max_num_comment_pages = $comment_query->max_num_pages; if ($separate_comments) { $wp_query->comments_by_type = separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } else { $wp_query->comments_by_type = array(); } $overridden_cpage = false; if ('' == get_query_var('cpage') && $wp_query->max_num_comment_pages > 1) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = true; } if (!defined('COMMENTS_TEMPLATE')) { define('COMMENTS_TEMPLATE', true); } $theme_template = STYLESHEETPATH . $file; /** * Filter the path to the theme template file used for the comments template. * * @since 1.5.1 * * @param string $theme_template The path to the theme template file. */ $include = apply_filters('comments_template', $theme_template); if (file_exists($include)) { require $include; } elseif (file_exists(TEMPLATEPATH . $file)) { require TEMPLATEPATH . $file; } else { // Backward compat code will be removed in a future release require ABSPATH . WPINC . '/theme-compat/comments.php'; } }
function ajax_wpt_widget_content() { $tab = $_POST['tab']; $args = $_POST['args']; $page = intval($_POST['page']); if ($page < 1) { $page = 1; } if (!is_array($args)) { return ''; } // sanitize args $post_num = empty($args['post_num']) ? 5 : intval($args['post_num']); if ($post_num > 20 || $post_num < 1) { // max 20 posts $post_num = 5; } $comment_num = empty($args['comment_num']) ? 5 : intval($args['comment_num']); if ($comment_num > 20 || $comment_num < 1) { $comment_num = 5; } $show_thumb = !empty($args['show_thumb']); $thumb_size = $args['thumb_size']; if ($thumb_size != 'small' && $thumb_size != 'large') { $thumb_size = 'small'; // default } $show_date = !empty($args['show_date']); $show_excerpt = !empty($args['show_excerpt']); $excerpt_length = intval($args['excerpt_length']); if ($excerpt_length > 50 || $excerpt_length < 1) { $excerpt_length = 10; } $show_comment_num = !empty($args['show_comment_num']); $show_avatar = !empty($args['show_avatar']); $allow_pagination = !empty($args['allow_pagination']); $title_length = !empty($args['title_length']) ? $args['title_length'] : apply_filters('wpt_title_length_default', '15'); /* ---------- Tab Contents ---------- */ switch ($tab) { /* ---------- Popular Posts ---------- */ case "popular": ?> <ul> <?php $popular = new WP_Query(array('ignore_sticky_posts' => 1, 'posts_per_page' => $post_num, 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => '_wpt_view_count', 'order' => 'desc', 'paged' => $page)); $last_page = $popular->max_num_pages; while ($popular->have_posts()) { $popular->the_post(); ?> <li> <?php if ($show_thumb == 1) { ?> <?php if (has_post_thumbnail()) { ?> <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?> "> <a title="<?php the_title(); ?> " href="<?php the_permalink(); ?> "> <?php the_post_thumbnail('wp_review_' . $thumb_size, array('title' => '')); ?> </a> </div> <?php } ?> <?php } ?> <div class="entry-title"><a title="<?php the_title(); ?> " href="<?php the_permalink(); ?> "><?php echo $this->post_title($title_length); ?> </a></div> <?php if ($show_date == 1 || $show_comment_num == 1) { ?> <div class="wpt-postmeta"> <?php if ($show_date == 1) { ?> <?php the_time('F j, Y'); ?> <?php } ?> <?php if ($show_date == 1 && $show_comment_num == 1) { ?> • <?php } ?> <?php if ($show_comment_num == 1) { ?> <?php echo comments_number(__('No Comment', 'wp-tab-widget'), __('One Comment', 'wp-tab-widget'), '<span class="comments-number">%</span> ' . __('Comments', 'wp-tab-widget')); ?> <?php } ?> </div> <!--end .entry-meta--> <?php } ?> <?php if ($show_excerpt == 1) { ?> <div class="wpt_excerpt"> <p><?php echo $this->excerpt($excerpt_length); ?> </p> </div> <?php } ?> <div class="clear"></div> </li> <?php $post_num++; } wp_reset_query(); ?> </ul> <div class="clear"></div> <?php if ($allow_pagination) { ?> <?php $this->tab_pagination($page, $last_page); ?> <?php } ?> <?php break; /* ---------- Recent Posts ---------- */ /* ---------- Recent Posts ---------- */ case "recent": ?> <ul> <?php $recent = new WP_Query('posts_per_page=' . $post_num . '&orderby=post_date&order=desc&post_status=publish&paged=' . $page); $last_page = $recent->max_num_pages; while ($recent->have_posts()) { $recent->the_post(); ?> <li> <?php if ($show_thumb == 1) { ?> <?php if (has_post_thumbnail()) { ?> <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?> "> <a title="<?php the_title(); ?> " href="<?php the_permalink(); ?> "> <?php the_post_thumbnail('wp_review_' . $thumb_size, array('title' => '')); ?> </a> </div> <?php } ?> <?php } ?> <div class="entry-title"><a title="<?php the_title(); ?> " href="<?php the_permalink(); ?> "><?php echo $this->post_title($title_length); ?> </a></div> <?php if ($show_date == 1 || $show_comment_num == 1) { ?> <div class="wpt-postmeta"> <?php if ($show_date == 1) { ?> <?php the_time('F j, Y'); ?> <?php } ?> <?php if ($show_date == 1 && $show_comment_num == 1) { ?> • <?php } ?> <?php if ($show_comment_num == 1) { ?> <?php echo comments_number(__('No Comment', 'wp-tab-widget'), __('One Comment', 'wp-tab-widget'), '<span class="comm">%</span> ' . __('Comments', 'wp-tab-widget')); ?> <?php } ?> </div> <!--end .entry-meta--> <?php } ?> <?php if ($show_excerpt == 1) { ?> <div class="wpt_excerpt"> <p><?php echo $this->excerpt($excerpt_length); ?> </p> </div> <?php } ?> <div class="clear"></div> </li> <?php } wp_reset_query(); ?> </ul> <div class="clear"></div> <?php if ($allow_pagination) { ?> <?php $this->tab_pagination($page, $last_page); ?> <?php } ?> <?php break; /* ---------- Latest Comments ---------- */ /* ---------- Latest Comments ---------- */ case "comments": ?> <ul> <?php $no_comments = false; $avatar_size = 65; $comment_length = 90; // max length for comments $comments_total = new WP_Comment_Query(); $comments_total_number = $comments_total->query(array('count' => 1)); $last_page = ceil($comments_total_number / $comment_num); $comments_query = new WP_Comment_Query(); $offset = ($page - 1) * $comment_num; $comments = $comments_query->query(array('number' => $comment_num, 'offset' => $offset, 'status' => 'approve')); if ($comments) { foreach ($comments as $comment) { ?> <li> <?php if ($show_avatar) { ?> <div class="wpt_avatar"> <a href="<?php echo get_comment_link($comment->comment_ID); ?> "> <?php echo get_avatar($comment->comment_author_email, $avatar_size); ?> </a> </div> <?php } ?> <div class="wpt_comment_meta"> <a href="<?php echo get_comment_link($comment->comment_ID); ?> "> <span class="wpt_comment_author"><?php echo get_comment_author($comment->comment_ID); ?> </span> - <span class="wpt_comment_post"><?php echo get_the_title($comment->comment_post_ID); ?> </span> </a> </div> <div class="wpt_comment_content"> <p><?php echo $this->truncate(strip_tags(apply_filters('get_comment_text', $comment->comment_content)), $comment_length); ?> </p> </div> <div class="clear"></div> </li> <?php } } else { ?> <li> <div class="no-comments"><?php _e('No comments yet.', 'wp-tab-widget'); ?> </div> </li> <?php $no_comments = true; } ?> </ul> <?php if ($allow_pagination && !$no_comments) { ?> <?php $this->tab_pagination($page, $last_page); ?> <?php } ?> <?php break; /* ---------- Tags ---------- */ /* ---------- Tags ---------- */ case "tags": ?> <ul> <?php $tags = get_tags(array('get' => 'all')); if ($tags) { foreach ($tags as $tag) { ?> <li><a href="<?php echo get_term_link($tag); ?> "><?php echo $tag->name; ?> </a></li> <?php } } else { _e('No tags created.', 'wp-tab-widget'); } ?> </ul> <?php break; } die; // required to return a proper result }
/** * Creates a custom query for pingbacks/trackbacks (i.e., 'pings') * and displays them. Using this custom query instead of * wp_list_comments() allows us to always show all pings, * even when we're showing paginated comments. * * @since Independent Publisher 1.0 */ function independent_publisher_pings() { $args = array('post_id' => get_the_ID(), 'type' => 'pings'); $pings_query = new WP_Comment_Query(); $pings = $pings_query->query($args); if ($pings) { foreach ($pings as $ping) { ?> <li <?php comment_class('', $ping->comment_ID); ?> id="li-comment-<?php echo $ping->comment_ID; ?> "> <?php printf('<cite class="fn">%s</cite>', get_comment_author_link($ping->comment_ID)); ?> <span> <?php edit_comment_link(__('(Edit)', 'independent-publisher'), ' ', ''); ?> </span> </li> <?php } } }
/** * Retrieve a list of comments. * * The comment list can be for the blog as a whole or for an individual post. * * @since 2.7.0 * * @param string|array $args Optional. Array or string of arguments. See {@see WP_Comment_Query::parse_query()} * for information on accepted arguments. Default empty. * @return int|array List of comments or number of found comments if `$count` argument is true. */ function get_comments($args = '') { $query = new WP_Comment_Query(); return $query->query($args); }
/** * Get a list of comments. * * ## OPTIONS * * [--<field>=<value>] * : One or more args to pass to WP_Comment_Query. * * [--field=<field>] * : Prints the value of a single field for each comment. * * [--fields=<fields>] * : Limit the output to specific object fields. * * [--format=<format>] * : Render output in a particular format. * --- * default: table * options: * - table * - ids * - csv * - json * - count * - yaml * --- * * ## AVAILABLE FIELDS * * These fields will be displayed by default for each comment: * * * comment_ID * * comment_post_ID * * comment_date * * comment_approved * * comment_author * * comment_author_email * * These fields are optionally available: * * * comment_author_url * * comment_author_IP * * comment_date_gmt * * comment_content * * comment_karma * * comment_agent * * comment_type * * comment_parent * * user_id * * ## EXAMPLES * * # List comment IDs * $ wp comment list --field=ID * 22 * 23 * 24 * * # List comments of a post * $ wp comment list --post_id=1 --fields=ID,comment_date,comment_author * +------------+---------------------+----------------+ * | comment_ID | comment_date | comment_author | * +------------+---------------------+----------------+ * | 1 | 2015-06-20 09:00:10 | Mr WordPress | * +------------+---------------------+----------------+ * * # List approved comments * $ wp comment list --number=3 --status=approve --fields=ID,comment_date,comment_author * +------------+---------------------+----------------+ * | comment_ID | comment_date | comment_author | * +------------+---------------------+----------------+ * | 1 | 2015-06-20 09:00:10 | Mr WordPress | * | 30 | 2013-03-14 12:35:07 | John Doe | * | 29 | 2013-03-14 11:56:08 | Jane Doe | * +------------+---------------------+----------------+ * * @subcommand list */ public function list_($_, $assoc_args) { $formatter = $this->get_formatter($assoc_args); if ('ids' == $formatter->format) { $assoc_args['fields'] = 'comment_ID'; } $query = new WP_Comment_Query(); $comments = $query->query($assoc_args); if ('ids' == $formatter->format) { $comments = wp_list_pluck($comments, 'comment_ID'); } $formatter->display_items($comments); }
/** * Calculate what page number a comment will appear on for comment paging. * * @since 2.7.0 * * @global wpdb $wpdb * @param int $comment_ID Comment ID. * @param array $args { * Array of optional arguments. * @type string $type Limit paginated comments to those matching a given type. Accepts 'comment', * 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'. * Default is 'all'. * @type int $per_page Per-page count to use when calculating pagination. Defaults to the value of the * 'comments_per_page' option. * @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of * `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option. * } * * @return int|null Comment page number or null on error. */ function get_page_of_comment($comment_ID, $args = array()) { global $wpdb; if (!($comment = get_comment($comment_ID))) { return; } $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => ''); $args = wp_parse_args($args, $defaults); if ('' === $args['per_page']) { $args['per_page'] = get_query_var('comments_per_page'); } if (empty($args['per_page'])) { $args['per_page'] = 0; $args['page'] = 0; } if ($args['per_page'] < 1) { return 1; } if ('' === $args['max_depth']) { if (get_option('thread_comments')) { $args['max_depth'] = get_option('thread_comments_depth'); } else { $args['max_depth'] = -1; } } // Find this comment's top level parent if threading is enabled if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) { return get_page_of_comment($comment->comment_parent, $args); } $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt))); $comment_query = new WP_Comment_Query(); $older_comment_count = $comment_query->query($comment_args); // No older comments? Then it's page #1. if (0 == $older_comment_count) { return 1; } // Divide comments older than this one by comments per page to get this comment's page number return ceil(($older_comment_count + 1) / $args['per_page']); }
function widget($args, $instance) { // Outputs the content of the widget extract($args); // Make before_widget, etc available. $widget_title = null; $number_of_comments = null; $widget_title = esc_attr(apply_filters('widget_title', $instance['widget_title'])); $number_of_comments = esc_attr($instance['number_of_comments']); echo $before_widget; if (!empty($widget_title)) { echo $before_title . $widget_title . $after_title; } else { echo $before_title . esc_html('Recent Comments', 'popper') . $after_title; } ?> <ul class="popper-widget-list"> <?php if ($number_of_comments == 0) { $number_of_comments = 5; } $args = array('orderby' => 'date', 'number' => $number_of_comments, 'status' => 'approve'); global $comment; // The Query $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); // Comment Loop if ($comments) { foreach ($comments as $comment) { ?> <li> <a href="<?php echo get_permalink($comment->comment_post_ID); ?> #comment-<?php echo $comment->comment_ID; ?> "> <div class="post-icon"> <?php echo get_avatar(get_comment_author_email($comment->comment_ID), $size = '96'); ?> </div> <p class="title"><span><?php comment_author(); ?> </span></p> <p class="excerpt"><?php echo esc_attr(comment_excerpt($comment->comment_ID)); ?> </p> <p class="original-title"><span><?php _e('on', 'popper'); ?> </span> <?php the_title_attribute(array('post' => $comment->comment_post_ID)); ?> </p> </a> </li> <?php } } ?> </ul> <?php echo $after_widget; }
/** * Get a list of comments. * * ## OPTIONS * * [--<field>=<value>] * : One or more args to pass to WP_Comment_Query. * * [--field=<field>] * : Prints the value of a single field for each comment. * * [--fields=<fields>] * : Limit the output to specific object fields. * * [--format=<format>] * : Render output in a particular format. * --- * default: table * options: * - table * - ids * - csv * - json * - count * - yaml * --- * * ## AVAILABLE FIELDS * * These fields will be displayed by default for each comment: * * * comment_ID * * comment_post_ID * * comment_date * * comment_approved * * comment_author * * comment_author_email * * These fields are optionally available: * * * comment_author_url * * comment_author_IP * * comment_date_gmt * * comment_content * * comment_karma * * comment_agent * * comment_type * * comment_parent * * user_id * * url * * ## EXAMPLES * * # List comment IDs. * $ wp comment list --field=ID * 22 * 23 * 24 * * # List comments of a post. * $ wp comment list --post_id=1 --fields=ID,comment_date,comment_author * +------------+---------------------+----------------+ * | comment_ID | comment_date | comment_author | * +------------+---------------------+----------------+ * | 1 | 2015-06-20 09:00:10 | Mr WordPress | * +------------+---------------------+----------------+ * * # List approved comments. * $ wp comment list --number=3 --status=approve --fields=ID,comment_date,comment_author * +------------+---------------------+----------------+ * | comment_ID | comment_date | comment_author | * +------------+---------------------+----------------+ * | 1 | 2015-06-20 09:00:10 | Mr WordPress | * | 30 | 2013-03-14 12:35:07 | John Doe | * | 29 | 2013-03-14 11:56:08 | Jane Doe | * +------------+---------------------+----------------+ * * @subcommand list */ public function list_($_, $assoc_args) { $formatter = $this->get_formatter($assoc_args); if ('ids' == $formatter->format) { $assoc_args['fields'] = 'comment_ID'; } if (!empty($assoc_args['comment__in'])) { $assoc_args['comment__in'] = explode(',', $assoc_args['comment__in']); } if (!empty($assoc_args['comment__in']) && !empty($assoc_args['orderby']) && 'comment__in' === $assoc_args['orderby'] && Utils\wp_version_compare('4.4', '<')) { $comments = array(); foreach ($assoc_args['comment__in'] as $comment_id) { $comment = get_comment($comment_id); if ($comment) { $comments[] = $comment; } else { WP_CLI::warning(sprintf("Invalid comment %s.", $comment_id)); } } } else { $query = new WP_Comment_Query(); $comments = $query->query($assoc_args); } if ('ids' == $formatter->format) { $comments = wp_list_pluck($comments, 'comment_ID'); } else { $comments = array_map(function ($comment) { $comment->url = get_comment_link($comment->comment_ID); return $comment; }, $comments); } $formatter->display_items($comments); }
/** * Load the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment template from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @uses $withcomments Will not try to get the comments if the post has none. * * @since 1.5.0 * * @global WP_Query $wp_query * @global WP_Post $post * @global wpdb $wpdb * @global int $id * @global WP_Comment $comment * @global string $user_login * @global int $user_ID * @global string $user_identity * @global bool $overridden_cpage * * @param string $file Optional. The file to load. Default '/comments.php'. * @param bool $separate_comments Optional. Whether to separate the comments by comment type. * Default false. */ function comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments) || empty($post)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /* * Comment author information fetched from the comment cookies. */ $commenter = wp_get_current_commenter(); /* * The name of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */ $comment_author = $commenter['comment_author']; /* * The email address of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */ $comment_author_email = $commenter['comment_author_email']; /* * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); $comment_args = array('orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve', 'post_id' => $post->ID, 'hierarchical' => 'threaded', 'no_found_rows' => false, 'update_comment_meta_cache' => false); if ($user_ID) { $comment_args['include_unapproved'] = array($user_ID); } elseif (!empty($comment_author_email)) { $comment_args['include_unapproved'] = array($comment_author_email); } $per_page = 0; if (get_option('page_comments')) { $per_page = (int) get_query_var('comments_per_page'); if (0 === $per_page) { $per_page = (int) get_option('comments_per_page'); } $comment_args['number'] = $per_page; $page = (int) get_query_var('cpage'); if ($page) { $comment_args['offset'] = ($page - 1) * $per_page; } elseif ('oldest' === get_option('default_comments_page')) { $comment_args['offset'] = 0; } else { // If fetching the first page of 'newest', we need a top-level comment count. $top_level_query = new WP_Comment_Query(); $top_level_count = $top_level_query->query(array('count' => true, 'orderby' => false, 'post_id' => $post->ID, 'parent' => 0)); $comment_args['offset'] = (ceil($top_level_count / $per_page) - 1) * $per_page; } } $comment_query = new WP_Comment_Query($comment_args); $_comments = $comment_query->comments; // Trees must be flattened before they're passed to the walker. $comments_flat = array(); foreach ($_comments as $_comment) { $comments_flat = array_merge($comments_flat, array($_comment), $_comment->get_children(array('format' => 'flat', 'status' => $comment_args['status'], 'orderby' => $comment_args['orderby']))); } /** * Filter the comments array. * * @since 2.1.0 * * @param array $comments Array of comments supplied to the comments template. * @param int $post_ID Post ID. */ $wp_query->comments = apply_filters('comments_array', $comments_flat, $post->ID); // Set up lazy-loading for comment metadata. add_action('get_comment_metadata', array($wp_query, 'lazyload_comment_meta'), 10, 2); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); $wp_query->max_num_comment_pages = $comment_query->max_num_pages; if ($separate_comments) { $wp_query->comments_by_type = separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } else { $wp_query->comments_by_type = array(); } $overridden_cpage = false; if ('' == get_query_var('cpage') && $wp_query->max_num_comment_pages > 1) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = true; } if (!defined('COMMENTS_TEMPLATE')) { define('COMMENTS_TEMPLATE', true); } $theme_template = STYLESHEETPATH . $file; /** * Filter the path to the theme template file used for the comments template. * * @since 1.5.1 * * @param string $theme_template The path to the theme template file. */ $include = apply_filters('comments_template', $theme_template); if (file_exists($include)) { require $include; } elseif (file_exists(TEMPLATEPATH . $file)) { require TEMPLATEPATH . $file; } else { // Backward compat code will be removed in a future release require ABSPATH . WPINC . '/theme-compat/comments.php'; } }
function bp_course_get_course_reviews($args = NULL) { $defaults = array('id' => get_the_ID()); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $args = array('status' => 'approve', 'post_id' => $id); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); // Comment Loop if ($comments) { $ratings = 0; $count = 0; $rating = array(); foreach ($comments as $comment) { $rate = get_comment_meta($comment->comment_ID, 'review_rating', true); if (isset($rate) && $rate != '') { $rating[] = $rate; } } $count = count($rating); if (!$count) { $count = 1; } $ratings = round(array_sum($rating) / $count, 1); update_post_meta(get_the_ID(), 'average_rating', $ratings); update_post_meta(get_the_ID(), 'rating_count', $count); $reviews = array('rating' => $rating, 'count' => $count); return $reviews; } else { return 0; } }
function bp_course_quiz_auto_submit($quiz_id, $user_id) { $quiz_auto_evaluate = get_post_meta($quiz_id, 'vibe_quiz_auto_evaluate', true); if (vibe_validate($quiz_auto_evaluate)) { // Auto Evaluate for Quiz Enabled, Quiz auto evaluate, autoevaluate $total_marks = 0; $questions = vibe_sanitize(get_post_meta($quiz_id, 'quiz_questions' . $user_id, false)); if (!isset($questions) || !is_array($questions)) { // Fallback for Older versions $questions = vibe_sanitize(get_post_meta($quiz_id, 'vibe_quiz_questions', false)); } if (count($questions)) { $sum = $max_sum = 0; foreach ($questions['ques'] as $key => $question) { // Grab all the Questions $marks = 0; if (isset($question) && $question) { $type = get_post_meta($question, 'vibe_question_type', true); $auto_evaluate_question_types = vibe_get_option('auto_eval_question_type'); if (isset($auto_evaluate_question_types) && is_Array($auto_evaluate_question_types) && count($auto_evaluate_question_types)) { // Validated } else { $auto_evaluate_question_types = array('single'); } if (isset($type) && in_array($type, $auto_evaluate_question_types)) { $correct_answer = get_post_meta($question, 'vibe_question_answer', true); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query(array('post_id' => $question, 'user_id' => $user_id, 'number' => 1, 'status' => 'approve')); foreach ($comments as $comment) { $comment->comment_content = trim($comment->comment_content, ','); if ($comment->comment_content == $correct_answer) { $marks = $questions['marks'][$key]; $total_marks = $total_marks + $marks; } else { // Use cases for No exact match for answer if ($type == 'multiple') { if (!strlen($comment->comment_content)) { $marks = 0; } else { $marked_answers = explode(',', $comment->comment_content); if (!is_array($marks_answers)) { // Force Array Form $marks_answers = array($marks_answers); } $correct_answers = explode(',', $correct_answer); if (!is_array($correct_answers)) { // Force Array Form $correct_answers = array($correct_answers); } sort($marked_answers); sort($correct_answers); if (array_diff($marked_answers, $correct_answers) == array_diff($correct_answers, $marked_answers)) { $marks = $questions['marks'][$key]; $total_marks = $total_marks + $marks; } else { $marks = apply_filters('wplms_incorrect_quiz_answer', 0, $quiz_id, $comment->comment_content, $question); $total_marks = $total_marks + $marks; } } } else { if ($type == 'smalltext' || $type == 'fillblank') { if (strpos($correct_answer, ',')) { $correct_answers_array = explode(',', $correct_answer); foreach ($correct_answers_array as $c_answer) { if (strtolower($c_answer) == strtolower($comment->comment_content)) { $marks = $questions['marks'][$key]; $total_marks = $total_marks + $marks; break; } else { $marks = apply_filters('wplms_incorrect_quiz_answer', 0, $quiz_id, $comment->comment_content, $question); $total_marks = $total_marks + $marks; } } } } } // If user does not marks in any of above use cases if ($marks == 0) { $marks = apply_filters('wplms_incorrect_quiz_answer', 0, $quiz_id, $comment->comment_content, $question); } } update_comment_meta($comment->comment_ID, 'marks', $marks); } //END-For } } } update_post_meta($quiz_id, $user_id, $total_marks); $max_marks = array_sum($questions['marks']); do_action('wplms_evaluate_quiz', $quiz_id, $total_marks, $user_id, $max_marks); } } else { // End Auto evaluate and Send notification to instructor do_action('wplms_submit_quiz', $quiz_id, $course_id, $user_id); } }
/** * Calculate what page number a comment will appear on for comment paging. * * @since 2.7.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $comment_ID Comment ID. * @param array $args { * Array of optional arguments. * @type string $type Limit paginated comments to those matching a given type. Accepts 'comment', * 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'. * Default is 'all'. * @type int $per_page Per-page count to use when calculating pagination. Defaults to the value of the * 'comments_per_page' option. * @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of * `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option. * } * * @return int|null Comment page number or null on error. */ function get_page_of_comment($comment_ID, $args = array()) { global $wpdb; $page = null; if (!($comment = get_comment($comment_ID))) { return; } $defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => ''); $args = wp_parse_args($args, $defaults); $original_args = $args; // Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option. if (get_option('page_comments')) { if ('' === $args['per_page']) { $args['per_page'] = get_query_var('comments_per_page'); } if ('' === $args['per_page']) { $args['per_page'] = get_option('comments_per_page'); } } if (empty($args['per_page'])) { $args['per_page'] = 0; $args['page'] = 0; } if ($args['per_page'] < 1) { $page = 1; } if (null === $page) { if ('' === $args['max_depth']) { if (get_option('thread_comments')) { $args['max_depth'] = get_option('thread_comments_depth'); } else { $args['max_depth'] = -1; } } // Find this comment's top level parent if threading is enabled if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) { return get_page_of_comment($comment->comment_parent, $args); } $comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt))); $comment_query = new WP_Comment_Query(); $older_comment_count = $comment_query->query($comment_args); // No older comments? Then it's page #1. if (0 == $older_comment_count) { $page = 1; // Divide comments older than this one by comments per page to get this comment's page number } else { $page = ceil(($older_comment_count + 1) / $args['per_page']); } } /** * Filters the calculated page on which a comment appears. * * @since 4.4.0 * * @param int $page Comment page. * @param array $args { * Arguments used to calculate pagination. These include arguments auto-detected by the function, * based on query vars, system settings, etc. For pristine arguments passed to the function, * see `$original_args`. * * @type string $type Type of comments to count. * @type int $page Calculated current page. * @type int $per_page Calculated number of comments per page. * @type int $max_depth Maximum comment threading depth allowed. * } * @param array $original_args { * Array of arguments passed to the function. Some or all of these may not be set. * * @type string $type Type of comments to count. * @type int $page Current comment page. * @type int $per_page Number of comments per page. * @type int $max_depth Maximum comment threading depth allowed. * } */ return apply_filters('get_page_of_comment', (int) $page, $args, $original_args); }
function render_comments_table($limit) { global $current_user, $wpdb; $pagenum = isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 1; $offset = ($pagenum - 1) * $limit; $args = array('number' => $limit, 'offset' => $offset, 'post_author' => $current_user->ID, 'post_type' => 'download', 'status' => 'approve', 'meta_query' => array(array('key' => 'fes-already-processed', 'compare' => 'NOT EXISTS'))); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); if (count($comments) == 0) { echo '<tr><td colspan="4">' . __('No Comments Found', 'edd_fes') . '</td></tr>'; } foreach ($comments as $comment) { $this->render_comments_table_row($comment); } $args = array('post_author' => $current_user->ID, 'post_type' => 'download', 'status' => 'approve', 'author__not_in' => array($current_user->ID), 'meta_query' => array(array('key' => 'fes-already-processed', 'compare' => 'NOT EXISTS'))); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); if (count($comments) > 0) { $pagenum = isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 1; $num_of_pages = ceil(count($comments) / $limit); $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'prev_text' => __('«', 'aag'), 'next_text' => __('»', 'aag'), 'total' => $num_of_pages, 'current' => $pagenum)); if ($page_links) { echo '<div class="fes-pagination">' . $page_links . '</div>'; } } }
/** * @ticket 22400 */ public function test_comment_cache_key_should_ignore_custom_params() { global $wpdb; $p = self::factory()->post->create(); $c = self::factory()->comment->create(array('comment_post_ID' => $p)); $q1 = new WP_Comment_Query(); $q1->query(array('post_id' => $p, 'fields' => 'ids')); $num_queries = $wpdb->num_queries; $q2 = new WP_Comment_Query(); $q2->query(array('post_id' => $p, 'fields' => 'ids', 'foo' => 'bar')); $this->assertSame($num_queries, $wpdb->num_queries); }
/** * Checks if a review already exists by using a eKomi order ID * * @param string $review_order_id * @return boolean */ public function review_exists($review_order_id) { $comments_query = new WP_Comment_Query(); $comments = $comments_query->query(array('meta_key' => 'order_id', 'meta_value' => $review_order_id)); return empty($comments) ? false : true; }
function xoadanhgiakhoahoc() { $id = $_POST['id']; $course_id = $_POST['course_id']; $kq = wp_delete_comment($id); if ($kq == true) { $args = array('status' => 'approve', 'post_id' => $course_id); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); if ($comments) { $ratings = 0; $count = 0; $rating = array(); foreach ($comments as $comment) { $rate = get_comment_meta($comment->comment_ID, 'review_rating', true); if (isset($rate) && $rate != '') { $rating[] = $rate; } } $count = count($rating); if (!$count) { $count = 1; } $ratings = round(array_sum($rating) / $count, 1); update_post_meta($course_id, 'average_rating', $ratings); update_post_meta($course_id, 'rating_count', $count); } echo '1'; } else { echo 'xóa đánh giá thất bại'; } die; }
function bp_course_quiz_auto_submit($quiz_id, $user_id) { $quiz_auto_evaluate = get_post_meta($quiz_id, 'vibe_quiz_auto_evaluate', true); if (vibe_validate($quiz_auto_evaluate)) { // Auto Evaluate for Quiz Enabled, Quiz auto evaluate, autoevaluate $total_marks = 0; $questions = vibe_sanitize(get_post_meta($quiz_id, 'quiz_questions' . $user_id, false)); if (!isset($questions) || !is_array($questions)) { // Fallback for Older versions $questions = vibe_sanitize(get_post_meta($quiz_id, 'vibe_quiz_questions', false)); } if (count($questions)) { $sum = $max_sum = 0; foreach ($questions['ques'] as $key => $question) { // Grab all the Questions if (isset($question) && $question) { $type = get_post_meta($question, 'vibe_question_type', true); $auto_evaluate_question_types = vibe_get_option('auto_eval_question_type'); if (isset($auto_evaluate_question_types) && is_Array($auto_evaluate_question_types) && count($auto_evaluate_question_types)) { // Validated } else { $auto_evaluate_question_types = array('single'); } if (isset($type) && in_array($type, $auto_evaluate_question_types)) { $correct_answer = get_post_meta($question, 'vibe_question_answer', true); $comments_query = new WP_Comment_Query(); $comments = $comments_query->query(array('post_id' => $question, 'user_id' => $user_id, 'number' => 1, 'status' => 'approve')); foreach ($comments as $comment) { $comment->comment_content = trim($comment->comment_content, ','); if ($comment->comment_content == $correct_answer) { $marks = $questions['marks'][$key]; $total_marks = $total_marks + $marks; } else { if ($type == 'multiple') { if (!strlen($comment->comment_content)) { $marks = 0; } else { $marked_answers = explode(',', $comment->comment_content); if (!is_array($marks_answers)) { // Force Array Form $marks_answers = array($marks_answers); } $correct_answers = explode(',', $correct_answer); if (!is_array($correct_answers)) { // Force Array Form $correct_answers = array($correct_answers); } sort($marked_answers); sort($correct_answers); if (array_diff($marked_answers, $correct_answers) == array_diff($correct_answers, $marked_answers)) { $marks = $questions['marks'][$key]; $total_marks = $total_marks + $marks; } else { $marks = apply_filters('wplms_incorrect_quiz_answer', 0, $comment->comment_content, $question); } } } elseif ($type == 'smalltext' || $type == 'fillblank') { if (strpos($correct_answer, ',')) { $correct_answers_array = explode(',', $correct_answer); foreach ($correct_answers_array as $c_answer) { if (strtolower($c_answer) == strtolower($comment->comment_content)) { $marks = $questions['marks'][$key]; $total_marks = $total_marks + $marks; break; } } } } else { $marks = apply_filters('wplms_incorrect_quiz_answer', 0, $comment->comment_content, $question); } } update_comment_meta($comment->comment_ID, 'marks', $marks); } //END-For } } } if (update_post_meta($quiz_id, $user_id, $total_marks)) { $message = __('You\'ve obtained ', 'vibe') . $total_marks . __(' out of ', 'vibe') . array_sum($questions['marks']) . __(' in quiz ', 'vibe') . ' <a href="' . get_permalink($quiz_id) . '">' . get_the_title($quiz_id) . '</a>'; $sender_id = get_post_field('post_author', $quiz_id); if (!is_numeric($sender_id)) { $sender_id = get_current_user_id(); } if (function_exists('messages_new_message')) { messages_new_message(array('sender_id' => $sender_id, 'subject' => __('Quiz results available', 'vibe'), 'content' => $message, 'recipients' => $user_id)); } $max_marks = array_sum($questions['marks']); $activity_id = bp_course_record_activity(array('action' => __('Quiz Auto Evaluated', 'vibe'), 'content' => __('Quiz ', 'vibe') . get_the_title($quiz_id) . __(' auto evaluated for student ', 'vibe') . bp_core_get_userlink($user_id) . __(' with marks ', 'vibe') . ' = ' . $total_marks . __('/', 'vibe') . $max_marks, 'type' => 'evaluate_quiz', 'primary_link' => get_permalink($quiz_id), 'item_id' => $quiz_id, 'secondary_item_id' => $user_id)); bp_course_record_activity_meta(array('id' => $activity_id, 'meta_key' => 'instructor', 'meta_value' => get_post_field('post_author', $quiz_id))); do_action('badgeos_wplms_evaluate_quiz', $quiz_id, $total_marks, $user_id); } } } else { // End Auto evaluate and Send notification to instructor if (function_exists('messages_new_message')) { $instructor_id = get_post_field('post_author', $quiz_id); $course_id = get_post_meta($quiz_id, 'vibe_course', true); if (isset($course_id) && is_numeric($course_id)) { $quiz_link = '<a href="' . get_permalink($course_id) . '?action=admin&submissions">' . get_the_title($quiz_id) . '</a>'; } else { $quiz_link = get_the_title($quiz_id); } $message = sprintf(__('Quiz %s submitted by student %s for evaluation', 'vibe'), $quiz_link, bp_core_get_userlink($user_id)); messages_new_message(array('sender_id' => $user_id, 'subject' => __('Quiz submitted for evaluation', 'vibe'), 'content' => $message, 'recipients' => $instructor_id)); } } }
function wplms_ajax_notes_discussion($name) { $args = array(); $user_id = get_current_user_id(); $number = vibe_get_option('loop_number'); if (!is_numeric($number)) { $number = 5; } switch ($name) { case 'all': $args = apply_filters('wplms_notes_dicussion_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve')); break; case 'all_public': $args = apply_filters('wplms_notes_dicussion_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'type' => 'public')); break; case 'unit_notes': $user_id = get_current_user_id(); $args = apply_filters('wplms_notes_dicussion_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'post_author' => $user_id, 'type' => 'note')); break; case 'unit_discussions': $user_id = get_current_user_id(); $args = apply_filters('wplms_notes_dicussion_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'post_author' => $user_id, 'type' => 'public')); break; case 'my_notes': $user_id = get_current_user_id(); $args = apply_filters('wplms_notes_dicussion_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'type' => 'note', 'user_id' => $user_id)); $args['user_id'] = $user_id; break; case 'my_discussion': $args = apply_filters('wplms_notes_dicussion_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'type' => 'public', 'user_id' => $user_id)); $args['user_id'] = $user_id; break; } ?> <div id="notes_query"><?php echo json_encode($args); ?> </div> <div id="notes_discussions"> <?php $comments_query = new WP_Comment_Query(); $comments = $comments_query->query($args); $this->comments_loop($comments); ?> </div> <?php }