Edit File by line
/home/barbar84/www/wp-inclu...
File: comment.php
$comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt'];
[2000] Fix | Delete
[2001] Fix | Delete
$comment_post_ID = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID'];
[2002] Fix | Delete
$comment_content = ! isset( $data['comment_content'] ) ? '' : $data['comment_content'];
[2003] Fix | Delete
$comment_karma = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
[2004] Fix | Delete
$comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
[2005] Fix | Delete
$comment_agent = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
[2006] Fix | Delete
$comment_type = empty( $data['comment_type'] ) ? 'comment' : $data['comment_type'];
[2007] Fix | Delete
$comment_parent = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];
[2008] Fix | Delete
[2009] Fix | Delete
$user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
[2010] Fix | Delete
[2011] Fix | Delete
$compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' );
[2012] Fix | Delete
if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) {
[2013] Fix | Delete
return false;
[2014] Fix | Delete
}
[2015] Fix | Delete
[2016] Fix | Delete
$id = (int) $wpdb->insert_id;
[2017] Fix | Delete
[2018] Fix | Delete
if ( 1 == $comment_approved ) {
[2019] Fix | Delete
wp_update_comment_count( $comment_post_ID );
[2020] Fix | Delete
[2021] Fix | Delete
foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
[2022] Fix | Delete
wp_cache_delete( "lastcommentmodified:$timezone", 'timeinfo' );
[2023] Fix | Delete
}
[2024] Fix | Delete
}
[2025] Fix | Delete
[2026] Fix | Delete
clean_comment_cache( $id );
[2027] Fix | Delete
[2028] Fix | Delete
$comment = get_comment( $id );
[2029] Fix | Delete
[2030] Fix | Delete
// If metadata is provided, store it.
[2031] Fix | Delete
if ( isset( $commentdata['comment_meta'] ) && is_array( $commentdata['comment_meta'] ) ) {
[2032] Fix | Delete
foreach ( $commentdata['comment_meta'] as $meta_key => $meta_value ) {
[2033] Fix | Delete
add_comment_meta( $comment->comment_ID, $meta_key, $meta_value, true );
[2034] Fix | Delete
}
[2035] Fix | Delete
}
[2036] Fix | Delete
[2037] Fix | Delete
/**
[2038] Fix | Delete
* Fires immediately after a comment is inserted into the database.
[2039] Fix | Delete
*
[2040] Fix | Delete
* @since 2.8.0
[2041] Fix | Delete
*
[2042] Fix | Delete
* @param int $id The comment ID.
[2043] Fix | Delete
* @param WP_Comment $comment Comment object.
[2044] Fix | Delete
*/
[2045] Fix | Delete
do_action( 'wp_insert_comment', $id, $comment );
[2046] Fix | Delete
[2047] Fix | Delete
return $id;
[2048] Fix | Delete
}
[2049] Fix | Delete
[2050] Fix | Delete
/**
[2051] Fix | Delete
* Filters and sanitizes comment data.
[2052] Fix | Delete
*
[2053] Fix | Delete
* Sets the comment data 'filtered' field to true when finished. This can be
[2054] Fix | Delete
* checked as to whether the comment should be filtered and to keep from
[2055] Fix | Delete
* filtering the same comment more than once.
[2056] Fix | Delete
*
[2057] Fix | Delete
* @since 2.0.0
[2058] Fix | Delete
*
[2059] Fix | Delete
* @param array $commentdata Contains information on the comment.
[2060] Fix | Delete
* @return array Parsed comment information.
[2061] Fix | Delete
*/
[2062] Fix | Delete
function wp_filter_comment( $commentdata ) {
[2063] Fix | Delete
if ( isset( $commentdata['user_ID'] ) ) {
[2064] Fix | Delete
/**
[2065] Fix | Delete
* Filters the comment author's user ID before it is set.
[2066] Fix | Delete
*
[2067] Fix | Delete
* The first time this filter is evaluated, 'user_ID' is checked
[2068] Fix | Delete
* (for back-compat), followed by the standard 'user_id' value.
[2069] Fix | Delete
*
[2070] Fix | Delete
* @since 1.5.0
[2071] Fix | Delete
*
[2072] Fix | Delete
* @param int $user_ID The comment author's user ID.
[2073] Fix | Delete
*/
[2074] Fix | Delete
$commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] );
[2075] Fix | Delete
} elseif ( isset( $commentdata['user_id'] ) ) {
[2076] Fix | Delete
/** This filter is documented in wp-includes/comment.php */
[2077] Fix | Delete
$commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] );
[2078] Fix | Delete
}
[2079] Fix | Delete
[2080] Fix | Delete
/**
[2081] Fix | Delete
* Filters the comment author's browser user agent before it is set.
[2082] Fix | Delete
*
[2083] Fix | Delete
* @since 1.5.0
[2084] Fix | Delete
*
[2085] Fix | Delete
* @param string $comment_agent The comment author's browser user agent.
[2086] Fix | Delete
*/
[2087] Fix | Delete
$commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) );
[2088] Fix | Delete
/** This filter is documented in wp-includes/comment.php */
[2089] Fix | Delete
$commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] );
[2090] Fix | Delete
/**
[2091] Fix | Delete
* Filters the comment content before it is set.
[2092] Fix | Delete
*
[2093] Fix | Delete
* @since 1.5.0
[2094] Fix | Delete
*
[2095] Fix | Delete
* @param string $comment_content The comment content.
[2096] Fix | Delete
*/
[2097] Fix | Delete
$commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] );
[2098] Fix | Delete
/**
[2099] Fix | Delete
* Filters the comment author's IP address before it is set.
[2100] Fix | Delete
*
[2101] Fix | Delete
* @since 1.5.0
[2102] Fix | Delete
*
[2103] Fix | Delete
* @param string $comment_author_ip The comment author's IP address.
[2104] Fix | Delete
*/
[2105] Fix | Delete
$commentdata['comment_author_IP'] = apply_filters( 'pre_comment_user_ip', $commentdata['comment_author_IP'] );
[2106] Fix | Delete
/** This filter is documented in wp-includes/comment.php */
[2107] Fix | Delete
$commentdata['comment_author_url'] = apply_filters( 'pre_comment_author_url', $commentdata['comment_author_url'] );
[2108] Fix | Delete
/** This filter is documented in wp-includes/comment.php */
[2109] Fix | Delete
$commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] );
[2110] Fix | Delete
$commentdata['filtered'] = true;
[2111] Fix | Delete
return $commentdata;
[2112] Fix | Delete
}
[2113] Fix | Delete
[2114] Fix | Delete
/**
[2115] Fix | Delete
* Whether a comment should be blocked because of comment flood.
[2116] Fix | Delete
*
[2117] Fix | Delete
* @since 2.1.0
[2118] Fix | Delete
*
[2119] Fix | Delete
* @param bool $block Whether plugin has already blocked comment.
[2120] Fix | Delete
* @param int $time_lastcomment Timestamp for last comment.
[2121] Fix | Delete
* @param int $time_newcomment Timestamp for new comment.
[2122] Fix | Delete
* @return bool Whether comment should be blocked.
[2123] Fix | Delete
*/
[2124] Fix | Delete
function wp_throttle_comment_flood( $block, $time_lastcomment, $time_newcomment ) {
[2125] Fix | Delete
if ( $block ) { // A plugin has already blocked... we'll let that decision stand.
[2126] Fix | Delete
return $block;
[2127] Fix | Delete
}
[2128] Fix | Delete
if ( ( $time_newcomment - $time_lastcomment ) < 15 ) {
[2129] Fix | Delete
return true;
[2130] Fix | Delete
}
[2131] Fix | Delete
return false;
[2132] Fix | Delete
}
[2133] Fix | Delete
[2134] Fix | Delete
/**
[2135] Fix | Delete
* Adds a new comment to the database.
[2136] Fix | Delete
*
[2137] Fix | Delete
* Filters new comment to ensure that the fields are sanitized and valid before
[2138] Fix | Delete
* inserting comment into database. Calls {@see 'comment_post'} action with comment ID
[2139] Fix | Delete
* and whether comment is approved by WordPress. Also has {@see 'preprocess_comment'}
[2140] Fix | Delete
* filter for processing the comment data before the function handles it.
[2141] Fix | Delete
*
[2142] Fix | Delete
* We use `REMOTE_ADDR` here directly. If you are behind a proxy, you should ensure
[2143] Fix | Delete
* that it is properly set, such as in wp-config.php, for your environment.
[2144] Fix | Delete
*
[2145] Fix | Delete
* See {@link https://core.trac.wordpress.org/ticket/9235}
[2146] Fix | Delete
*
[2147] Fix | Delete
* @since 1.5.0
[2148] Fix | Delete
* @since 4.3.0 Introduced the `comment_agent` and `comment_author_IP` arguments.
[2149] Fix | Delete
* @since 4.7.0 The `$avoid_die` parameter was added, allowing the function
[2150] Fix | Delete
* to return a WP_Error object instead of dying.
[2151] Fix | Delete
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
[2152] Fix | Delete
* @since 5.5.0 Introduced the `comment_type` argument.
[2153] Fix | Delete
*
[2154] Fix | Delete
* @see wp_insert_comment()
[2155] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[2156] Fix | Delete
*
[2157] Fix | Delete
* @param array $commentdata {
[2158] Fix | Delete
* Comment data.
[2159] Fix | Delete
*
[2160] Fix | Delete
* @type string $comment_author The name of the comment author.
[2161] Fix | Delete
* @type string $comment_author_email The comment author email address.
[2162] Fix | Delete
* @type string $comment_author_url The comment author URL.
[2163] Fix | Delete
* @type string $comment_content The content of the comment.
[2164] Fix | Delete
* @type string $comment_date The date the comment was submitted. Default is the current time.
[2165] Fix | Delete
* @type string $comment_date_gmt The date the comment was submitted in the GMT timezone.
[2166] Fix | Delete
* Default is `$comment_date` in the GMT timezone.
[2167] Fix | Delete
* @type string $comment_type Comment type. Default 'comment'.
[2168] Fix | Delete
* @type int $comment_parent The ID of this comment's parent, if any. Default 0.
[2169] Fix | Delete
* @type int $comment_post_ID The ID of the post that relates to the comment.
[2170] Fix | Delete
* @type int $user_id The ID of the user who submitted the comment. Default 0.
[2171] Fix | Delete
* @type int $user_ID Kept for backward-compatibility. Use `$user_id` instead.
[2172] Fix | Delete
* @type string $comment_agent Comment author user agent. Default is the value of 'HTTP_USER_AGENT'
[2173] Fix | Delete
* in the `$_SERVER` superglobal sent in the original request.
[2174] Fix | Delete
* @type string $comment_author_IP Comment author IP address in IPv4 format. Default is the value of
[2175] Fix | Delete
* 'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request.
[2176] Fix | Delete
* }
[2177] Fix | Delete
* @param bool $wp_error Should errors be returned as WP_Error objects instead of
[2178] Fix | Delete
* executing wp_die()? Default false.
[2179] Fix | Delete
* @return int|false|WP_Error The ID of the comment on success, false or WP_Error on failure.
[2180] Fix | Delete
*/
[2181] Fix | Delete
function wp_new_comment( $commentdata, $wp_error = false ) {
[2182] Fix | Delete
global $wpdb;
[2183] Fix | Delete
[2184] Fix | Delete
if ( isset( $commentdata['user_ID'] ) ) {
[2185] Fix | Delete
$commentdata['user_ID'] = (int) $commentdata['user_ID'];
[2186] Fix | Delete
$commentdata['user_id'] = $commentdata['user_ID'];
[2187] Fix | Delete
}
[2188] Fix | Delete
[2189] Fix | Delete
$prefiltered_user_id = ( isset( $commentdata['user_id'] ) ) ? (int) $commentdata['user_id'] : 0;
[2190] Fix | Delete
[2191] Fix | Delete
if ( ! isset( $commentdata['comment_author_IP'] ) ) {
[2192] Fix | Delete
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
[2193] Fix | Delete
}
[2194] Fix | Delete
[2195] Fix | Delete
if ( ! isset( $commentdata['comment_agent'] ) ) {
[2196] Fix | Delete
$commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
[2197] Fix | Delete
}
[2198] Fix | Delete
[2199] Fix | Delete
/**
[2200] Fix | Delete
* Filters a comment's data before it is sanitized and inserted into the database.
[2201] Fix | Delete
*
[2202] Fix | Delete
* @since 1.5.0
[2203] Fix | Delete
* @since 5.6.0 Comment data includes the `comment_agent` and `comment_author_IP` values.
[2204] Fix | Delete
*
[2205] Fix | Delete
* @param array $commentdata Comment data.
[2206] Fix | Delete
*/
[2207] Fix | Delete
$commentdata = apply_filters( 'preprocess_comment', $commentdata );
[2208] Fix | Delete
[2209] Fix | Delete
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
[2210] Fix | Delete
if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) {
[2211] Fix | Delete
$commentdata['user_ID'] = (int) $commentdata['user_ID'];
[2212] Fix | Delete
$commentdata['user_id'] = $commentdata['user_ID'];
[2213] Fix | Delete
} elseif ( isset( $commentdata['user_id'] ) ) {
[2214] Fix | Delete
$commentdata['user_id'] = (int) $commentdata['user_id'];
[2215] Fix | Delete
}
[2216] Fix | Delete
[2217] Fix | Delete
$commentdata['comment_parent'] = isset( $commentdata['comment_parent'] ) ? absint( $commentdata['comment_parent'] ) : 0;
[2218] Fix | Delete
[2219] Fix | Delete
$parent_status = ( $commentdata['comment_parent'] > 0 ) ? wp_get_comment_status( $commentdata['comment_parent'] ) : '';
[2220] Fix | Delete
[2221] Fix | Delete
$commentdata['comment_parent'] = ( 'approved' === $parent_status || 'unapproved' === $parent_status ) ? $commentdata['comment_parent'] : 0;
[2222] Fix | Delete
[2223] Fix | Delete
$commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP'] );
[2224] Fix | Delete
[2225] Fix | Delete
$commentdata['comment_agent'] = substr( $commentdata['comment_agent'], 0, 254 );
[2226] Fix | Delete
[2227] Fix | Delete
if ( empty( $commentdata['comment_date'] ) ) {
[2228] Fix | Delete
$commentdata['comment_date'] = current_time( 'mysql' );
[2229] Fix | Delete
}
[2230] Fix | Delete
[2231] Fix | Delete
if ( empty( $commentdata['comment_date_gmt'] ) ) {
[2232] Fix | Delete
$commentdata['comment_date_gmt'] = current_time( 'mysql', 1 );
[2233] Fix | Delete
}
[2234] Fix | Delete
[2235] Fix | Delete
if ( empty( $commentdata['comment_type'] ) ) {
[2236] Fix | Delete
$commentdata['comment_type'] = 'comment';
[2237] Fix | Delete
}
[2238] Fix | Delete
[2239] Fix | Delete
$commentdata = wp_filter_comment( $commentdata );
[2240] Fix | Delete
[2241] Fix | Delete
$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
[2242] Fix | Delete
if ( is_wp_error( $commentdata['comment_approved'] ) ) {
[2243] Fix | Delete
return $commentdata['comment_approved'];
[2244] Fix | Delete
}
[2245] Fix | Delete
[2246] Fix | Delete
$comment_ID = wp_insert_comment( $commentdata );
[2247] Fix | Delete
if ( ! $comment_ID ) {
[2248] Fix | Delete
$fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' );
[2249] Fix | Delete
[2250] Fix | Delete
foreach ( $fields as $field ) {
[2251] Fix | Delete
if ( isset( $commentdata[ $field ] ) ) {
[2252] Fix | Delete
$commentdata[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, $field, $commentdata[ $field ] );
[2253] Fix | Delete
}
[2254] Fix | Delete
}
[2255] Fix | Delete
[2256] Fix | Delete
$commentdata = wp_filter_comment( $commentdata );
[2257] Fix | Delete
[2258] Fix | Delete
$commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
[2259] Fix | Delete
if ( is_wp_error( $commentdata['comment_approved'] ) ) {
[2260] Fix | Delete
return $commentdata['comment_approved'];
[2261] Fix | Delete
}
[2262] Fix | Delete
[2263] Fix | Delete
$comment_ID = wp_insert_comment( $commentdata );
[2264] Fix | Delete
if ( ! $comment_ID ) {
[2265] Fix | Delete
return false;
[2266] Fix | Delete
}
[2267] Fix | Delete
}
[2268] Fix | Delete
[2269] Fix | Delete
/**
[2270] Fix | Delete
* Fires immediately after a comment is inserted into the database.
[2271] Fix | Delete
*
[2272] Fix | Delete
* @since 1.2.0
[2273] Fix | Delete
* @since 4.5.0 The `$commentdata` parameter was added.
[2274] Fix | Delete
*
[2275] Fix | Delete
* @param int $comment_ID The comment ID.
[2276] Fix | Delete
* @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
[2277] Fix | Delete
* @param array $commentdata Comment data.
[2278] Fix | Delete
*/
[2279] Fix | Delete
do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'], $commentdata );
[2280] Fix | Delete
[2281] Fix | Delete
return $comment_ID;
[2282] Fix | Delete
}
[2283] Fix | Delete
[2284] Fix | Delete
/**
[2285] Fix | Delete
* Send a comment moderation notification to the comment moderator.
[2286] Fix | Delete
*
[2287] Fix | Delete
* @since 4.4.0
[2288] Fix | Delete
*
[2289] Fix | Delete
* @param int $comment_ID ID of the comment.
[2290] Fix | Delete
* @return bool True on success, false on failure.
[2291] Fix | Delete
*/
[2292] Fix | Delete
function wp_new_comment_notify_moderator( $comment_ID ) {
[2293] Fix | Delete
$comment = get_comment( $comment_ID );
[2294] Fix | Delete
[2295] Fix | Delete
// Only send notifications for pending comments.
[2296] Fix | Delete
$maybe_notify = ( '0' == $comment->comment_approved );
[2297] Fix | Delete
[2298] Fix | Delete
/** This filter is documented in wp-includes/comment.php */
[2299] Fix | Delete
$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_ID );
[2300] Fix | Delete
[2301] Fix | Delete
if ( ! $maybe_notify ) {
[2302] Fix | Delete
return false;
[2303] Fix | Delete
}
[2304] Fix | Delete
[2305] Fix | Delete
return wp_notify_moderator( $comment_ID );
[2306] Fix | Delete
}
[2307] Fix | Delete
[2308] Fix | Delete
/**
[2309] Fix | Delete
* Send a notification of a new comment to the post author.
[2310] Fix | Delete
*
[2311] Fix | Delete
* @since 4.4.0
[2312] Fix | Delete
*
[2313] Fix | Delete
* Uses the {@see 'notify_post_author'} filter to determine whether the post author
[2314] Fix | Delete
* should be notified when a new comment is added, overriding site setting.
[2315] Fix | Delete
*
[2316] Fix | Delete
* @param int $comment_ID Comment ID.
[2317] Fix | Delete
* @return bool True on success, false on failure.
[2318] Fix | Delete
*/
[2319] Fix | Delete
function wp_new_comment_notify_postauthor( $comment_ID ) {
[2320] Fix | Delete
$comment = get_comment( $comment_ID );
[2321] Fix | Delete
[2322] Fix | Delete
$maybe_notify = get_option( 'comments_notify' );
[2323] Fix | Delete
[2324] Fix | Delete
/**
[2325] Fix | Delete
* Filters whether to send the post author new comment notification emails,
[2326] Fix | Delete
* overriding the site setting.
[2327] Fix | Delete
*
[2328] Fix | Delete
* @since 4.4.0
[2329] Fix | Delete
*
[2330] Fix | Delete
* @param bool $maybe_notify Whether to notify the post author about the new comment.
[2331] Fix | Delete
* @param int $comment_ID The ID of the comment for the notification.
[2332] Fix | Delete
*/
[2333] Fix | Delete
$maybe_notify = apply_filters( 'notify_post_author', $maybe_notify, $comment_ID );
[2334] Fix | Delete
[2335] Fix | Delete
/*
[2336] Fix | Delete
* wp_notify_postauthor() checks if notifying the author of their own comment.
[2337] Fix | Delete
* By default, it won't, but filters can override this.
[2338] Fix | Delete
*/
[2339] Fix | Delete
if ( ! $maybe_notify ) {
[2340] Fix | Delete
return false;
[2341] Fix | Delete
}
[2342] Fix | Delete
[2343] Fix | Delete
// Only send notifications for approved comments.
[2344] Fix | Delete
if ( ! isset( $comment->comment_approved ) || '1' != $comment->comment_approved ) {
[2345] Fix | Delete
return false;
[2346] Fix | Delete
}
[2347] Fix | Delete
[2348] Fix | Delete
return wp_notify_postauthor( $comment_ID );
[2349] Fix | Delete
}
[2350] Fix | Delete
[2351] Fix | Delete
/**
[2352] Fix | Delete
* Sets the status of a comment.
[2353] Fix | Delete
*
[2354] Fix | Delete
* The {@see 'wp_set_comment_status'} action is called after the comment is handled.
[2355] Fix | Delete
* If the comment status is not in the list, then false is returned.
[2356] Fix | Delete
*
[2357] Fix | Delete
* @since 1.0.0
[2358] Fix | Delete
*
[2359] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[2360] Fix | Delete
*
[2361] Fix | Delete
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
[2362] Fix | Delete
* @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'.
[2363] Fix | Delete
* @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default false.
[2364] Fix | Delete
* @return bool|WP_Error True on success, false or WP_Error on failure.
[2365] Fix | Delete
*/
[2366] Fix | Delete
function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false ) {
[2367] Fix | Delete
global $wpdb;
[2368] Fix | Delete
[2369] Fix | Delete
switch ( $comment_status ) {
[2370] Fix | Delete
case 'hold':
[2371] Fix | Delete
case '0':
[2372] Fix | Delete
$status = '0';
[2373] Fix | Delete
break;
[2374] Fix | Delete
case 'approve':
[2375] Fix | Delete
case '1':
[2376] Fix | Delete
$status = '1';
[2377] Fix | Delete
add_action( 'wp_set_comment_status', 'wp_new_comment_notify_postauthor' );
[2378] Fix | Delete
break;
[2379] Fix | Delete
case 'spam':
[2380] Fix | Delete
$status = 'spam';
[2381] Fix | Delete
break;
[2382] Fix | Delete
case 'trash':
[2383] Fix | Delete
$status = 'trash';
[2384] Fix | Delete
break;
[2385] Fix | Delete
default:
[2386] Fix | Delete
return false;
[2387] Fix | Delete
}
[2388] Fix | Delete
[2389] Fix | Delete
$comment_old = clone get_comment( $comment_id );
[2390] Fix | Delete
[2391] Fix | Delete
if ( ! $wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $comment_old->comment_ID ) ) ) {
[2392] Fix | Delete
if ( $wp_error ) {
[2393] Fix | Delete
return new WP_Error( 'db_update_error', __( 'Could not update comment status.' ), $wpdb->last_error );
[2394] Fix | Delete
} else {
[2395] Fix | Delete
return false;
[2396] Fix | Delete
}
[2397] Fix | Delete
}
[2398] Fix | Delete
[2399] Fix | Delete
clean_comment_cache( $comment_old->comment_ID );
[2400] Fix | Delete
[2401] Fix | Delete
$comment = get_comment( $comment_old->comment_ID );
[2402] Fix | Delete
[2403] Fix | Delete
/**
[2404] Fix | Delete
* Fires immediately after transitioning a comment's status from one to another in the database
[2405] Fix | Delete
* and removing the comment from the object cache, but prior to all status transition hooks.
[2406] Fix | Delete
*
[2407] Fix | Delete
* @since 1.5.0
[2408] Fix | Delete
*
[2409] Fix | Delete
* @param int $comment_id Comment ID.
[2410] Fix | Delete
* @param string $comment_status Current comment status. Possible values include
[2411] Fix | Delete
* 'hold', '0', 'approve', '1', 'spam', and 'trash'.
[2412] Fix | Delete
*/
[2413] Fix | Delete
do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status );
[2414] Fix | Delete
[2415] Fix | Delete
wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment );
[2416] Fix | Delete
[2417] Fix | Delete
wp_update_comment_count( $comment->comment_post_ID );
[2418] Fix | Delete
[2419] Fix | Delete
return true;
[2420] Fix | Delete
}
[2421] Fix | Delete
[2422] Fix | Delete
/**
[2423] Fix | Delete
* Updates an existing comment in the database.
[2424] Fix | Delete
*
[2425] Fix | Delete
* Filters the comment and makes sure certain fields are valid before updating.
[2426] Fix | Delete
*
[2427] Fix | Delete
* @since 2.0.0
[2428] Fix | Delete
* @since 4.9.0 Add updating comment meta during comment update.
[2429] Fix | Delete
* @since 5.5.0 The `$wp_error` parameter was added.
[2430] Fix | Delete
* @since 5.5.0 The return values for an invalid comment or post ID
[2431] Fix | Delete
* were changed to false instead of 0.
[2432] Fix | Delete
*
[2433] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[2434] Fix | Delete
*
[2435] Fix | Delete
* @param array $commentarr Contains information on the comment.
[2436] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
[2437] Fix | Delete
* @return int|false|WP_Error The value 1 if the comment was updated, 0 if not updated.
[2438] Fix | Delete
* False or a WP_Error object on failure.
[2439] Fix | Delete
*/
[2440] Fix | Delete
function wp_update_comment( $commentarr, $wp_error = false ) {
[2441] Fix | Delete
global $wpdb;
[2442] Fix | Delete
[2443] Fix | Delete
// First, get all of the original fields.
[2444] Fix | Delete
$comment = get_comment( $commentarr['comment_ID'], ARRAY_A );
[2445] Fix | Delete
if ( empty( $comment ) ) {
[2446] Fix | Delete
if ( $wp_error ) {
[2447] Fix | Delete
return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) );
[2448] Fix | Delete
} else {
[2449] Fix | Delete
return false;
[2450] Fix | Delete
}
[2451] Fix | Delete
}
[2452] Fix | Delete
[2453] Fix | Delete
// Make sure that the comment post ID is valid (if specified).
[2454] Fix | Delete
if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
[2455] Fix | Delete
if ( $wp_error ) {
[2456] Fix | Delete
return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) );
[2457] Fix | Delete
} else {
[2458] Fix | Delete
return false;
[2459] Fix | Delete
}
[2460] Fix | Delete
}
[2461] Fix | Delete
[2462] Fix | Delete
$filter_comment = false;
[2463] Fix | Delete
if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
[2464] Fix | Delete
$filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
[2465] Fix | Delete
}
[2466] Fix | Delete
[2467] Fix | Delete
if ( $filter_comment ) {
[2468] Fix | Delete
add_filter( 'pre_comment_content', 'wp_filter_kses' );
[2469] Fix | Delete
}
[2470] Fix | Delete
[2471] Fix | Delete
// Escape data pulled from DB.
[2472] Fix | Delete
$comment = wp_slash( $comment );
[2473] Fix | Delete
[2474] Fix | Delete
$old_status = $comment['comment_approved'];
[2475] Fix | Delete
[2476] Fix | Delete
// Merge old and new fields with new fields overwriting old ones.
[2477] Fix | Delete
$commentarr = array_merge( $comment, $commentarr );
[2478] Fix | Delete
[2479] Fix | Delete
$commentarr = wp_filter_comment( $commentarr );
[2480] Fix | Delete
[2481] Fix | Delete
if ( $filter_comment ) {
[2482] Fix | Delete
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
[2483] Fix | Delete
}
[2484] Fix | Delete
[2485] Fix | Delete
// Now extract the merged array.
[2486] Fix | Delete
$data = wp_unslash( $commentarr );
[2487] Fix | Delete
[2488] Fix | Delete
/**
[2489] Fix | Delete
* Filters the comment content before it is updated in the database.
[2490] Fix | Delete
*
[2491] Fix | Delete
* @since 1.5.0
[2492] Fix | Delete
*
[2493] Fix | Delete
* @param string $comment_content The comment data.
[2494] Fix | Delete
*/
[2495] Fix | Delete
$data['comment_content'] = apply_filters( 'comment_save_pre', $data['comment_content'] );
[2496] Fix | Delete
[2497] Fix | Delete
$data['comment_date_gmt'] = get_gmt_from_date( $data['comment_date'] );
[2498] Fix | Delete
[2499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function