Edit File by line
/home/barbar84/www/wp-inclu...
File: comment.php
}
[3000] Fix | Delete
[3001] Fix | Delete
/*
[3002] Fix | Delete
* Step 1.
[3003] Fix | Delete
* Parsing the post, external links (if any) are stored in the $post_links array.
[3004] Fix | Delete
*/
[3005] Fix | Delete
$post_links_temp = wp_extract_urls( $content );
[3006] Fix | Delete
[3007] Fix | Delete
/*
[3008] Fix | Delete
* Step 2.
[3009] Fix | Delete
* Walking through the links array.
[3010] Fix | Delete
* First we get rid of links pointing to sites, not to specific files.
[3011] Fix | Delete
* Example:
[3012] Fix | Delete
* http://dummy-weblog.org
[3013] Fix | Delete
* http://dummy-weblog.org/
[3014] Fix | Delete
* http://dummy-weblog.org/post.php
[3015] Fix | Delete
* We don't wanna ping first and second types, even if they have a valid <link/>.
[3016] Fix | Delete
*/
[3017] Fix | Delete
foreach ( (array) $post_links_temp as $link_test ) {
[3018] Fix | Delete
// If we haven't pung it already and it isn't a link to itself.
[3019] Fix | Delete
if ( ! in_array( $link_test, $pung, true ) && ( url_to_postid( $link_test ) != $post->ID )
[3020] Fix | Delete
// Also, let's never ping local attachments.
[3021] Fix | Delete
&& ! is_local_attachment( $link_test )
[3022] Fix | Delete
) {
[3023] Fix | Delete
$test = parse_url( $link_test );
[3024] Fix | Delete
if ( $test ) {
[3025] Fix | Delete
if ( isset( $test['query'] ) ) {
[3026] Fix | Delete
$post_links[] = $link_test;
[3027] Fix | Delete
} elseif ( isset( $test['path'] ) && ( '/' !== $test['path'] ) && ( '' !== $test['path'] ) ) {
[3028] Fix | Delete
$post_links[] = $link_test;
[3029] Fix | Delete
}
[3030] Fix | Delete
}
[3031] Fix | Delete
}
[3032] Fix | Delete
}
[3033] Fix | Delete
[3034] Fix | Delete
$post_links = array_unique( $post_links );
[3035] Fix | Delete
[3036] Fix | Delete
/**
[3037] Fix | Delete
* Fires just before pinging back links found in a post.
[3038] Fix | Delete
*
[3039] Fix | Delete
* @since 2.0.0
[3040] Fix | Delete
*
[3041] Fix | Delete
* @param string[] $post_links Array of link URLs to be checked (passed by reference).
[3042] Fix | Delete
* @param string[] $pung Array of link URLs already pinged (passed by reference).
[3043] Fix | Delete
* @param int $post_ID The post ID.
[3044] Fix | Delete
*/
[3045] Fix | Delete
do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post->ID ) );
[3046] Fix | Delete
[3047] Fix | Delete
foreach ( (array) $post_links as $pagelinkedto ) {
[3048] Fix | Delete
$pingback_server_url = discover_pingback_server_uri( $pagelinkedto );
[3049] Fix | Delete
[3050] Fix | Delete
if ( $pingback_server_url ) {
[3051] Fix | Delete
set_time_limit( 60 );
[3052] Fix | Delete
// Now, the RPC call.
[3053] Fix | Delete
$pagelinkedfrom = get_permalink( $post );
[3054] Fix | Delete
[3055] Fix | Delete
// Using a timeout of 3 seconds should be enough to cover slow servers.
[3056] Fix | Delete
$client = new WP_HTTP_IXR_Client( $pingback_server_url );
[3057] Fix | Delete
$client->timeout = 3;
[3058] Fix | Delete
/**
[3059] Fix | Delete
* Filters the user agent sent when pinging-back a URL.
[3060] Fix | Delete
*
[3061] Fix | Delete
* @since 2.9.0
[3062] Fix | Delete
*
[3063] Fix | Delete
* @param string $concat_useragent The user agent concatenated with ' -- WordPress/'
[3064] Fix | Delete
* and the WordPress version.
[3065] Fix | Delete
* @param string $useragent The useragent.
[3066] Fix | Delete
* @param string $pingback_server_url The server URL being linked to.
[3067] Fix | Delete
* @param string $pagelinkedto URL of page linked to.
[3068] Fix | Delete
* @param string $pagelinkedfrom URL of page linked from.
[3069] Fix | Delete
*/
[3070] Fix | Delete
$client->useragent = apply_filters( 'pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo( 'version' ), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom );
[3071] Fix | Delete
// When set to true, this outputs debug messages by itself.
[3072] Fix | Delete
$client->debug = false;
[3073] Fix | Delete
[3074] Fix | Delete
if ( $client->query( 'pingback.ping', $pagelinkedfrom, $pagelinkedto ) || ( isset( $client->error->code ) && 48 == $client->error->code ) ) { // Already registered.
[3075] Fix | Delete
add_ping( $post, $pagelinkedto );
[3076] Fix | Delete
}
[3077] Fix | Delete
}
[3078] Fix | Delete
}
[3079] Fix | Delete
}
[3080] Fix | Delete
[3081] Fix | Delete
/**
[3082] Fix | Delete
* Check whether blog is public before returning sites.
[3083] Fix | Delete
*
[3084] Fix | Delete
* @since 2.1.0
[3085] Fix | Delete
*
[3086] Fix | Delete
* @param mixed $sites Will return if blog is public, will not return if not public.
[3087] Fix | Delete
* @return mixed Empty string if blog is not public, returns $sites, if site is public.
[3088] Fix | Delete
*/
[3089] Fix | Delete
function privacy_ping_filter( $sites ) {
[3090] Fix | Delete
if ( '0' != get_option( 'blog_public' ) ) {
[3091] Fix | Delete
return $sites;
[3092] Fix | Delete
} else {
[3093] Fix | Delete
return '';
[3094] Fix | Delete
}
[3095] Fix | Delete
}
[3096] Fix | Delete
[3097] Fix | Delete
/**
[3098] Fix | Delete
* Send a Trackback.
[3099] Fix | Delete
*
[3100] Fix | Delete
* Updates database when sending trackback to prevent duplicates.
[3101] Fix | Delete
*
[3102] Fix | Delete
* @since 0.71
[3103] Fix | Delete
*
[3104] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[3105] Fix | Delete
*
[3106] Fix | Delete
* @param string $trackback_url URL to send trackbacks.
[3107] Fix | Delete
* @param string $title Title of post.
[3108] Fix | Delete
* @param string $excerpt Excerpt of post.
[3109] Fix | Delete
* @param int $ID Post ID.
[3110] Fix | Delete
* @return int|false|void Database query from update.
[3111] Fix | Delete
*/
[3112] Fix | Delete
function trackback( $trackback_url, $title, $excerpt, $ID ) {
[3113] Fix | Delete
global $wpdb;
[3114] Fix | Delete
[3115] Fix | Delete
if ( empty( $trackback_url ) ) {
[3116] Fix | Delete
return;
[3117] Fix | Delete
}
[3118] Fix | Delete
[3119] Fix | Delete
$options = array();
[3120] Fix | Delete
$options['timeout'] = 10;
[3121] Fix | Delete
$options['body'] = array(
[3122] Fix | Delete
'title' => $title,
[3123] Fix | Delete
'url' => get_permalink( $ID ),
[3124] Fix | Delete
'blog_name' => get_option( 'blogname' ),
[3125] Fix | Delete
'excerpt' => $excerpt,
[3126] Fix | Delete
);
[3127] Fix | Delete
[3128] Fix | Delete
$response = wp_safe_remote_post( $trackback_url, $options );
[3129] Fix | Delete
[3130] Fix | Delete
if ( is_wp_error( $response ) ) {
[3131] Fix | Delete
return;
[3132] Fix | Delete
}
[3133] Fix | Delete
[3134] Fix | Delete
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID ) );
[3135] Fix | Delete
return $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID ) );
[3136] Fix | Delete
}
[3137] Fix | Delete
[3138] Fix | Delete
/**
[3139] Fix | Delete
* Send a pingback.
[3140] Fix | Delete
*
[3141] Fix | Delete
* @since 1.2.0
[3142] Fix | Delete
*
[3143] Fix | Delete
* @param string $server Host of blog to connect to.
[3144] Fix | Delete
* @param string $path Path to send the ping.
[3145] Fix | Delete
*/
[3146] Fix | Delete
function weblog_ping( $server = '', $path = '' ) {
[3147] Fix | Delete
include_once ABSPATH . WPINC . '/class-IXR.php';
[3148] Fix | Delete
include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
[3149] Fix | Delete
[3150] Fix | Delete
// Using a timeout of 3 seconds should be enough to cover slow servers.
[3151] Fix | Delete
$client = new WP_HTTP_IXR_Client( $server, ( ( ! strlen( trim( $path ) ) || ( '/' === $path ) ) ? false : $path ) );
[3152] Fix | Delete
$client->timeout = 3;
[3153] Fix | Delete
$client->useragent .= ' -- WordPress/' . get_bloginfo( 'version' );
[3154] Fix | Delete
[3155] Fix | Delete
// When set to true, this outputs debug messages by itself.
[3156] Fix | Delete
$client->debug = false;
[3157] Fix | Delete
$home = trailingslashit( home_url() );
[3158] Fix | Delete
if ( ! $client->query( 'weblogUpdates.extendedPing', get_option( 'blogname' ), $home, get_bloginfo( 'rss2_url' ) ) ) { // Then try a normal ping.
[3159] Fix | Delete
$client->query( 'weblogUpdates.ping', get_option( 'blogname' ), $home );
[3160] Fix | Delete
}
[3161] Fix | Delete
}
[3162] Fix | Delete
[3163] Fix | Delete
/**
[3164] Fix | Delete
* Default filter attached to pingback_ping_source_uri to validate the pingback's Source URI
[3165] Fix | Delete
*
[3166] Fix | Delete
* @since 3.5.1
[3167] Fix | Delete
*
[3168] Fix | Delete
* @see wp_http_validate_url()
[3169] Fix | Delete
*
[3170] Fix | Delete
* @param string $source_uri
[3171] Fix | Delete
* @return string
[3172] Fix | Delete
*/
[3173] Fix | Delete
function pingback_ping_source_uri( $source_uri ) {
[3174] Fix | Delete
return (string) wp_http_validate_url( $source_uri );
[3175] Fix | Delete
}
[3176] Fix | Delete
[3177] Fix | Delete
/**
[3178] Fix | Delete
* Default filter attached to xmlrpc_pingback_error.
[3179] Fix | Delete
*
[3180] Fix | Delete
* Returns a generic pingback error code unless the error code is 48,
[3181] Fix | Delete
* which reports that the pingback is already registered.
[3182] Fix | Delete
*
[3183] Fix | Delete
* @since 3.5.1
[3184] Fix | Delete
*
[3185] Fix | Delete
* @link https://www.hixie.ch/specs/pingback/pingback#TOC3
[3186] Fix | Delete
*
[3187] Fix | Delete
* @param IXR_Error $ixr_error
[3188] Fix | Delete
* @return IXR_Error
[3189] Fix | Delete
*/
[3190] Fix | Delete
function xmlrpc_pingback_error( $ixr_error ) {
[3191] Fix | Delete
if ( 48 === $ixr_error->code ) {
[3192] Fix | Delete
return $ixr_error;
[3193] Fix | Delete
}
[3194] Fix | Delete
return new IXR_Error( 0, '' );
[3195] Fix | Delete
}
[3196] Fix | Delete
[3197] Fix | Delete
//
[3198] Fix | Delete
// Cache.
[3199] Fix | Delete
//
[3200] Fix | Delete
[3201] Fix | Delete
/**
[3202] Fix | Delete
* Removes a comment from the object cache.
[3203] Fix | Delete
*
[3204] Fix | Delete
* @since 2.3.0
[3205] Fix | Delete
*
[3206] Fix | Delete
* @param int|array $ids Comment ID or an array of comment IDs to remove from cache.
[3207] Fix | Delete
*/
[3208] Fix | Delete
function clean_comment_cache( $ids ) {
[3209] Fix | Delete
foreach ( (array) $ids as $id ) {
[3210] Fix | Delete
wp_cache_delete( $id, 'comment' );
[3211] Fix | Delete
[3212] Fix | Delete
/**
[3213] Fix | Delete
* Fires immediately after a comment has been removed from the object cache.
[3214] Fix | Delete
*
[3215] Fix | Delete
* @since 4.5.0
[3216] Fix | Delete
*
[3217] Fix | Delete
* @param int $id Comment ID.
[3218] Fix | Delete
*/
[3219] Fix | Delete
do_action( 'clean_comment_cache', $id );
[3220] Fix | Delete
}
[3221] Fix | Delete
[3222] Fix | Delete
wp_cache_set( 'last_changed', microtime(), 'comment' );
[3223] Fix | Delete
}
[3224] Fix | Delete
[3225] Fix | Delete
/**
[3226] Fix | Delete
* Updates the comment cache of given comments.
[3227] Fix | Delete
*
[3228] Fix | Delete
* Will add the comments in $comments to the cache. If comment ID already exists
[3229] Fix | Delete
* in the comment cache then it will not be updated. The comment is added to the
[3230] Fix | Delete
* cache using the comment group with the key using the ID of the comments.
[3231] Fix | Delete
*
[3232] Fix | Delete
* @since 2.3.0
[3233] Fix | Delete
* @since 4.4.0 Introduced the `$update_meta_cache` parameter.
[3234] Fix | Delete
*
[3235] Fix | Delete
* @param WP_Comment[] $comments Array of comment objects
[3236] Fix | Delete
* @param bool $update_meta_cache Whether to update commentmeta cache. Default true.
[3237] Fix | Delete
*/
[3238] Fix | Delete
function update_comment_cache( $comments, $update_meta_cache = true ) {
[3239] Fix | Delete
foreach ( (array) $comments as $comment ) {
[3240] Fix | Delete
wp_cache_add( $comment->comment_ID, $comment, 'comment' );
[3241] Fix | Delete
}
[3242] Fix | Delete
[3243] Fix | Delete
if ( $update_meta_cache ) {
[3244] Fix | Delete
// Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
[3245] Fix | Delete
$comment_ids = array();
[3246] Fix | Delete
foreach ( $comments as $comment ) {
[3247] Fix | Delete
$comment_ids[] = $comment->comment_ID;
[3248] Fix | Delete
}
[3249] Fix | Delete
update_meta_cache( 'comment', $comment_ids );
[3250] Fix | Delete
}
[3251] Fix | Delete
}
[3252] Fix | Delete
[3253] Fix | Delete
/**
[3254] Fix | Delete
* Adds any comments from the given IDs to the cache that do not already exist in cache.
[3255] Fix | Delete
*
[3256] Fix | Delete
* @since 4.4.0
[3257] Fix | Delete
* @access private
[3258] Fix | Delete
*
[3259] Fix | Delete
* @see update_comment_cache()
[3260] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[3261] Fix | Delete
*
[3262] Fix | Delete
* @param int[] $comment_ids Array of comment IDs.
[3263] Fix | Delete
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true.
[3264] Fix | Delete
*/
[3265] Fix | Delete
function _prime_comment_caches( $comment_ids, $update_meta_cache = true ) {
[3266] Fix | Delete
global $wpdb;
[3267] Fix | Delete
[3268] Fix | Delete
$non_cached_ids = _get_non_cached_ids( $comment_ids, 'comment' );
[3269] Fix | Delete
if ( ! empty( $non_cached_ids ) ) {
[3270] Fix | Delete
$fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) );
[3271] Fix | Delete
[3272] Fix | Delete
update_comment_cache( $fresh_comments, $update_meta_cache );
[3273] Fix | Delete
}
[3274] Fix | Delete
}
[3275] Fix | Delete
[3276] Fix | Delete
//
[3277] Fix | Delete
// Internal.
[3278] Fix | Delete
//
[3279] Fix | Delete
[3280] Fix | Delete
/**
[3281] Fix | Delete
* Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
[3282] Fix | Delete
*
[3283] Fix | Delete
* @since 2.7.0
[3284] Fix | Delete
* @access private
[3285] Fix | Delete
*
[3286] Fix | Delete
* @param WP_Post $posts Post data object.
[3287] Fix | Delete
* @param WP_Query $query Query object.
[3288] Fix | Delete
* @return array
[3289] Fix | Delete
*/
[3290] Fix | Delete
function _close_comments_for_old_posts( $posts, $query ) {
[3291] Fix | Delete
if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) ) {
[3292] Fix | Delete
return $posts;
[3293] Fix | Delete
}
[3294] Fix | Delete
[3295] Fix | Delete
/**
[3296] Fix | Delete
* Filters the list of post types to automatically close comments for.
[3297] Fix | Delete
*
[3298] Fix | Delete
* @since 3.2.0
[3299] Fix | Delete
*
[3300] Fix | Delete
* @param string[] $post_types An array of post type names.
[3301] Fix | Delete
*/
[3302] Fix | Delete
$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
[3303] Fix | Delete
if ( ! in_array( $posts[0]->post_type, $post_types, true ) ) {
[3304] Fix | Delete
return $posts;
[3305] Fix | Delete
}
[3306] Fix | Delete
[3307] Fix | Delete
$days_old = (int) get_option( 'close_comments_days_old' );
[3308] Fix | Delete
if ( ! $days_old ) {
[3309] Fix | Delete
return $posts;
[3310] Fix | Delete
}
[3311] Fix | Delete
[3312] Fix | Delete
if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
[3313] Fix | Delete
$posts[0]->comment_status = 'closed';
[3314] Fix | Delete
$posts[0]->ping_status = 'closed';
[3315] Fix | Delete
}
[3316] Fix | Delete
[3317] Fix | Delete
return $posts;
[3318] Fix | Delete
}
[3319] Fix | Delete
[3320] Fix | Delete
/**
[3321] Fix | Delete
* Close comments on an old post. Hooked to comments_open and pings_open.
[3322] Fix | Delete
*
[3323] Fix | Delete
* @since 2.7.0
[3324] Fix | Delete
* @access private
[3325] Fix | Delete
*
[3326] Fix | Delete
* @param bool $open Comments open or closed.
[3327] Fix | Delete
* @param int $post_id Post ID.
[3328] Fix | Delete
* @return bool $open
[3329] Fix | Delete
*/
[3330] Fix | Delete
function _close_comments_for_old_post( $open, $post_id ) {
[3331] Fix | Delete
if ( ! $open ) {
[3332] Fix | Delete
return $open;
[3333] Fix | Delete
}
[3334] Fix | Delete
[3335] Fix | Delete
if ( ! get_option( 'close_comments_for_old_posts' ) ) {
[3336] Fix | Delete
return $open;
[3337] Fix | Delete
}
[3338] Fix | Delete
[3339] Fix | Delete
$days_old = (int) get_option( 'close_comments_days_old' );
[3340] Fix | Delete
if ( ! $days_old ) {
[3341] Fix | Delete
return $open;
[3342] Fix | Delete
}
[3343] Fix | Delete
[3344] Fix | Delete
$post = get_post( $post_id );
[3345] Fix | Delete
[3346] Fix | Delete
/** This filter is documented in wp-includes/comment.php */
[3347] Fix | Delete
$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
[3348] Fix | Delete
if ( ! in_array( $post->post_type, $post_types, true ) ) {
[3349] Fix | Delete
return $open;
[3350] Fix | Delete
}
[3351] Fix | Delete
[3352] Fix | Delete
// Undated drafts should not show up as comments closed.
[3353] Fix | Delete
if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
[3354] Fix | Delete
return $open;
[3355] Fix | Delete
}
[3356] Fix | Delete
[3357] Fix | Delete
if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
[3358] Fix | Delete
return false;
[3359] Fix | Delete
}
[3360] Fix | Delete
[3361] Fix | Delete
return $open;
[3362] Fix | Delete
}
[3363] Fix | Delete
[3364] Fix | Delete
/**
[3365] Fix | Delete
* Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form.
[3366] Fix | Delete
*
[3367] Fix | Delete
* This function expects unslashed data, as opposed to functions such as `wp_new_comment()` which
[3368] Fix | Delete
* expect slashed data.
[3369] Fix | Delete
*
[3370] Fix | Delete
* @since 4.4.0
[3371] Fix | Delete
*
[3372] Fix | Delete
* @param array $comment_data {
[3373] Fix | Delete
* Comment data.
[3374] Fix | Delete
*
[3375] Fix | Delete
* @type string|int $comment_post_ID The ID of the post that relates to the comment.
[3376] Fix | Delete
* @type string $author The name of the comment author.
[3377] Fix | Delete
* @type string $email The comment author email address.
[3378] Fix | Delete
* @type string $url The comment author URL.
[3379] Fix | Delete
* @type string $comment The content of the comment.
[3380] Fix | Delete
* @type string|int $comment_parent The ID of this comment's parent, if any. Default 0.
[3381] Fix | Delete
* @type string $_wp_unfiltered_html_comment The nonce value for allowing unfiltered HTML.
[3382] Fix | Delete
* }
[3383] Fix | Delete
* @return WP_Comment|WP_Error A WP_Comment object on success, a WP_Error object on failure.
[3384] Fix | Delete
*/
[3385] Fix | Delete
function wp_handle_comment_submission( $comment_data ) {
[3386] Fix | Delete
[3387] Fix | Delete
$comment_post_ID = 0;
[3388] Fix | Delete
$comment_parent = 0;
[3389] Fix | Delete
$user_ID = 0;
[3390] Fix | Delete
$comment_author = null;
[3391] Fix | Delete
$comment_author_email = null;
[3392] Fix | Delete
$comment_author_url = null;
[3393] Fix | Delete
$comment_content = null;
[3394] Fix | Delete
[3395] Fix | Delete
if ( isset( $comment_data['comment_post_ID'] ) ) {
[3396] Fix | Delete
$comment_post_ID = (int) $comment_data['comment_post_ID'];
[3397] Fix | Delete
}
[3398] Fix | Delete
if ( isset( $comment_data['author'] ) && is_string( $comment_data['author'] ) ) {
[3399] Fix | Delete
$comment_author = trim( strip_tags( $comment_data['author'] ) );
[3400] Fix | Delete
}
[3401] Fix | Delete
if ( isset( $comment_data['email'] ) && is_string( $comment_data['email'] ) ) {
[3402] Fix | Delete
$comment_author_email = trim( $comment_data['email'] );
[3403] Fix | Delete
}
[3404] Fix | Delete
if ( isset( $comment_data['url'] ) && is_string( $comment_data['url'] ) ) {
[3405] Fix | Delete
$comment_author_url = trim( $comment_data['url'] );
[3406] Fix | Delete
}
[3407] Fix | Delete
if ( isset( $comment_data['comment'] ) && is_string( $comment_data['comment'] ) ) {
[3408] Fix | Delete
$comment_content = trim( $comment_data['comment'] );
[3409] Fix | Delete
}
[3410] Fix | Delete
if ( isset( $comment_data['comment_parent'] ) ) {
[3411] Fix | Delete
$comment_parent = absint( $comment_data['comment_parent'] );
[3412] Fix | Delete
}
[3413] Fix | Delete
[3414] Fix | Delete
$post = get_post( $comment_post_ID );
[3415] Fix | Delete
[3416] Fix | Delete
if ( empty( $post->comment_status ) ) {
[3417] Fix | Delete
[3418] Fix | Delete
/**
[3419] Fix | Delete
* Fires when a comment is attempted on a post that does not exist.
[3420] Fix | Delete
*
[3421] Fix | Delete
* @since 1.5.0
[3422] Fix | Delete
*
[3423] Fix | Delete
* @param int $comment_post_ID Post ID.
[3424] Fix | Delete
*/
[3425] Fix | Delete
do_action( 'comment_id_not_found', $comment_post_ID );
[3426] Fix | Delete
[3427] Fix | Delete
return new WP_Error( 'comment_id_not_found' );
[3428] Fix | Delete
[3429] Fix | Delete
}
[3430] Fix | Delete
[3431] Fix | Delete
// get_post_status() will get the parent status for attachments.
[3432] Fix | Delete
$status = get_post_status( $post );
[3433] Fix | Delete
[3434] Fix | Delete
if ( ( 'private' === $status ) && ! current_user_can( 'read_post', $comment_post_ID ) ) {
[3435] Fix | Delete
return new WP_Error( 'comment_id_not_found' );
[3436] Fix | Delete
}
[3437] Fix | Delete
[3438] Fix | Delete
$status_obj = get_post_status_object( $status );
[3439] Fix | Delete
[3440] Fix | Delete
if ( ! comments_open( $comment_post_ID ) ) {
[3441] Fix | Delete
[3442] Fix | Delete
/**
[3443] Fix | Delete
* Fires when a comment is attempted on a post that has comments closed.
[3444] Fix | Delete
*
[3445] Fix | Delete
* @since 1.5.0
[3446] Fix | Delete
*
[3447] Fix | Delete
* @param int $comment_post_ID Post ID.
[3448] Fix | Delete
*/
[3449] Fix | Delete
do_action( 'comment_closed', $comment_post_ID );
[3450] Fix | Delete
[3451] Fix | Delete
return new WP_Error( 'comment_closed', __( 'Sorry, comments are closed for this item.' ), 403 );
[3452] Fix | Delete
[3453] Fix | Delete
} elseif ( 'trash' === $status ) {
[3454] Fix | Delete
[3455] Fix | Delete
/**
[3456] Fix | Delete
* Fires when a comment is attempted on a trashed post.
[3457] Fix | Delete
*
[3458] Fix | Delete
* @since 2.9.0
[3459] Fix | Delete
*
[3460] Fix | Delete
* @param int $comment_post_ID Post ID.
[3461] Fix | Delete
*/
[3462] Fix | Delete
do_action( 'comment_on_trash', $comment_post_ID );
[3463] Fix | Delete
[3464] Fix | Delete
return new WP_Error( 'comment_on_trash' );
[3465] Fix | Delete
[3466] Fix | Delete
} elseif ( ! $status_obj->public && ! $status_obj->private ) {
[3467] Fix | Delete
[3468] Fix | Delete
/**
[3469] Fix | Delete
* Fires when a comment is attempted on a post in draft mode.
[3470] Fix | Delete
*
[3471] Fix | Delete
* @since 1.5.1
[3472] Fix | Delete
*
[3473] Fix | Delete
* @param int $comment_post_ID Post ID.
[3474] Fix | Delete
*/
[3475] Fix | Delete
do_action( 'comment_on_draft', $comment_post_ID );
[3476] Fix | Delete
[3477] Fix | Delete
if ( current_user_can( 'read_post', $comment_post_ID ) ) {
[3478] Fix | Delete
return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 );
[3479] Fix | Delete
} else {
[3480] Fix | Delete
return new WP_Error( 'comment_on_draft' );
[3481] Fix | Delete
}
[3482] Fix | Delete
} elseif ( post_password_required( $comment_post_ID ) ) {
[3483] Fix | Delete
[3484] Fix | Delete
/**
[3485] Fix | Delete
* Fires when a comment is attempted on a password-protected post.
[3486] Fix | Delete
*
[3487] Fix | Delete
* @since 2.9.0
[3488] Fix | Delete
*
[3489] Fix | Delete
* @param int $comment_post_ID Post ID.
[3490] Fix | Delete
*/
[3491] Fix | Delete
do_action( 'comment_on_password_protected', $comment_post_ID );
[3492] Fix | Delete
[3493] Fix | Delete
return new WP_Error( 'comment_on_password_protected' );
[3494] Fix | Delete
[3495] Fix | Delete
} else {
[3496] Fix | Delete
[3497] Fix | Delete
/**
[3498] Fix | Delete
* Fires before a comment is posted.
[3499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function