本文整理汇总了PHP中wp_get_comment_status函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_comment_status函数的具体用法?PHP wp_get_comment_status怎么用?PHP wp_get_comment_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_comment_status函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: annot_end_shortcode
/**
* Annotaion Shortcode - End of a annotation
* @param array $atts Attributes of the shortcode - only c for the comment id is accepted and required
* @param null $content the Content in the code
* @return null|string
*/
public static function annot_end_shortcode($atts, $content = null)
{
// Attributes
extract(shortcode_atts(array('c' => false), $atts));
//Check if the comment is shown then add the span for the javascript
if ($c && wp_get_comment_status($c) == 'approved') {
return '<span id="annot-stop-' . $c . '" class="annot-stop"></span>' . $content;
} else {
return $content;
}
}
示例2: _test_as_admin
/**
* Test as a privilged user (administrator)
* Expects test to pass
* @param mixed $comment Comment object
* @return void
*/
public function _test_as_admin($comment)
{
// Reset request
$this->_clear_post_action();
// Become an administrator
$this->_setRole('administrator');
// Set up a default request
$_POST['id'] = $comment->comment_ID;
$_POST['_ajax_nonce'] = wp_create_nonce('approve-comment_' . $comment->comment_ID);
$_POST['_total'] = count($this->_comments);
$_POST['_per_page'] = 100;
$_POST['_page'] = 1;
$_POST['_url'] = admin_url('edit-comments.php');
// Save the comment status
$prev_status = wp_get_comment_status($comment->comment_ID);
// Make the request
try {
$this->_handleAjax('dim-comment');
} catch (WPAjaxDieContinueException $e) {
unset($e);
}
// Get the response
$xml = simplexml_load_string($this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA);
// Ensure everything is correct
$this->assertEquals($comment->comment_ID, (string) $xml->response[0]->comment['id']);
$this->assertEquals('dim-comment_' . $comment->comment_ID, (string) $xml->response['action']);
$this->assertGreaterThanOrEqual(time() - 10, (int) $xml->response[0]->comment[0]->supplemental[0]->time[0]);
$this->assertLessThanOrEqual(time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0]);
// Check the status
$current = wp_get_comment_status($comment->comment_ID);
if (in_array($prev_status, array('unapproved', 'spam'))) {
$this->assertEquals('approved', $current);
} else {
$this->assertEquals('unapproved', $current);
}
// The total is calculated based on a page break -OR- a random number. Let's look for both possible outcomes
$comment_count = wp_count_comments(0);
$recalc_total = $comment_count->total_comments;
// Delta is not specified, it will always be 1 lower than the request
$total = $_POST['_total'] - 1;
// Check for either possible total
$this->assertTrue(in_array((int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array($total, $recalc_total)));
}
示例3: get_events
/**
* Get list of events. There's filter `slack_get_events`
* to extend available events that can be notified to
* Slack.
*/
public function get_events()
{
return apply_filters('slack_get_events', array('post_published' => array('action' => 'transition_post_status', 'description' => __('When a post is published', 'slack'), 'default' => true, 'message' => function ($new_status, $old_status, $post) {
$notified_post_types = apply_filters('slack_event_transition_post_status_post_types', array('post'));
if (!in_array($post->post_type, $notified_post_types)) {
return false;
}
if ('publish' !== $old_status && 'publish' === $new_status) {
$excerpt = has_excerpt($post->ID) ? apply_filters('get_the_excerpt', $post->post_excerpt) : wp_trim_words(strip_shortcodes($post->post_content), 55, '…');
return sprintf('New post published: *<%1$s|%2$s>* by *%3$s*' . "\n" . '> %4$s', get_permalink($post->ID), get_the_title($post->ID), get_the_author_meta('display_name', $post->post_author), $excerpt);
}
}), 'post_pending_review' => array('action' => 'transition_post_status', 'description' => __('When a post needs review', 'slack'), 'default' => false, 'message' => function ($new_status, $old_status, $post) {
$notified_post_types = apply_filters('slack_event_transition_post_status_post_types', array('post'));
if (!in_array($post->post_type, $notified_post_types)) {
return false;
}
if ('pending' !== $old_status && 'pending' === $new_status) {
$excerpt = has_excerpt($post->ID) ? apply_filters('get_the_excerpt', $post->post_excerpt) : wp_trim_words(strip_shortcodes($post->post_content), 55, '…');
return sprintf('New post needs review: *<%1$s|%2$s>* by *%3$s*' . "\n" . '> %4$s', admin_url(sprintf('post.php?post=%d&action=edit', $post->ID)), get_the_title($post->ID), get_the_author_meta('display_name', $post->post_author), $excerpt);
}
}), 'new_comment' => array('action' => 'wp_insert_comment', 'priority' => 999, 'description' => __('When there is a new comment', 'slack'), 'default' => false, 'message' => function ($comment_id, $comment) {
$comment = is_object($comment) ? $comment : get_comment(absint($comment));
$post_id = $comment->comment_post_ID;
$notified_post_types = apply_filters('slack_event_wp_insert_comment_post_types', array('post'));
if (!in_array(get_post_type($post_id), $notified_post_types)) {
return false;
}
$post_title = get_the_title($post_id);
$comment_status = wp_get_comment_status($comment_id);
// Ignore spam.
if ('spam' === $comment_status) {
return false;
}
return sprintf('<%1$s|New comment> by *%2$s* on *<%3$s|%4$s>* (_%5$s_)' . "\n" . '>%6$s', admin_url("comment.php?c={$comment_id}&action=editcomment"), $comment->comment_author, get_permalink($post_id), $post_title, $comment_status, preg_replace("/\n/", "\n>", get_comment_text($comment_id)));
})));
}
示例4: get_actions
/**
* @see CPAC_Column_Actions::get_actions()
* @since 2.3.4
*/
public function get_actions($id)
{
global $post, $comment_status;
$comment = get_comment($id);
// set uased vars
$user_can = current_user_can('edit_comment', $comment->comment_ID);
$the_comment_status = wp_get_comment_status($comment->comment_ID);
if ($user_can) {
$del_nonce = esc_html('_wpnonce=' . wp_create_nonce("delete-comment_{$comment->comment_ID}"));
$approve_nonce = esc_html('_wpnonce=' . wp_create_nonce("approve-comment_{$comment->comment_ID}"));
$url = "comment.php?c={$comment->comment_ID}";
$approve_url = esc_url($url . "&action=approvecomment&{$approve_nonce}");
$unapprove_url = esc_url($url . "&action=unapprovecomment&{$approve_nonce}");
$spam_url = esc_url($url . "&action=spamcomment&{$del_nonce}");
$unspam_url = esc_url($url . "&action=unspamcomment&{$del_nonce}");
$trash_url = esc_url($url . "&action=trashcomment&{$del_nonce}");
$untrash_url = esc_url($url . "&action=untrashcomment&{$del_nonce}");
$delete_url = esc_url($url . "&action=deletecomment&{$del_nonce}");
}
/** begin - copied from class-wp-comments-list-table */
if ($user_can) {
// preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
$actions = array('approve' => '', 'unapprove' => '', 'reply' => '', 'quickedit' => '', 'edit' => '', 'spam' => '', 'unspam' => '', 'trash' => '', 'untrash' => '', 'delete' => '');
if ($comment_status && 'all' != $comment_status) {
// not looking at all comments
if ('approved' == $the_comment_status) {
$actions['unapprove'] = "<a href='{$unapprove_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&new=unapproved vim-u vim-destructive' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
} else {
if ('unapproved' == $the_comment_status) {
$actions['approve'] = "<a href='{$approve_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}:e7e7d3:action=dim-comment&new=approved vim-a vim-destructive' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
}
}
} else {
$actions['approve'] = "<a href='{$approve_url}' class='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
$actions['unapprove'] = "<a href='{$unapprove_url}' class='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
}
if ('spam' != $the_comment_status && 'trash' != $the_comment_status) {
$actions['spam'] = "<a href='{$spam_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::spam=1 vim-s vim-destructive' title='" . esc_attr__('Mark this comment as spam') . "'>" . _x('Spam', 'verb') . '</a>';
} elseif ('spam' == $the_comment_status) {
$actions['unspam'] = "<a href='{$unspam_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:unspam=1 vim-z vim-destructive'>" . _x('Not Spam', 'comment') . '</a>';
} elseif ('trash' == $the_comment_status) {
$actions['untrash'] = "<a href='{$untrash_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}:66cc66:untrash=1 vim-z vim-destructive'>" . __('Restore') . '</a>';
}
if ('spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS) {
$actions['delete'] = "<a href='{$delete_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::delete=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
} else {
$actions['trash'] = "<a href='{$trash_url}' class='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1 delete vim-d vim-destructive' title='" . esc_attr__('Move this comment to the trash') . "'>" . _x('Trash', 'verb') . '</a>';
}
if ('spam' != $the_comment_status && 'trash' != $the_comment_status) {
$actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>" . __('Edit') . '</a>';
$actions['quickedit'] = '<a onclick="commentReply.open( \'' . $comment->comment_ID . '\',\'' . $post->ID . '\',\'edit\' );return false;" class="vim-q" title="' . esc_attr__('Quick Edit') . '" href="#">' . __('Quick Edit') . '</a>';
$actions['reply'] = '<a onclick="commentReply.open( \'' . $comment->comment_ID . '\',\'' . $post->ID . '\' );return false;" class="vim-r" title="' . esc_attr__('Reply to this comment') . '" href="#">' . __('Reply') . '</a>';
}
$actions = apply_filters('comment_row_actions', array_filter($actions), $comment);
$actions_copy = $actions;
$actions = array();
foreach ($actions_copy as $action => $link) {
$action_append = '';
// Reply and quickedit need a hide-if-no-js span when not added with ajax
if (('reply' == $action || 'quickedit' == $action) && !defined('DOING_AJAX')) {
$action_append .= ' hide-if-no-js';
} elseif ($action == 'untrash' && $the_comment_status == 'trash' || $action == 'unspam' && $the_comment_status == 'spam') {
if ('1' == get_comment_meta($comment->comment_ID, '_wp_trash_meta_status', true)) {
$action_append .= ' approve';
} else {
$action_append .= ' unapprove';
}
}
$action .= $action_append;
$actions[$action] = $link;
}
}
return $actions;
}
示例5: _wp_dashboard_recent_comments_row
/**
* @global WP_Comment $comment
*
* @param WP_Comment $comment
* @param bool $show_date
*/
function _wp_dashboard_recent_comments_row(&$comment, $show_date = true)
{
$GLOBALS['comment'] = clone $comment;
if ($comment->comment_post_ID > 0 && current_user_can('edit_post', $comment->comment_post_ID)) {
$comment_post_title = _draft_or_post_title($comment->comment_post_ID);
$comment_post_url = get_edit_post_link($comment->comment_post_ID);
$comment_post_link = "<a href='{$comment_post_url}'>{$comment_post_title}</a>";
} else {
$comment_post_link = '';
}
$actions_string = '';
if (current_user_can('edit_comment', $comment->comment_ID)) {
// Pre-order it: Approve | Reply | Edit | Spam | Trash.
$actions = array('approve' => '', 'unapprove' => '', 'reply' => '', 'edit' => '', 'spam' => '', 'trash' => '', 'delete' => '', 'view' => '');
$del_nonce = esc_html('_wpnonce=' . wp_create_nonce("delete-comment_{$comment->comment_ID}"));
$approve_nonce = esc_html('_wpnonce=' . wp_create_nonce("approve-comment_{$comment->comment_ID}"));
$approve_url = esc_url("comment.php?action=approvecomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$approve_nonce}");
$unapprove_url = esc_url("comment.php?action=unapprovecomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$approve_nonce}");
$spam_url = esc_url("comment.php?action=spamcomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$del_nonce}");
$trash_url = esc_url("comment.php?action=trashcomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$del_nonce}");
$delete_url = esc_url("comment.php?action=deletecomment&p={$comment->comment_post_ID}&c={$comment->comment_ID}&{$del_nonce}");
$actions['approve'] = "<a href='{$approve_url}' data-wp-lists='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__('Approve this comment') . "'>" . __('Approve') . '</a>';
$actions['unapprove'] = "<a href='{$unapprove_url}' data-wp-lists='dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' title='" . esc_attr__('Unapprove this comment') . "'>" . __('Unapprove') . '</a>';
$actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>" . __('Edit') . '</a>';
$actions['reply'] = '<a onclick="window.commentReply && commentReply.open(\'' . $comment->comment_ID . '\',\'' . $comment->comment_post_ID . '\');return false;" class="vim-r hide-if-no-js" title="' . esc_attr__('Reply to this comment') . '" href="#">' . __('Reply') . '</a>';
$actions['spam'] = "<a href='{$spam_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::spam=1' class='vim-s vim-destructive' title='" . esc_attr__('Mark this comment as spam') . "'>" . _x('Spam', 'verb') . '</a>';
if (!EMPTY_TRASH_DAYS) {
$actions['delete'] = "<a href='{$delete_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1' class='delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
} else {
$actions['trash'] = "<a href='{$trash_url}' data-wp-lists='delete:the-comment-list:comment-{$comment->comment_ID}::trash=1' class='delete vim-d vim-destructive' title='" . esc_attr__('Move this comment to the trash') . "'>" . _x('Trash', 'verb') . '</a>';
}
if ('1' === $comment->comment_approved) {
$actions['view'] = '<a class="comment-link" href="' . esc_url(get_comment_link($comment)) . '">' . _x('View', 'verb') . '</a>';
}
/**
* Filter the action links displayed for each comment in the 'Recent Comments'
* dashboard widget.
*
* @since 2.6.0
*
* @param array $actions An array of comment actions. Default actions include:
* 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
* 'Delete', and 'Trash'.
* @param WP_Comment $comment The comment object.
*/
$actions = apply_filters('comment_row_actions', array_filter($actions), $comment);
$i = 0;
foreach ($actions as $action => $link) {
++$i;
('approve' == $action || 'unapprove' == $action) && 2 === $i || 1 === $i ? $sep = '' : ($sep = ' | ');
// Reply and quickedit need a hide-if-no-js span
if ('reply' == $action || 'quickedit' == $action) {
$action .= ' hide-if-no-js';
}
$actions_string .= "<span class='{$action}'>{$sep}{$link}</span>";
}
}
?>
<div id="comment-<?php
echo $comment->comment_ID;
?>
" <?php
comment_class(array('comment-item', wp_get_comment_status($comment)), $comment);
?>
>
<?php
echo get_avatar($comment, 50, 'mystery');
?>
<?php
if (!$comment->comment_type || 'comment' == $comment->comment_type) {
?>
<div class="dashboard-comment-wrap has-row-actions">
<h4 class="comment-meta">
<?php
if ($comment_post_link) {
printf(__('From %1$s on %2$s%3$s'), '<cite class="comment-author">' . get_comment_author_link($comment) . '</cite>', $comment_post_link, ' <span class="approve">' . __('[Pending]') . '</span>');
} else {
printf(__('From %1$s %2$s'), '<cite class="comment-author">' . get_comment_author_link($comment) . '</cite>', ' <span class="approve">' . __('[Pending]') . '</span>');
}
?>
</h4>
<?php
} else {
switch ($comment->comment_type) {
case 'pingback':
$type = __('Pingback');
break;
case 'trackback':
$type = __('Trackback');
//.........这里部分代码省略.........
示例6: wp_new_comment
/**
* Adds a new comment to the database.
*
* Filters new comment to ensure that the fields are sanitized and valid before
* inserting comment into database. Calls 'comment_post' action with comment ID
* and whether comment is approved by WordPress. Also has 'preprocess_comment'
* filter for processing the comment data before the function handles it.
*
* We use REMOTE_ADDR here directly. If you are behind a proxy, you should ensure
* that it is properly set, such as in wp-config.php, for your environment.
* See {@link https://core.trac.wordpress.org/ticket/9235}
*
* @since 1.5.0
* @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`.
*
* @see wp_insert_comment()
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param array $commentdata {
* Comment data.
*
* @type string $comment_author The name of the comment author.
* @type string $comment_author_email The comment author email address.
* @type string $comment_author_url The comment author URL.
* @type string $comment_content The content of the comment.
* @type string $comment_date The date the comment was submitted. Default is the current time.
* @type string $comment_date_gmt The date the comment was submitted in the GMT timezone.
* Default is `$comment_date` in the GMT timezone.
* @type int $comment_parent The ID of this comment's parent, if any. Default 0.
* @type int $comment_post_ID The ID of the post that relates to the comment.
* @type int $user_id The ID of the user who submitted the comment. Default 0.
* @type int $user_ID Kept for backward-compatibility. Use `$user_id` instead.
* @type string $comment_agent Comment author user agent. Default is the value of 'HTTP_USER_AGENT'
* in the `$_SERVER` superglobal sent in the original request.
* @type string $comment_author_IP Comment author IP address in IPv4 format. Default is the value of
* 'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request.
* }
* @return int|false The ID of the comment on success, false on failure.
*/
function wp_new_comment($commentdata)
{
global $wpdb;
if (isset($commentdata['user_ID'])) {
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
}
$prefiltered_user_id = isset($commentdata['user_id']) ? (int) $commentdata['user_id'] : 0;
/**
* Filter a comment's data before it is sanitized and inserted into the database.
*
* @since 1.5.0
*
* @param array $commentdata Comment data.
*/
$commentdata = apply_filters('preprocess_comment', $commentdata);
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
if (isset($commentdata['user_ID']) && $prefiltered_user_id !== (int) $commentdata['user_ID']) {
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
} elseif (isset($commentdata['user_id'])) {
$commentdata['user_id'] = (int) $commentdata['user_id'];
}
$commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
$parent_status = 0 < $commentdata['comment_parent'] ? wp_get_comment_status($commentdata['comment_parent']) : '';
$commentdata['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $commentdata['comment_parent'] : 0;
if (!isset($commentdata['comment_author_IP'])) {
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
}
$commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP']);
if (!isset($commentdata['comment_agent'])) {
$commentdata['comment_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
}
$commentdata['comment_agent'] = substr($commentdata['comment_agent'], 0, 254);
if (empty($commentdata['comment_date'])) {
$commentdata['comment_date'] = current_time('mysql');
}
if (empty($commentdata['comment_date_gmt'])) {
$commentdata['comment_date_gmt'] = current_time('mysql', 1);
}
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
if (!$comment_ID) {
$fields = array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_content');
foreach ($fields as $field) {
if (isset($commentdata[$field])) {
$commentdata[$field] = $wpdb->strip_invalid_text_for_column($wpdb->comments, $field, $commentdata[$field]);
}
}
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
if (!$comment_ID) {
return false;
}
}
/**
* Fires immediately after a comment is inserted into the database.
*
* @since 1.2.0
*
* @param int $comment_ID The comment ID.
//.........这里部分代码省略.........
示例7: cron_recheck
public static function cron_recheck()
{
global $wpdb;
$api_key = self::get_api_key();
$status = self::verify_key($api_key);
if (get_option('akismet_alert_code') || $status == 'invalid') {
// since there is currently a problem with the key, reschedule a check for 6 hours hence
wp_schedule_single_event(time() + 21600, 'akismet_schedule_cron_recheck');
do_action('akismet_scheduled_recheck', 'key-problem-' . get_option('akismet_alert_code') . '-' . $status);
return false;
}
delete_option('akismet_available_servers');
$comment_errors = $wpdb->get_col("SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'\tLIMIT 100");
load_plugin_textdomain('akismet');
foreach ((array) $comment_errors as $comment_id) {
// if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
$comment = get_comment($comment_id);
if (!$comment || strtotime($comment->comment_date_gmt) < strtotime("-15 days")) {
delete_comment_meta($comment_id, 'akismet_error');
delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
continue;
}
add_comment_meta($comment_id, 'akismet_rechecking', true);
$status = self::check_db_comment($comment_id, 'retry');
$event = '';
if ($status == 'true') {
$event = 'cron-retry-spam';
} elseif ($status == 'false') {
$event = 'cron-retry-ham';
}
// If we got back a legit response then update the comment history
// other wise just bail now and try again later. No point in
// re-trying all the comments once we hit one failure.
if (!empty($event)) {
delete_comment_meta($comment_id, 'akismet_error');
self::update_comment_history($comment_id, '', $event);
update_comment_meta($comment_id, 'akismet_result', $status);
// make sure the comment status is still pending. if it isn't, that means the user has already moved it elsewhere.
$comment = get_comment($comment_id);
if ($comment && 'unapproved' == wp_get_comment_status($comment_id)) {
if ($status == 'true') {
wp_spam_comment($comment_id);
} elseif ($status == 'false') {
// comment is good, but it's still in the pending queue. depending on the moderation settings
// we may need to change it to approved.
if (check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type)) {
wp_set_comment_status($comment_id, 1);
} else {
if (get_comment_meta($comment_id, 'akismet_delayed_moderation_email', true)) {
wp_notify_moderator($comment_id);
}
}
}
}
delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
} else {
// If this comment has been pending moderation for longer than MAX_DELAY_BEFORE_MODERATION_EMAIL,
// send a moderation email now.
if (intval(gmdate('U')) - strtotime($comment->comment_date_gmt) < self::MAX_DELAY_BEFORE_MODERATION_EMAIL) {
delete_comment_meta($comment_id, 'akismet_delayed_moderation_email');
wp_notify_moderator($comment_id);
}
delete_comment_meta($comment_id, 'akismet_rechecking');
wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
do_action('akismet_scheduled_recheck', 'check-db-comment-' . $status);
return;
}
delete_comment_meta($comment_id, 'akismet_rechecking');
}
$remaining = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'");
if ($remaining && !wp_next_scheduled('akismet_schedule_cron_recheck')) {
wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
do_action('akismet_scheduled_recheck', 'remaining');
}
}
示例8: get_comment
function get_comment($comment_id, $context)
{
global $blog_id;
$comment = get_comment($comment_id);
if (!$comment || is_wp_error($comment)) {
return new WP_Error('unknown_comment', 'Unknown comment', 404);
}
$types = array('', 'comment', 'pingback', 'trackback');
if (!in_array($comment->comment_type, $types)) {
return new WP_Error('unknown_comment', 'Unknown comment', 404);
}
$post = get_post($comment->comment_post_ID);
if (!$post || is_wp_error($post)) {
return new WP_Error('unknown_post', 'Unknown post', 404);
}
$status = wp_get_comment_status($comment->comment_ID);
// Permissions
switch ($context) {
case 'edit':
if (!current_user_can('edit_comment', $comment->comment_ID)) {
return new WP_Error('unauthorized', 'User cannot edit comment', 403);
}
$GLOBALS['post'] = $post;
$comment = get_comment_to_edit($comment->comment_ID);
foreach (array('comment_author', 'comment_author_email', 'comment_author_url') as $field) {
$comment->{$field} = htmlspecialchars_decode($comment->{$field}, ENT_QUOTES);
}
break;
case 'display':
if ('approved' !== $status) {
$current_user_id = get_current_user_id();
$user_can_read_coment = false;
if ($current_user_id && $comment->user_id && $current_user_id == $comment->user_id) {
$user_can_read_coment = true;
} elseif ($comment->comment_author_email && $comment->comment_author && isset($this->api->token_details['user']) && isset($this->api->token_details['user']['user_email']) && $this->api->token_details['user']['user_email'] === $comment->comment_author_email && $this->api->token_details['user']['display_name'] === $comment->comment_author) {
$user_can_read_coment = true;
} else {
$user_can_read_coment = current_user_can('edit_comment', $comment->comment_ID);
}
if (!$user_can_read_coment) {
return new WP_Error('unauthorized', 'User cannot read unapproved comment', 403);
}
}
$GLOBALS['post'] = $post;
setup_postdata($post);
break;
default:
return new WP_Error('invalid_context', 'Invalid API CONTEXT', 400);
}
$can_view = $this->user_can_view_post($post->ID);
if (!$can_view || is_wp_error($can_view)) {
return $can_view;
}
$GLOBALS['comment'] = $comment;
$response = array();
foreach (array_keys($this->comment_object_format) as $key) {
switch ($key) {
case 'ID':
// explicitly cast all output
$response[$key] = (int) $comment->comment_ID;
break;
case 'post':
$response[$key] = (object) array('ID' => (int) $post->ID, 'title' => (string) get_the_title($post->ID), 'type' => (string) $post->post_type, 'link' => (string) $this->links->get_post_link($this->api->get_blog_id_for_output(), $post->ID));
break;
case 'author':
$response[$key] = (object) $this->get_author($comment, 'edit' === $context && current_user_can('edit_comment', $comment->comment_ID));
break;
case 'date':
$response[$key] = (string) $this->format_date($comment->comment_date_gmt, $comment->comment_date);
break;
case 'URL':
$response[$key] = (string) esc_url_raw(get_comment_link($comment->comment_ID));
break;
case 'short_URL':
// @todo - pagination
$response[$key] = (string) esc_url_raw(wp_get_shortlink($post->ID) . "%23comment-{$comment->comment_ID}");
break;
case 'content':
if ('display' === $context) {
ob_start();
comment_text();
$response[$key] = (string) ob_get_clean();
} else {
$response[$key] = (string) $comment->comment_content;
}
break;
case 'status':
$response[$key] = (string) $status;
break;
case 'parent':
// (object|false)
if ($comment->comment_parent) {
$parent = get_comment($comment->comment_parent);
$response[$key] = (object) array('ID' => (int) $parent->comment_ID, 'type' => (string) ($parent->comment_type ? $parent->comment_type : 'comment'), 'link' => (string) $this->links->get_comment_link($blog_id, $parent->comment_ID));
} else {
$response[$key] = false;
}
break;
case 'type':
$response[$key] = (string) ($comment->comment_type ? $comment->comment_type : 'comment');
//.........这里部分代码省略.........
示例9: get_comment_list_item
function get_comment_list_item($id, $alt = 0, $reply = false)
{
global $authordata, $comment, $wpdb, $user_identity, $user_email, $user_url;
get_currentuserinfo();
$id = (int) $id;
$comment =& get_comment($id);
$class = '';
$post = get_post($comment->comment_post_ID);
$authordata = get_userdata($post->post_author);
$comment_status = wp_get_comment_status($comment->comment_ID);
if (isset($_GET['replyid'])) {
$query = remove_query_arg('replyid');
} else {
$query = add_query_arg('replyid', $comment->comment_ID);
}
if ('unapproved' == $comment_status) {
$class .= ' unapproved';
}
if ($alt % 2) {
$class .= ' alternate';
}
echo "<li id='comment-{$comment->comment_ID}' class='{$class}'>";
?>
<p><strong><?php
comment_author();
?>
</strong> <?php
if ($comment->comment_author_email) {
?>
| <?php
comment_author_email_link();
?>
<?php
}
if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) {
?>
| <?php
comment_author_url_link();
?>
<?php
}
?>
| <?php
_e('IP:');
?>
<a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php
comment_author_IP();
?>
"><?php
comment_author_IP();
?>
</a></p>
<?php
comment_text();
?>
<p><?php
comment_date(__('M j, g:i A'));
?>
— [
<?php
if (current_user_can('edit_post', $comment->comment_post_ID)) {
echo " <a href='comment.php?action=editcomment&c=" . $comment->comment_ID . "'>" . __('Edit') . '</a>';
echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
if ('none' != $comment_status && current_user_can('moderate_comments')) {
echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
}
echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&dt=spam&p=" . $comment->comment_post_ID . "&c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', {$comment->comment_ID}, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> ";
echo " | <a href='" . $query . "' onclick=' return addReplyForm(\"" . get_option('siteurl') . "/wp-content/plugins/soc-comments/soc-comments-post.php\"," . $id . "," . $comment->comment_post_ID . ",\"" . $user_identity . "\",\"" . $user_email . "\",\"" . $user_url . "\",\"" . wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) . "\",\"" . add_query_arg('ajax', '1') . "\")' >" . __('Reply') . " </a>";
}
$post = get_post($comment->comment_post_ID);
$post_title = wp_specialchars($post->post_title, 'double');
$post_title = '' == $post_title ? "# {$comment->comment_post_ID}" : $post_title;
?>
] — <a href="<?php
echo get_permalink($comment->comment_post_ID);
?>
"><?php
echo $post_title;
?>
</a></p>
<div id="com-<?php
echo $comment->comment_ID;
?>
" >
<?php
if (true == $reply) {
?>
<?php
if ('open' == $post->comment_status) {
?>
<form action="<?php
echo get_option('siteurl');
?>
/wp-comments-post.php" method="POST" id="comment-reply-form">
//.........这里部分代码省略.........
示例10: delete_comment
function delete_comment($path, $blog_id, $comment_id)
{
$comment = get_comment($comment_id);
if (!$comment || is_wp_error($comment)) {
return new WP_Error('unknown_comment', 'Unknown comment', 404);
}
if (!current_user_can('edit_comment', $comment->comment_ID)) {
// [sic] There is no delete_comment cap
return new WP_Error('unauthorized', 'User cannot delete comment', 403);
}
$args = $this->query_args();
$return = $this->get_comment($comment->comment_ID, $args['context']);
if (!$return || is_wp_error($return)) {
return $return;
}
do_action('wpcom_json_api_objects', 'comments');
wp_delete_comment($comment->comment_ID);
$status = wp_get_comment_status($comment->comment_ID);
if (false === $status) {
$return['status'] = 'deleted';
return $return;
}
return $this->get_comment($comment->comment_ID, $args['context']);
}
示例11: die
if (wp_delete_post($id)) {
die('1');
} else {
die('0');
}
break;
case 'dim-comment':
// On success, die with time() instead of 1
if (!($comment = get_comment($id))) {
$x = new WP_Ajax_Response(array('what' => 'comment', 'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))));
$x->send();
}
if (!current_user_can('edit_post', $comment->comment_post_ID) && !current_user_can('moderate_comments')) {
die('-1');
}
$current = wp_get_comment_status($comment->comment_ID);
if ($_POST['new'] == $current) {
die((string) time());
}
check_ajax_referer("approve-comment_{$id}");
if (in_array($current, array('unapproved', 'spam'))) {
$result = wp_set_comment_status($comment->comment_ID, 'approve', true);
} else {
$result = wp_set_comment_status($comment->comment_ID, 'hold', true);
}
if (is_wp_error($result)) {
$x = new WP_Ajax_Response(array('what' => 'comment', 'id' => $result));
$x->send();
}
// Decide if we need to send back '1' or a more complicated response including page links and comment counts
_wp_ajax_delete_comment_response($comment->comment_ID);
示例12: handle_status_param
/**
* Set the comment_status of a given comment object when creating or updating a comment.
*
* @param string|int $new_status
* @param object $comment
* @return boolean $changed
*/
protected function handle_status_param($new_status, $comment)
{
$old_status = wp_get_comment_status($comment->comment_ID);
if ($new_status === $old_status) {
return false;
}
switch ($new_status) {
case 'approved':
case 'approve':
case '1':
$changed = wp_set_comment_status($comment->comment_ID, 'approve');
break;
case 'hold':
case '0':
$changed = wp_set_comment_status($comment->comment_ID, 'hold');
break;
case 'spam':
$changed = wp_spam_comment($comment->comment_ID);
break;
case 'unspam':
$changed = wp_unspam_comment($comment->comment_ID);
break;
case 'trash':
$changed = wp_trash_comment($comment->comment_ID);
break;
case 'untrash':
$changed = wp_untrash_comment($comment->comment_ID);
break;
default:
$changed = false;
break;
}
return $changed;
}
示例13: hook_edit_comment
function hook_edit_comment($comment_id)
{
if (wp_get_comment_status($comment_id) == 'approved') {
$container = blcContainerHelper::get_container(array($this->container_type, $comment_id));
$container->mark_as_unsynched();
}
}
示例14: widget
//.........这里部分代码省略.........
$post = null;
$id = RatingWidgetPlugin::Urid2PostId($urid);
$status = @get_post_status($id);
if (false === $status) {
if (RWLogger::IsOn()) {
RWLogger::Log('POST_NOT_EXIST', $id);
}
// Post not exist.
continue;
} else {
if ('publish' !== $status && 'private' !== $status) {
if (RWLogger::IsOn()) {
RWLogger::Log('POST_NOT_VISIBLE', 'status = ' . $status);
}
// Post not yet published.
continue;
} else {
if ('private' === $status && !is_user_logged_in()) {
if (RWLogger::IsOn()) {
RWLogger::Log('RatingWidgetPlugin_TopRatedWidget::widget', 'POST_PRIVATE && USER_LOGGED_OUT');
}
// Private post but user is not logged in.
continue;
}
}
}
$post = @get_post($id);
$title = trim(strip_tags($post->post_title));
$permalink = get_permalink($post->ID);
} else {
if ('comments' === $type) {
$comment = null;
$id = RatingWidgetPlugin::Urid2CommentId($urid);
$status = @wp_get_comment_status($id);
if (false === $status) {
if (RWLogger::IsOn()) {
RWLogger::Log('COMMENT_NOT_EXIST', $id);
}
// Comment not exist.
continue;
} else {
if ('approved' !== $status) {
if (RWLogger::IsOn()) {
RWLogger::Log('COMMENT_NOT_VISIBLE', 'status = ' . $status);
}
// Comment not approved.
continue;
}
}
$comment = @get_comment($id);
$title = trim(strip_tags($comment->comment_content));
$permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
} else {
if ('activity_updates' === $type || 'activity_comments' === $type) {
$id = RatingWidgetPlugin::Urid2ActivityId($urid);
$activity = new bp_activity_activity($id);
if (!is_object($activity)) {
if (RWLogger::IsOn()) {
RWLogger::Log('BP_ACTIVITY_NOT_EXIST', $id);
}
// Activity not exist.
continue;
} else {
if (!empty($activity->is_spam)) {
if (RWLogger::IsOn()) {
RWLogger::Log('BP_ACTIVITY_NOT_VISIBLE (SPAM or TRASH)');
示例15: get_status_link
/**
* Returns a approve/unapprove/spam/unspam/trash/untrash link for a comment
*
* @param $comment_id int The comment_id of the comment you want the URL to affect
* @param $type string The type of action you want the link to apply to the comment: approve/spam/trash
*/
public function get_status_link($comment_id, $type)
{
if (!($comment = get_comment($comment_id))) {
return FALSE;
}
// END if
if (!in_array($type, array('approve', 'spam', 'trash'))) {
return FALSE;
}
// END if
$text = NULL;
$class = NULL;
$status = wp_get_comment_status($comment->comment_ID);
if ('approve' == $type) {
if ('approved' == $status) {
$text = 'Unapprove';
$class = 'approved-comment';
} else {
$text = 'Approve';
$class = 'unapproved-comment';
}
//end else
} elseif ('spam' == $type) {
if ('spam' == $status) {
$text = 'Unspam';
$class = 'spammed-comment';
} else {
$text = 'Spam';
$class = 'unspamed-comment';
}
//end else
} elseif ('trash' == $type) {
if ('trash' == $status) {
$text = 'Untrash';
$class = 'trashed-comment';
} else {
$text = 'Trash';
$class = 'untrashed-comment';
}
//end else
}
//end elseif
if (!$text) {
return;
}
//end if
$url = $this->get_status_url($comment->comment_ID, $type);
return '<a href="' . esc_url($url) . '" title="' . $text . '" class="' . $class . '">' . $text . '</a>';
}