comment_exists()
Determines if a comment exists based on author and date.
For best performance, use $timezone = 'gmt', which queries a field that is properly indexed. The default value for $timezone is 'blog' for legacy reasons.
Хуков нет.
Возвращает
Строку|null
. Comment post ID on success.
Использование
comment_exists( $comment_author, $comment_date, $timezone );
- $comment_author(строка) (обязательный)
- Author of the comment.
- $comment_date(строка) (обязательный)
- Date of the comment.
- $timezone(строка)
- Timezone. Accepts 'blog' or 'gmt'.
По умолчанию: 'blog'
Заметки
- Global. wpdb. $wpdb WordPress database abstraction object.
Список изменений
С версии 2.0.0 | Введена. |
С версии 4.4.0 | Added the $timezone parameter. |
Код comment_exists() comment exists WP 6.6.2
function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) { global $wpdb; $date_field = 'comment_date'; if ( 'gmt' === $timezone ) { $date_field = 'comment_date_gmt'; } return $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_author = %s AND $date_field = %s", stripslashes( $comment_author ), stripslashes( $comment_date ) ) ); }