[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> comment.php (summary)

Core Comment API

File Size: 4030 lines (129 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 2 files
 wp-includes/class-IXR.php
 wp-includes/class-wp-http-ixr-client.php

Defines 72 functions

  check_comment()
  get_approved_comments()
  get_comment()
  get_comments()
  get_comment_statuses()
  get_default_comment_status()
  get_lastcommentmodified()
  get_comment_count()
  add_comment_meta()
  delete_comment_meta()
  get_comment_meta()
  wp_lazyload_comment_meta()
  update_comment_meta()
  wp_set_comment_cookies()
  sanitize_comment_cookies()
  wp_allow_comment()
  check_comment_flood_db()
  wp_check_comment_flood()
  separate_comments()
  get_comment_pages_count()
  get_page_of_comment()
  wp_get_comment_fields_max_lengths()
  wp_check_comment_data_max_lengths()
  wp_check_comment_disallowed_list()
  wp_count_comments()
  wp_delete_comment()
  wp_trash_comment()
  wp_untrash_comment()
  wp_spam_comment()
  wp_unspam_comment()
  wp_get_comment_status()
  wp_transition_comment_status()
  _clear_modified_cache_on_transition_comment_status()
  wp_get_current_commenter()
  wp_get_unapproved_comment_author_email()
  wp_insert_comment()
  wp_filter_comment()
  wp_throttle_comment_flood()
  wp_new_comment()
  wp_new_comment_notify_moderator()
  wp_new_comment_notify_postauthor()
  wp_set_comment_status()
  wp_update_comment()
  wp_defer_comment_counting()
  wp_update_comment_count()
  wp_update_comment_count_now()
  discover_pingback_server_uri()
  do_all_pings()
  do_all_pingbacks()
  do_all_enclosures()
  do_all_trackbacks()
  do_trackbacks()
  generic_ping()
  pingback()
  privacy_ping_filter()
  trackback()
  weblog_ping()
  pingback_ping_source_uri()
  xmlrpc_pingback_error()
  clean_comment_cache()
  update_comment_cache()
  _prime_comment_caches()
  _close_comments_for_old_posts()
  _close_comments_for_old_post()
  wp_handle_comment_submission()
  wp_register_comment_personal_data_exporter()
  wp_comments_personal_data_exporter()
  wp_register_comment_personal_data_eraser()
  wp_comments_personal_data_eraser()
  wp_cache_set_comments_last_changed()
  _wp_batch_update_comment_type()
  _wp_check_for_scheduled_update_comment_type()

Functions
Functions that are not part of a class:

check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type )   X-Ref
Checks whether a comment passes internal checks to be allowed to add.

If manual comment moderation is set in the administration, then all checks,
regardless of their type and substance, will fail and the function will
return false.

If the number of links exceeds the amount in the administration, then the
check fails. If any of the parameter contents contain any disallowed words,
then the check fails.

If the comment author was approved before, then the comment is automatically
approved.

If all checks pass, the function will return true.

param: string $author       Comment author name.
param: string $email        Comment author email.
param: string $url          Comment author URL.
param: string $comment      Content of the comment.
param: string $user_ip      Comment author IP address.
param: string $user_agent   Comment author User-Agent.
param: string $comment_type Comment type, either user-submitted comment,
return: bool If all checks pass, true, otherwise false.

get_approved_comments( $post_id, $args = array()   X-Ref
Retrieves the approved comments for a post.

param: int   $post_id The ID of the post.
param: array $args    {
return: WP_Comment[]|int[]|int The approved comments, or number of comments if `$count`

get_comment( $comment = null, $output = OBJECT )   X-Ref
Retrieves comment data given a comment ID or comment object.

If an object is passed then the comment data will be cached and then returned
after being passed through a filter. If the comment is empty, then the global
comment variable will be used, if it is set.

param: WP_Comment|string|int $comment Comment to retrieve.
param: string                $output  Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
return: WP_Comment|array|null Depends on $output value.

get_comments( $args = '' )   X-Ref
Retrieves a list of comments.

The comment list can be for the blog as a whole or for an individual post.

param: string|array $args Optional. Array or string of arguments. See WP_Comment_Query::__construct()
return: WP_Comment[]|int[]|int List of comments or number of found comments if `$count` argument is true.

get_comment_statuses()   X-Ref
Retrieves all of the WordPress supported comment statuses.

Comments have a limited set of valid status values, this provides the comment
status values and descriptions.

return: string[] List of comment status labels keyed by status.

get_default_comment_status( $post_type = 'post', $comment_type = 'comment' )   X-Ref
Gets the default comment status for a post type.

param: string $post_type    Optional. Post type. Default 'post'.
param: string $comment_type Optional. Comment type. Default 'comment'.
return: string Either 'open' or 'closed'.

get_lastcommentmodified( $timezone = 'server' )   X-Ref
Retrieves the date the last comment was modified.

param: string $timezone Which timezone to use in reference to 'gmt', 'blog', or 'server' locations.
return: string|false Last comment modified date on success, false on failure.

get_comment_count( $post_id = 0 )   X-Ref
Retrieves the total comment counts for the whole site or a single post.

param: int $post_id Optional. Restrict the comment counts to the given post. Default 0, which indicates that
return: int[] {

add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false )   X-Ref
Adds meta data field to a comment.

param: int    $comment_id Comment ID.
param: string $meta_key   Metadata name.
param: mixed  $meta_value Metadata value. Must be serializable if non-scalar.
param: bool   $unique     Optional. Whether the same key should not be added.
return: int|false Meta ID on success, false on failure.

delete_comment_meta( $comment_id, $meta_key, $meta_value = '' )   X-Ref
Removes metadata matching criteria from a comment.

You can match based on the key, or key and value. Removing based on key and
value, will keep from removing duplicate metadata with the same key. It also
allows removing all metadata matching key, if needed.

param: int    $comment_id Comment ID.
param: string $meta_key   Metadata name.
param: mixed  $meta_value Optional. Metadata value. If provided,
return: bool True on success, false on failure.

get_comment_meta( $comment_id, $key = '', $single = false )   X-Ref
Retrieves comment meta field for a comment.

param: int    $comment_id Comment ID.
param: string $key        Optional. The meta key to retrieve. By default,
param: bool   $single     Optional. Whether to return a single value.
return: mixed An array of values if `$single` is false.

wp_lazyload_comment_meta( array $comment_ids )   X-Ref
Queue comment meta for lazy-loading.

param: array $comment_ids List of comment IDs.

update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' )   X-Ref
Updates comment meta field based on comment ID.

Use the $prev_value parameter to differentiate between meta fields with the
same key and comment ID.

If the meta field for the comment does not exist, it will be added.

param: int    $comment_id Comment ID.
param: string $meta_key   Metadata key.
param: mixed  $meta_value Metadata value. Must be serializable if non-scalar.
param: mixed  $prev_value Optional. Previous value to check before updating.
return: int|bool Meta ID if the key didn't exist, true on successful update,

wp_set_comment_cookies( $comment, $user, $cookies_consent = true )   X-Ref
Sets the cookies used to store an unauthenticated commentator's identity. Typically used
to recall previous comments by this commentator that are still held in moderation.

param: WP_Comment $comment         Comment object.
param: WP_User    $user            Comment author's user object. The user may not exist.
param: bool       $cookies_consent Optional. Comment author's consent to store cookies. Default true.

sanitize_comment_cookies()   X-Ref
Sanitizes the cookies sent to the user already.

Will only do anything if the cookies have already been created for the user.
Mostly used after cookies had been sent to use elsewhere.


wp_allow_comment( $commentdata, $wp_error = false )   X-Ref
Validates whether this comment is allowed to be made.

param: array $commentdata Contains information on the comment.
param: bool  $wp_error    When true, a disallowed comment will result in the function
return: int|string|WP_Error Allowed comments return the approval status (0|1|'spam'|'trash').

check_comment_flood_db()   X-Ref
Hooks WP's native database-based comment-flood check.

This wrapper maintains backward compatibility with plugins that expect to
be able to unhook the legacy check_comment_flood_db() function from
'check_comment_flood' using remove_action().


wp_check_comment_flood( $is_flood, $ip, $email, $date, $avoid_die = false )   X-Ref
Checks whether comment flooding is occurring.

Won't run, if current user can manage options, so to not block
administrators.

param: bool   $is_flood  Is a comment flooding occurring?
param: string $ip        Comment author's IP address.
param: string $email     Comment author's email address.
param: string $date      MySQL time string.
param: bool   $avoid_die When true, a disallowed comment will result in the function
return: bool Whether comment flooding is occurring.

separate_comments( &$comments )   X-Ref
Separates an array of comments into an array keyed by comment_type.

param: WP_Comment[] $comments Array of comments
return: WP_Comment[] Array of comments keyed by comment_type.

get_comment_pages_count( $comments = null, $per_page = null, $threaded = null )   X-Ref
Calculates the total number of comment pages.

param: WP_Comment[] $comments Optional. Array of WP_Comment objects. Defaults to `$wp_query->comments`.
param: int          $per_page Optional. Comments per page. Defaults to the value of `comments_per_page`
param: bool         $threaded Optional. Control over flat or threaded comments. Defaults to the value
return: int Number of comment pages.

get_page_of_comment( $comment_id, $args = array()   X-Ref
Calculates what page number a comment will appear on for comment paging.

param: int   $comment_id Comment ID.
param: array $args {
return: int|null Comment page number or null on error.

wp_get_comment_fields_max_lengths()   X-Ref
Retrieves the maximum character lengths for the comment form fields.

return: int[] Array of maximum lengths keyed by field name.

wp_check_comment_data_max_lengths( $comment_data )   X-Ref
Compares the lengths of comment data against the maximum character limits.

param: array $comment_data Array of arguments for inserting a comment.
return: WP_Error|true WP_Error when a comment field exceeds the limit,

wp_check_comment_disallowed_list( $author, $email, $url, $comment, $user_ip, $user_agent )   X-Ref
Checks if a comment contains disallowed characters or words.

param: string $author The author of the comment
param: string $email The email of the comment
param: string $url The url used in the comment
param: string $comment The comment content
param: string $user_ip The comment author's IP address
param: string $user_agent The author's browser user agent
return: bool True if comment contains disallowed content, false if comment does not

wp_count_comments( $post_id = 0 )   X-Ref
Retrieves the total comment counts for the whole site or a single post.

The comment stats are cached and then retrieved, if they already exist in the
cache.

param: int $post_id Optional. Restrict the comment counts to the given post. Default 0, which indicates that
return: stdClass {

wp_delete_comment( $comment_id, $force_delete = false )   X-Ref
Trashes or deletes a comment.

The comment is moved to Trash instead of permanently deleted unless Trash is
disabled, item is already in the Trash, or $force_delete is true.

The post comment count will be updated if the comment was approved and has a
post ID available.

param: int|WP_Comment $comment_id   Comment ID or WP_Comment object.
param: bool           $force_delete Whether to bypass Trash and force deletion. Default false.
return: bool True on success, false on failure.

wp_trash_comment( $comment_id )   X-Ref
Moves a comment to the Trash

If Trash is disabled, comment is permanently deleted.

param: int|WP_Comment $comment_id Comment ID or WP_Comment object.
return: bool True on success, false on failure.

wp_untrash_comment( $comment_id )   X-Ref
Removes a comment from the Trash

param: int|WP_Comment $comment_id Comment ID or WP_Comment object.
return: bool True on success, false on failure.

wp_spam_comment( $comment_id )   X-Ref
Marks a comment as Spam.

param: int|WP_Comment $comment_id Comment ID or WP_Comment object.
return: bool True on success, false on failure.

wp_unspam_comment( $comment_id )   X-Ref
Removes a comment from the Spam.

param: int|WP_Comment $comment_id Comment ID or WP_Comment object.
return: bool True on success, false on failure.

wp_get_comment_status( $comment_id )   X-Ref
Retrieves the status of a comment by comment ID.

param: int|WP_Comment $comment_id Comment ID or WP_Comment object
return: string|false Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure.

wp_transition_comment_status( $new_status, $old_status, $comment )   X-Ref
Calls hooks for when a comment status transition occurs.

Calls hooks for comment status transitions. If the new comment status is not the same
as the previous comment status, then two hooks will be ran, the first is
{@see 'transition_comment_status'} with new status, old status, and comment data.
The next action called is {@see 'comment_$old_status_to_$new_status'}. It has
the comment data.

The final action will run whether or not the comment statuses are the same.
The action is named {@see 'comment_$new_status_$comment->comment_type'}.

param: string     $new_status New comment status.
param: string     $old_status Previous comment status.
param: WP_Comment $comment    Comment object.

_clear_modified_cache_on_transition_comment_status( $new_status, $old_status )   X-Ref
Clears the lastcommentmodified cached value when a comment status is changed.

Deletes the lastcommentmodified cache key when a comment enters or leaves
'approved' status.

param: string $new_status The new comment status.
param: string $old_status The old comment status.

wp_get_current_commenter()   X-Ref
Gets current commenter's name, email, and URL.

Expects cookies content to already be sanitized. User of this function might
wish to recheck the returned array for validity.

return: array {

wp_get_unapproved_comment_author_email()   X-Ref
Gets unapproved comment author's email.

Used to allow the commenter to see their pending comment.

return: string The unapproved comment author's email (when supplied).

wp_insert_comment( $commentdata )   X-Ref
Inserts a comment into the database.

param: array $commentdata {
return: int|false The new comment's ID on success, false on failure.

wp_filter_comment( $commentdata )   X-Ref
Filters and sanitizes comment data.

Sets the comment data 'filtered' field to true when finished. This can be
checked as to whether the comment should be filtered and to keep from
filtering the same comment more than once.

param: array $commentdata Contains information on the comment.
return: array Parsed comment information.

wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment )   X-Ref
Determines whether a comment should be blocked because of comment flood.

param: bool $block            Whether plugin has already blocked comment.
param: int  $time_lastcomment Timestamp for last comment.
param: int  $time_newcomment  Timestamp for new comment.
return: bool Whether comment should be blocked.

wp_new_comment( $commentdata, $wp_error = false )   X-Ref
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 {@see 'comment_post'} action with comment ID
and whether comment is approved by WordPress. Also has {@see '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}

param: array $commentdata {
param: bool  $wp_error Should errors be returned as WP_Error objects instead of
return: int|false|WP_Error The ID of the comment on success, false or WP_Error on failure.

wp_new_comment_notify_moderator( $comment_id )   X-Ref
Sends a comment moderation notification to the comment moderator.

param: int $comment_id ID of the comment.
return: bool True on success, false on failure.

wp_new_comment_notify_postauthor( $comment_id )   X-Ref
Sends a notification of a new comment to the post author.

param: int $comment_id Comment ID.
return: bool True on success, false on failure.

wp_set_comment_status( $comment_id, $comment_status, $wp_error = false )   X-Ref
Sets the status of a comment.

The {@see 'wp_set_comment_status'} action is called after the comment is handled.
If the comment status is not in the list, then false is returned.

param: int|WP_Comment $comment_id     Comment ID or WP_Comment object.
param: string         $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'.
param: bool           $wp_error       Whether to return a WP_Error object if there is a failure. Default false.
return: bool|WP_Error True on success, false or WP_Error on failure.

wp_update_comment( $commentarr, $wp_error = false )   X-Ref
Updates an existing comment in the database.

Filters the comment and makes sure certain fields are valid before updating.

param: array $commentarr Contains information on the comment.
param: bool  $wp_error   Optional. Whether to return a WP_Error on failure. Default false.
return: int|false|WP_Error The value 1 if the comment was updated, 0 if not updated.

wp_defer_comment_counting( $defer = null )   X-Ref
Determines whether to defer comment counting.

When setting $defer to true, all post comment counts will not be updated
until $defer is set to false. When $defer is set to false, then all
previously deferred updated post comment counts will then be automatically
updated without having to call wp_update_comment_count() after.

param: bool $defer
return: bool

wp_update_comment_count( $post_id, $do_deferred = false )   X-Ref
Updates the comment count for post(s).

When $do_deferred is false (is by default) and the comments have been set to
be deferred, the post_id will be added to a queue, which will be updated at a
later date and only updated once per post ID.

If the comments have not be set up to be deferred, then the post will be
updated. When $do_deferred is set to true, then all previous deferred post
IDs will be updated along with the current $post_id.

param: int|null $post_id     Post ID.
param: bool     $do_deferred Optional. Whether to process previously deferred
return: bool|void True on success, false on failure or if post with ID does

wp_update_comment_count_now( $post_id )   X-Ref
Updates the comment count for the post.

param: int $post_id Post ID
return: bool True on success, false if the post does not exist.

discover_pingback_server_uri( $url, $deprecated = '' )   X-Ref
Finds a pingback server URI based on the given URL.

Checks the HTML for the rel="pingback" link and X-Pingback headers. It does
a check for the X-Pingback headers first and returns that, if available.
The check for the rel="pingback" has more overhead than just the header.

param: string $url        URL to ping.
param: string $deprecated Not Used.
return: string|false String containing URI on success, false on failure.

do_all_pings()   X-Ref
Performs all pingbacks, enclosures, trackbacks, and sends to pingback services.


do_all_pingbacks()   X-Ref
Performs all pingbacks.


do_all_enclosures()   X-Ref
Performs all enclosures.


do_all_trackbacks()   X-Ref
Performs all trackbacks.


do_trackbacks( $post )   X-Ref
Performs trackbacks.

param: int|WP_Post $post Post ID or object to do trackbacks on.
return: void|false Returns false on failure.

generic_ping( $post_id = 0 )   X-Ref
Sends pings to all of the ping site services.

param: int $post_id Post ID.
return: int Same post ID as provided.

pingback( $content, $post )   X-Ref
Pings back the links found in a post.

param: string      $content Post content to check for links. If empty will retrieve from post.
param: int|WP_Post $post    Post ID or object.

privacy_ping_filter( $sites )   X-Ref
Checks whether blog is public before returning sites.

param: mixed $sites Will return if blog is public, will not return if not public.
return: mixed Empty string if blog is not public, returns $sites, if site is public.

trackback( $trackback_url, $title, $excerpt, $post_id )   X-Ref
Sends a Trackback.

Updates database when sending trackback to prevent duplicates.

param: string $trackback_url URL to send trackbacks.
param: string $title         Title of post.
param: string $excerpt       Excerpt of post.
param: int    $post_id       Post ID.
return: int|false|void Database query from update.

weblog_ping( $server = '', $path = '' )   X-Ref
Sends a pingback.

param: string $server Host of blog to connect to.
param: string $path Path to send the ping.

pingback_ping_source_uri( $source_uri )   X-Ref
Default filter attached to pingback_ping_source_uri to validate the pingback's Source URI.

param: string $source_uri
return: string

xmlrpc_pingback_error( $ixr_error )   X-Ref
Default filter attached to xmlrpc_pingback_error.

Returns a generic pingback error code unless the error code is 48,
which reports that the pingback is already registered.

param: IXR_Error $ixr_error
return: IXR_Error

clean_comment_cache( $ids )   X-Ref
Removes a comment from the object cache.

param: int|array $ids Comment ID or an array of comment IDs to remove from cache.

update_comment_cache( $comments, $update_meta_cache = true )   X-Ref
Updates the comment cache of given comments.

Will add the comments in $comments to the cache. If comment ID already exists
in the comment cache then it will not be updated. The comment is added to the
cache using the comment group with the key using the ID of the comments.

param: WP_Comment[] $comments          Array of comment objects
param: bool         $update_meta_cache Whether to update commentmeta cache. Default true.

_prime_comment_caches( $comment_ids, $update_meta_cache = true )   X-Ref
Adds any comments from the given IDs to the cache that do not already exist in cache.

param: int[] $comment_ids       Array of comment IDs.
param: bool  $update_meta_cache Optional. Whether to update the meta cache. Default true.

_close_comments_for_old_posts( $posts, $query )   X-Ref
Closes comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.

param: WP_Post  $posts Post data object.
param: WP_Query $query Query object.
return: array

_close_comments_for_old_post( $open, $post_id )   X-Ref
Closes comments on an old post. Hooked to comments_open and pings_open.

param: bool $open    Comments open or closed.
param: int  $post_id Post ID.
return: bool $open

wp_handle_comment_submission( $comment_data )   X-Ref
Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form.

This function expects unslashed data, as opposed to functions such as `wp_new_comment()` which
expect slashed data.

param: array $comment_data {
return: WP_Comment|WP_Error A WP_Comment object on success, a WP_Error object on failure.

wp_register_comment_personal_data_exporter( $exporters )   X-Ref
Registers the personal data exporter for comments.

param: array[] $exporters An array of personal data exporters.
return: array[] An array of personal data exporters.

wp_comments_personal_data_exporter( $email_address, $page = 1 )   X-Ref
Finds and exports personal data associated with an email address from the comments table.

param: string $email_address The comment author email address.
param: int    $page          Comment page number.
return: array {

wp_register_comment_personal_data_eraser( $erasers )   X-Ref
Registers the personal data eraser for comments.

param: array $erasers An array of personal data erasers.
return: array An array of personal data erasers.

wp_comments_personal_data_eraser( $email_address, $page = 1 )   X-Ref
Erases personal data associated with an email address from the comments table.

param: string $email_address The comment author email address.
param: int    $page          Comment page number.
return: array {

wp_cache_set_comments_last_changed()   X-Ref
Sets the last changed time for the 'comment' cache group.


_wp_batch_update_comment_type()   X-Ref
Updates the comment type for a batch of comments.


_wp_check_for_scheduled_update_comment_type()   X-Ref
In order to avoid the _wp_batch_update_comment_type() job being accidentally removed,
check that it's still scheduled while we haven't finished updating comment types.




Generated : Fri Apr 19 08:20:01 2024 Cross-referenced by PHPXref