Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../public_h.../wp-inclu...
File: comment.php
[1000] Fix | Delete
if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) {
[1001] Fix | Delete
$comments = $wp_query->comments;
[1002] Fix | Delete
}
[1003] Fix | Delete
[1004] Fix | Delete
if ( empty( $comments ) ) {
[1005] Fix | Delete
return 0;
[1006] Fix | Delete
}
[1007] Fix | Delete
[1008] Fix | Delete
if ( ! get_option( 'page_comments' ) ) {
[1009] Fix | Delete
return 1;
[1010] Fix | Delete
}
[1011] Fix | Delete
[1012] Fix | Delete
if ( ! isset( $per_page ) ) {
[1013] Fix | Delete
$per_page = (int) get_query_var( 'comments_per_page' );
[1014] Fix | Delete
}
[1015] Fix | Delete
if ( 0 === $per_page ) {
[1016] Fix | Delete
$per_page = (int) get_option( 'comments_per_page' );
[1017] Fix | Delete
}
[1018] Fix | Delete
if ( 0 === $per_page ) {
[1019] Fix | Delete
return 1;
[1020] Fix | Delete
}
[1021] Fix | Delete
[1022] Fix | Delete
if ( ! isset( $threaded ) ) {
[1023] Fix | Delete
$threaded = get_option( 'thread_comments' );
[1024] Fix | Delete
}
[1025] Fix | Delete
[1026] Fix | Delete
if ( $threaded ) {
[1027] Fix | Delete
$walker = new Walker_Comment();
[1028] Fix | Delete
$count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );
[1029] Fix | Delete
} else {
[1030] Fix | Delete
$count = ceil( count( $comments ) / $per_page );
[1031] Fix | Delete
}
[1032] Fix | Delete
[1033] Fix | Delete
return (int) $count;
[1034] Fix | Delete
}
[1035] Fix | Delete
[1036] Fix | Delete
/**
[1037] Fix | Delete
* Calculates what page number a comment will appear on for comment paging.
[1038] Fix | Delete
*
[1039] Fix | Delete
* @since 2.7.0
[1040] Fix | Delete
*
[1041] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1042] Fix | Delete
*
[1043] Fix | Delete
* @param int $comment_id Comment ID.
[1044] Fix | Delete
* @param array $args {
[1045] Fix | Delete
* Array of optional arguments.
[1046] Fix | Delete
*
[1047] Fix | Delete
* @type string $type Limit paginated comments to those matching a given type.
[1048] Fix | Delete
* Accepts 'comment', 'trackback', 'pingback', 'pings'
[1049] Fix | Delete
* (trackbacks and pingbacks), or 'all'. Default 'all'.
[1050] Fix | Delete
* @type int $per_page Per-page count to use when calculating pagination.
[1051] Fix | Delete
* Defaults to the value of the 'comments_per_page' option.
[1052] Fix | Delete
* @type int|string $max_depth If greater than 1, comment page will be determined
[1053] Fix | Delete
* for the top-level parent `$comment_id`.
[1054] Fix | Delete
* Defaults to the value of the 'thread_comments_depth' option.
[1055] Fix | Delete
* }
[1056] Fix | Delete
* @return int|null Comment page number or null on error.
[1057] Fix | Delete
*/
[1058] Fix | Delete
function get_page_of_comment( $comment_id, $args = array() ) {
[1059] Fix | Delete
global $wpdb;
[1060] Fix | Delete
[1061] Fix | Delete
$page = null;
[1062] Fix | Delete
[1063] Fix | Delete
$comment = get_comment( $comment_id );
[1064] Fix | Delete
if ( ! $comment ) {
[1065] Fix | Delete
return;
[1066] Fix | Delete
}
[1067] Fix | Delete
[1068] Fix | Delete
$defaults = array(
[1069] Fix | Delete
'type' => 'all',
[1070] Fix | Delete
'page' => '',
[1071] Fix | Delete
'per_page' => '',
[1072] Fix | Delete
'max_depth' => '',
[1073] Fix | Delete
);
[1074] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[1075] Fix | Delete
$original_args = $args;
[1076] Fix | Delete
[1077] Fix | Delete
// Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
[1078] Fix | Delete
if ( get_option( 'page_comments' ) ) {
[1079] Fix | Delete
if ( '' === $args['per_page'] ) {
[1080] Fix | Delete
$args['per_page'] = get_query_var( 'comments_per_page' );
[1081] Fix | Delete
}
[1082] Fix | Delete
[1083] Fix | Delete
if ( '' === $args['per_page'] ) {
[1084] Fix | Delete
$args['per_page'] = get_option( 'comments_per_page' );
[1085] Fix | Delete
}
[1086] Fix | Delete
}
[1087] Fix | Delete
[1088] Fix | Delete
if ( empty( $args['per_page'] ) ) {
[1089] Fix | Delete
$args['per_page'] = 0;
[1090] Fix | Delete
$args['page'] = 0;
[1091] Fix | Delete
}
[1092] Fix | Delete
[1093] Fix | Delete
if ( $args['per_page'] < 1 ) {
[1094] Fix | Delete
$page = 1;
[1095] Fix | Delete
}
[1096] Fix | Delete
[1097] Fix | Delete
if ( null === $page ) {
[1098] Fix | Delete
if ( '' === $args['max_depth'] ) {
[1099] Fix | Delete
if ( get_option( 'thread_comments' ) ) {
[1100] Fix | Delete
$args['max_depth'] = get_option( 'thread_comments_depth' );
[1101] Fix | Delete
} else {
[1102] Fix | Delete
$args['max_depth'] = -1;
[1103] Fix | Delete
}
[1104] Fix | Delete
}
[1105] Fix | Delete
[1106] Fix | Delete
// Find this comment's top-level parent if threading is enabled.
[1107] Fix | Delete
if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent ) {
[1108] Fix | Delete
return get_page_of_comment( $comment->comment_parent, $args );
[1109] Fix | Delete
}
[1110] Fix | Delete
[1111] Fix | Delete
$comment_args = array(
[1112] Fix | Delete
'type' => $args['type'],
[1113] Fix | Delete
'post_id' => $comment->comment_post_ID,
[1114] Fix | Delete
'fields' => 'ids',
[1115] Fix | Delete
'count' => true,
[1116] Fix | Delete
'status' => 'approve',
[1117] Fix | Delete
'orderby' => 'none',
[1118] Fix | Delete
'parent' => 0,
[1119] Fix | Delete
'date_query' => array(
[1120] Fix | Delete
array(
[1121] Fix | Delete
'column' => "$wpdb->comments.comment_date_gmt",
[1122] Fix | Delete
'before' => $comment->comment_date_gmt,
[1123] Fix | Delete
),
[1124] Fix | Delete
),
[1125] Fix | Delete
);
[1126] Fix | Delete
[1127] Fix | Delete
if ( is_user_logged_in() ) {
[1128] Fix | Delete
$comment_args['include_unapproved'] = array( get_current_user_id() );
[1129] Fix | Delete
} else {
[1130] Fix | Delete
$unapproved_email = wp_get_unapproved_comment_author_email();
[1131] Fix | Delete
[1132] Fix | Delete
if ( $unapproved_email ) {
[1133] Fix | Delete
$comment_args['include_unapproved'] = array( $unapproved_email );
[1134] Fix | Delete
}
[1135] Fix | Delete
}
[1136] Fix | Delete
[1137] Fix | Delete
/**
[1138] Fix | Delete
* Filters the arguments used to query comments in get_page_of_comment().
[1139] Fix | Delete
*
[1140] Fix | Delete
* @since 5.5.0
[1141] Fix | Delete
*
[1142] Fix | Delete
* @see WP_Comment_Query::__construct()
[1143] Fix | Delete
*
[1144] Fix | Delete
* @param array $comment_args {
[1145] Fix | Delete
* Array of WP_Comment_Query arguments.
[1146] Fix | Delete
*
[1147] Fix | Delete
* @type string $type Limit paginated comments to those matching a given type.
[1148] Fix | Delete
* Accepts 'comment', 'trackback', 'pingback', 'pings'
[1149] Fix | Delete
* (trackbacks and pingbacks), or 'all'. Default 'all'.
[1150] Fix | Delete
* @type int $post_id ID of the post.
[1151] Fix | Delete
* @type string $fields Comment fields to return.
[1152] Fix | Delete
* @type bool $count Whether to return a comment count (true) or array
[1153] Fix | Delete
* of comment objects (false).
[1154] Fix | Delete
* @type string $status Comment status.
[1155] Fix | Delete
* @type int $parent Parent ID of comment to retrieve children of.
[1156] Fix | Delete
* @type array $date_query Date query clauses to limit comments by. See WP_Date_Query.
[1157] Fix | Delete
* @type array $include_unapproved Array of IDs or email addresses whose unapproved comments
[1158] Fix | Delete
* will be included in paginated comments.
[1159] Fix | Delete
* }
[1160] Fix | Delete
*/
[1161] Fix | Delete
$comment_args = apply_filters( 'get_page_of_comment_query_args', $comment_args );
[1162] Fix | Delete
[1163] Fix | Delete
$comment_query = new WP_Comment_Query();
[1164] Fix | Delete
$older_comment_count = $comment_query->query( $comment_args );
[1165] Fix | Delete
[1166] Fix | Delete
// No older comments? Then it's page #1.
[1167] Fix | Delete
if ( 0 == $older_comment_count ) {
[1168] Fix | Delete
$page = 1;
[1169] Fix | Delete
[1170] Fix | Delete
// Divide comments older than this one by comments per page to get this comment's page number.
[1171] Fix | Delete
} else {
[1172] Fix | Delete
$page = (int) ceil( ( $older_comment_count + 1 ) / $args['per_page'] );
[1173] Fix | Delete
}
[1174] Fix | Delete
}
[1175] Fix | Delete
[1176] Fix | Delete
/**
[1177] Fix | Delete
* Filters the calculated page on which a comment appears.
[1178] Fix | Delete
*
[1179] Fix | Delete
* @since 4.4.0
[1180] Fix | Delete
* @since 4.7.0 Introduced the `$comment_id` parameter.
[1181] Fix | Delete
*
[1182] Fix | Delete
* @param int $page Comment page.
[1183] Fix | Delete
* @param array $args {
[1184] Fix | Delete
* Arguments used to calculate pagination. These include arguments auto-detected by the function,
[1185] Fix | Delete
* based on query vars, system settings, etc. For pristine arguments passed to the function,
[1186] Fix | Delete
* see `$original_args`.
[1187] Fix | Delete
*
[1188] Fix | Delete
* @type string $type Type of comments to count.
[1189] Fix | Delete
* @type int $page Calculated current page.
[1190] Fix | Delete
* @type int $per_page Calculated number of comments per page.
[1191] Fix | Delete
* @type int $max_depth Maximum comment threading depth allowed.
[1192] Fix | Delete
* }
[1193] Fix | Delete
* @param array $original_args {
[1194] Fix | Delete
* Array of arguments passed to the function. Some or all of these may not be set.
[1195] Fix | Delete
*
[1196] Fix | Delete
* @type string $type Type of comments to count.
[1197] Fix | Delete
* @type int $page Current comment page.
[1198] Fix | Delete
* @type int $per_page Number of comments per page.
[1199] Fix | Delete
* @type int $max_depth Maximum comment threading depth allowed.
[1200] Fix | Delete
* }
[1201] Fix | Delete
* @param int $comment_id ID of the comment.
[1202] Fix | Delete
*/
[1203] Fix | Delete
return apply_filters( 'get_page_of_comment', (int) $page, $args, $original_args, $comment_id );
[1204] Fix | Delete
}
[1205] Fix | Delete
[1206] Fix | Delete
/**
[1207] Fix | Delete
* Retrieves the maximum character lengths for the comment form fields.
[1208] Fix | Delete
*
[1209] Fix | Delete
* @since 4.5.0
[1210] Fix | Delete
*
[1211] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1212] Fix | Delete
*
[1213] Fix | Delete
* @return int[] Array of maximum lengths keyed by field name.
[1214] Fix | Delete
*/
[1215] Fix | Delete
function wp_get_comment_fields_max_lengths() {
[1216] Fix | Delete
global $wpdb;
[1217] Fix | Delete
[1218] Fix | Delete
$lengths = array(
[1219] Fix | Delete
'comment_author' => 245,
[1220] Fix | Delete
'comment_author_email' => 100,
[1221] Fix | Delete
'comment_author_url' => 200,
[1222] Fix | Delete
'comment_content' => 65525,
[1223] Fix | Delete
);
[1224] Fix | Delete
[1225] Fix | Delete
if ( $wpdb->is_mysql ) {
[1226] Fix | Delete
foreach ( $lengths as $column => $length ) {
[1227] Fix | Delete
$col_length = $wpdb->get_col_length( $wpdb->comments, $column );
[1228] Fix | Delete
$max_length = 0;
[1229] Fix | Delete
[1230] Fix | Delete
// No point if we can't get the DB column lengths.
[1231] Fix | Delete
if ( is_wp_error( $col_length ) ) {
[1232] Fix | Delete
break;
[1233] Fix | Delete
}
[1234] Fix | Delete
[1235] Fix | Delete
if ( ! is_array( $col_length ) && (int) $col_length > 0 ) {
[1236] Fix | Delete
$max_length = (int) $col_length;
[1237] Fix | Delete
} elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && (int) $col_length['length'] > 0 ) {
[1238] Fix | Delete
$max_length = (int) $col_length['length'];
[1239] Fix | Delete
[1240] Fix | Delete
if ( ! empty( $col_length['type'] ) && 'byte' === $col_length['type'] ) {
[1241] Fix | Delete
$max_length = $max_length - 10;
[1242] Fix | Delete
}
[1243] Fix | Delete
}
[1244] Fix | Delete
[1245] Fix | Delete
if ( $max_length > 0 ) {
[1246] Fix | Delete
$lengths[ $column ] = $max_length;
[1247] Fix | Delete
}
[1248] Fix | Delete
}
[1249] Fix | Delete
}
[1250] Fix | Delete
[1251] Fix | Delete
/**
[1252] Fix | Delete
* Filters the lengths for the comment form fields.
[1253] Fix | Delete
*
[1254] Fix | Delete
* @since 4.5.0
[1255] Fix | Delete
*
[1256] Fix | Delete
* @param int[] $lengths Array of maximum lengths keyed by field name.
[1257] Fix | Delete
*/
[1258] Fix | Delete
return apply_filters( 'wp_get_comment_fields_max_lengths', $lengths );
[1259] Fix | Delete
}
[1260] Fix | Delete
[1261] Fix | Delete
/**
[1262] Fix | Delete
* Compares the lengths of comment data against the maximum character limits.
[1263] Fix | Delete
*
[1264] Fix | Delete
* @since 4.7.0
[1265] Fix | Delete
*
[1266] Fix | Delete
* @param array $comment_data Array of arguments for inserting a comment.
[1267] Fix | Delete
* @return WP_Error|true WP_Error when a comment field exceeds the limit,
[1268] Fix | Delete
* otherwise true.
[1269] Fix | Delete
*/
[1270] Fix | Delete
function wp_check_comment_data_max_lengths( $comment_data ) {
[1271] Fix | Delete
$max_lengths = wp_get_comment_fields_max_lengths();
[1272] Fix | Delete
[1273] Fix | Delete
if ( isset( $comment_data['comment_author'] ) && mb_strlen( $comment_data['comment_author'], '8bit' ) > $max_lengths['comment_author'] ) {
[1274] Fix | Delete
return new WP_Error( 'comment_author_column_length', __( '<strong>Error:</strong> Your name is too long.' ), 200 );
[1275] Fix | Delete
}
[1276] Fix | Delete
[1277] Fix | Delete
if ( isset( $comment_data['comment_author_email'] ) && strlen( $comment_data['comment_author_email'] ) > $max_lengths['comment_author_email'] ) {
[1278] Fix | Delete
return new WP_Error( 'comment_author_email_column_length', __( '<strong>Error:</strong> Your email address is too long.' ), 200 );
[1279] Fix | Delete
}
[1280] Fix | Delete
[1281] Fix | Delete
if ( isset( $comment_data['comment_author_url'] ) && strlen( $comment_data['comment_author_url'] ) > $max_lengths['comment_author_url'] ) {
[1282] Fix | Delete
return new WP_Error( 'comment_author_url_column_length', __( '<strong>Error:</strong> Your URL is too long.' ), 200 );
[1283] Fix | Delete
}
[1284] Fix | Delete
[1285] Fix | Delete
if ( isset( $comment_data['comment_content'] ) && mb_strlen( $comment_data['comment_content'], '8bit' ) > $max_lengths['comment_content'] ) {
[1286] Fix | Delete
return new WP_Error( 'comment_content_column_length', __( '<strong>Error:</strong> Your comment is too long.' ), 200 );
[1287] Fix | Delete
}
[1288] Fix | Delete
[1289] Fix | Delete
return true;
[1290] Fix | Delete
}
[1291] Fix | Delete
[1292] Fix | Delete
/**
[1293] Fix | Delete
* Checks if a comment contains disallowed characters or words.
[1294] Fix | Delete
*
[1295] Fix | Delete
* @since 5.5.0
[1296] Fix | Delete
*
[1297] Fix | Delete
* @param string $author The author of the comment
[1298] Fix | Delete
* @param string $email The email of the comment
[1299] Fix | Delete
* @param string $url The url used in the comment
[1300] Fix | Delete
* @param string $comment The comment content
[1301] Fix | Delete
* @param string $user_ip The comment author's IP address
[1302] Fix | Delete
* @param string $user_agent The author's browser user agent
[1303] Fix | Delete
* @return bool True if comment contains disallowed content, false if comment does not
[1304] Fix | Delete
*/
[1305] Fix | Delete
function wp_check_comment_disallowed_list( $author, $email, $url, $comment, $user_ip, $user_agent ) {
[1306] Fix | Delete
/**
[1307] Fix | Delete
* Fires before the comment is tested for disallowed characters or words.
[1308] Fix | Delete
*
[1309] Fix | Delete
* @since 1.5.0
[1310] Fix | Delete
* @deprecated 5.5.0 Use {@see 'wp_check_comment_disallowed_list'} instead.
[1311] Fix | Delete
*
[1312] Fix | Delete
* @param string $author Comment author.
[1313] Fix | Delete
* @param string $email Comment author's email.
[1314] Fix | Delete
* @param string $url Comment author's URL.
[1315] Fix | Delete
* @param string $comment Comment content.
[1316] Fix | Delete
* @param string $user_ip Comment author's IP address.
[1317] Fix | Delete
* @param string $user_agent Comment author's browser user agent.
[1318] Fix | Delete
*/
[1319] Fix | Delete
do_action_deprecated(
[1320] Fix | Delete
'wp_blacklist_check',
[1321] Fix | Delete
array( $author, $email, $url, $comment, $user_ip, $user_agent ),
[1322] Fix | Delete
'5.5.0',
[1323] Fix | Delete
'wp_check_comment_disallowed_list',
[1324] Fix | Delete
__( 'Please consider writing more inclusive code.' )
[1325] Fix | Delete
);
[1326] Fix | Delete
[1327] Fix | Delete
/**
[1328] Fix | Delete
* Fires before the comment is tested for disallowed characters or words.
[1329] Fix | Delete
*
[1330] Fix | Delete
* @since 5.5.0
[1331] Fix | Delete
*
[1332] Fix | Delete
* @param string $author Comment author.
[1333] Fix | Delete
* @param string $email Comment author's email.
[1334] Fix | Delete
* @param string $url Comment author's URL.
[1335] Fix | Delete
* @param string $comment Comment content.
[1336] Fix | Delete
* @param string $user_ip Comment author's IP address.
[1337] Fix | Delete
* @param string $user_agent Comment author's browser user agent.
[1338] Fix | Delete
*/
[1339] Fix | Delete
do_action( 'wp_check_comment_disallowed_list', $author, $email, $url, $comment, $user_ip, $user_agent );
[1340] Fix | Delete
[1341] Fix | Delete
$mod_keys = trim( get_option( 'disallowed_keys' ) );
[1342] Fix | Delete
if ( '' === $mod_keys ) {
[1343] Fix | Delete
return false; // If moderation keys are empty.
[1344] Fix | Delete
}
[1345] Fix | Delete
[1346] Fix | Delete
// Ensure HTML tags are not being used to bypass the list of disallowed characters and words.
[1347] Fix | Delete
$comment_without_html = wp_strip_all_tags( $comment );
[1348] Fix | Delete
[1349] Fix | Delete
$words = explode( "\n", $mod_keys );
[1350] Fix | Delete
[1351] Fix | Delete
foreach ( (array) $words as $word ) {
[1352] Fix | Delete
$word = trim( $word );
[1353] Fix | Delete
[1354] Fix | Delete
// Skip empty lines.
[1355] Fix | Delete
if ( empty( $word ) ) {
[1356] Fix | Delete
continue; }
[1357] Fix | Delete
[1358] Fix | Delete
// Do some escaping magic so that '#' chars in the spam words don't break things:
[1359] Fix | Delete
$word = preg_quote( $word, '#' );
[1360] Fix | Delete
[1361] Fix | Delete
$pattern = "#$word#iu";
[1362] Fix | Delete
if ( preg_match( $pattern, $author )
[1363] Fix | Delete
|| preg_match( $pattern, $email )
[1364] Fix | Delete
|| preg_match( $pattern, $url )
[1365] Fix | Delete
|| preg_match( $pattern, $comment )
[1366] Fix | Delete
|| preg_match( $pattern, $comment_without_html )
[1367] Fix | Delete
|| preg_match( $pattern, $user_ip )
[1368] Fix | Delete
|| preg_match( $pattern, $user_agent )
[1369] Fix | Delete
) {
[1370] Fix | Delete
return true;
[1371] Fix | Delete
}
[1372] Fix | Delete
}
[1373] Fix | Delete
return false;
[1374] Fix | Delete
}
[1375] Fix | Delete
[1376] Fix | Delete
/**
[1377] Fix | Delete
* Retrieves the total comment counts for the whole site or a single post.
[1378] Fix | Delete
*
[1379] Fix | Delete
* The comment stats are cached and then retrieved, if they already exist in the
[1380] Fix | Delete
* cache.
[1381] Fix | Delete
*
[1382] Fix | Delete
* @see get_comment_count() Which handles fetching the live comment counts.
[1383] Fix | Delete
*
[1384] Fix | Delete
* @since 2.5.0
[1385] Fix | Delete
*
[1386] Fix | Delete
* @param int $post_id Optional. Restrict the comment counts to the given post. Default 0, which indicates that
[1387] Fix | Delete
* comment counts for the whole site will be retrieved.
[1388] Fix | Delete
* @return stdClass {
[1389] Fix | Delete
* The number of comments keyed by their status.
[1390] Fix | Delete
*
[1391] Fix | Delete
* @type int $approved The number of approved comments.
[1392] Fix | Delete
* @type int $moderated The number of comments awaiting moderation (a.k.a. pending).
[1393] Fix | Delete
* @type int $spam The number of spam comments.
[1394] Fix | Delete
* @type int $trash The number of trashed comments.
[1395] Fix | Delete
* @type int $post-trashed The number of comments for posts that are in the trash.
[1396] Fix | Delete
* @type int $total_comments The total number of non-trashed comments, including spam.
[1397] Fix | Delete
* @type int $all The total number of pending or approved comments.
[1398] Fix | Delete
* }
[1399] Fix | Delete
*/
[1400] Fix | Delete
function wp_count_comments( $post_id = 0 ) {
[1401] Fix | Delete
$post_id = (int) $post_id;
[1402] Fix | Delete
[1403] Fix | Delete
/**
[1404] Fix | Delete
* Filters the comments count for a given post or the whole site.
[1405] Fix | Delete
*
[1406] Fix | Delete
* @since 2.7.0
[1407] Fix | Delete
*
[1408] Fix | Delete
* @param array|stdClass $count An empty array or an object containing comment counts.
[1409] Fix | Delete
* @param int $post_id The post ID. Can be 0 to represent the whole site.
[1410] Fix | Delete
*/
[1411] Fix | Delete
$filtered = apply_filters( 'wp_count_comments', array(), $post_id );
[1412] Fix | Delete
if ( ! empty( $filtered ) ) {
[1413] Fix | Delete
return $filtered;
[1414] Fix | Delete
}
[1415] Fix | Delete
[1416] Fix | Delete
$count = wp_cache_get( "comments-{$post_id}", 'counts' );
[1417] Fix | Delete
if ( false !== $count ) {
[1418] Fix | Delete
return $count;
[1419] Fix | Delete
}
[1420] Fix | Delete
[1421] Fix | Delete
$stats = get_comment_count( $post_id );
[1422] Fix | Delete
$stats['moderated'] = $stats['awaiting_moderation'];
[1423] Fix | Delete
unset( $stats['awaiting_moderation'] );
[1424] Fix | Delete
[1425] Fix | Delete
$stats_object = (object) $stats;
[1426] Fix | Delete
wp_cache_set( "comments-{$post_id}", $stats_object, 'counts' );
[1427] Fix | Delete
[1428] Fix | Delete
return $stats_object;
[1429] Fix | Delete
}
[1430] Fix | Delete
[1431] Fix | Delete
/**
[1432] Fix | Delete
* Trashes or deletes a comment.
[1433] Fix | Delete
*
[1434] Fix | Delete
* The comment is moved to Trash instead of permanently deleted unless Trash is
[1435] Fix | Delete
* disabled, item is already in the Trash, or $force_delete is true.
[1436] Fix | Delete
*
[1437] Fix | Delete
* The post comment count will be updated if the comment was approved and has a
[1438] Fix | Delete
* post ID available.
[1439] Fix | Delete
*
[1440] Fix | Delete
* @since 2.0.0
[1441] Fix | Delete
*
[1442] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[1443] Fix | Delete
*
[1444] Fix | Delete
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
[1445] Fix | Delete
* @param bool $force_delete Whether to bypass Trash and force deletion. Default false.
[1446] Fix | Delete
* @return bool True on success, false on failure.
[1447] Fix | Delete
*/
[1448] Fix | Delete
function wp_delete_comment( $comment_id, $force_delete = false ) {
[1449] Fix | Delete
global $wpdb;
[1450] Fix | Delete
[1451] Fix | Delete
$comment = get_comment( $comment_id );
[1452] Fix | Delete
if ( ! $comment ) {
[1453] Fix | Delete
return false;
[1454] Fix | Delete
}
[1455] Fix | Delete
[1456] Fix | Delete
if ( ! $force_delete && EMPTY_TRASH_DAYS && ! in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ), true ) ) {
[1457] Fix | Delete
return wp_trash_comment( $comment_id );
[1458] Fix | Delete
}
[1459] Fix | Delete
[1460] Fix | Delete
/**
[1461] Fix | Delete
* Fires immediately before a comment is deleted from the database.
[1462] Fix | Delete
*
[1463] Fix | Delete
* @since 1.2.0
[1464] Fix | Delete
* @since 4.9.0 Added the `$comment` parameter.
[1465] Fix | Delete
*
[1466] Fix | Delete
* @param string $comment_id The comment ID as a numeric string.
[1467] Fix | Delete
* @param WP_Comment $comment The comment to be deleted.
[1468] Fix | Delete
*/
[1469] Fix | Delete
do_action( 'delete_comment', $comment->comment_ID, $comment );
[1470] Fix | Delete
[1471] Fix | Delete
// Move children up a level.
[1472] Fix | Delete
$children = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID ) );
[1473] Fix | Delete
if ( ! empty( $children ) ) {
[1474] Fix | Delete
$wpdb->update( $wpdb->comments, array( 'comment_parent' => $comment->comment_parent ), array( 'comment_parent' => $comment->comment_ID ) );
[1475] Fix | Delete
clean_comment_cache( $children );
[1476] Fix | Delete
}
[1477] Fix | Delete
[1478] Fix | Delete
// Delete metadata.
[1479] Fix | Delete
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) );
[1480] Fix | Delete
foreach ( $meta_ids as $mid ) {
[1481] Fix | Delete
delete_metadata_by_mid( 'comment', $mid );
[1482] Fix | Delete
}
[1483] Fix | Delete
[1484] Fix | Delete
if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) {
[1485] Fix | Delete
return false;
[1486] Fix | Delete
}
[1487] Fix | Delete
[1488] Fix | Delete
/**
[1489] Fix | Delete
* Fires immediately after a comment is deleted from the database.
[1490] Fix | Delete
*
[1491] Fix | Delete
* @since 2.9.0
[1492] Fix | Delete
* @since 4.9.0 Added the `$comment` parameter.
[1493] Fix | Delete
*
[1494] Fix | Delete
* @param string $comment_id The comment ID as a numeric string.
[1495] Fix | Delete
* @param WP_Comment $comment The deleted comment.
[1496] Fix | Delete
*/
[1497] Fix | Delete
do_action( 'deleted_comment', $comment->comment_ID, $comment );
[1498] Fix | Delete
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function