Как создать отдельную форму комментария для comment_reply_link() ?
Подскажите, пожалуйста, а как создать собственную форму оставления комментария на эту ссылку "Reply"? comment_reply_link()
У меня есть кастомная форма постановки комментариев
<div id="comments" class="company-rewiew-list">
<?php
$page = max(1, get_query_var('cpage'));
wp_list_comments(array(
'type' => 'comment',
'reverse_top_level' => false, // Отключите сортировку родительских комментариев от старых к новым
'reverse_children' => true, // Включите сортировку ответов на родительские комментарии от новых к старым
'callback' => 'reviews_theme_comment',
'per_page' => $per_page,
'cpage' => $page,
)); ?>
</div>
function reviews_theme_comment($comment, $args, $depth)
{
if (!$comment->comment_parent) {
// Это родительский комментарий, открываем новый блок rewiew-card
echo '<div class="rewiew-card" data-crating="' . $comment_rating . '" data-published="' . $comment_date . '">';
?>
<div> Comment Block
}
}
В ней добавляються дополнительные поля которые пишуться в базу, но когда я вивожу стандартную кнопку "Reply" и жму её, то мне уже не надо, что б пользователь который отвечает на выведеный комментарий заполнял поля рейтинга, соглашался с условиями лицензирования и тд... а мне подтягиваеться именна эта форма. Как это поправить ? (Скрыть через CSS не используэмые поля не вариант, поскольку ответы не запишуться в базу поскольку некоторые из этих доп полей есть обязательными к заполнению)
Сама форма выглядит так
<?php
$post_id = get_the_ID();
?>
<div class="company-review-control">
<div class="settings-form custom-checkbox custom-file">
<?php
add_action('comment_form_logged_in_after', 'extend_comment_custom_fields');
add_action('comment_form_after_fields', 'extend_comment_custom_fields');
function extend_comment_custom_fields()
{
echo '<div class="rating-label"><span>Product rating</span><div class="rating">';
for ($i = 5; $i > 0; $i--) {
echo '<input id="' . $i . '_star_product" class="rating-input" type="radio" name="rating_product" value="' . $i . '"/><label for="' . $i . '_star_product" class="rating-star"></label>';
}
echo '</div></div>';
echo '<div class="rating-label"><span>Service & Delivery</span><div class="rating">';
for ($i = 5; $i > 0; $i--) {
echo '<input id="' . $i . '_star_service" class="rating-input" type="radio" name="rating_service" value="' . $i . '"/><label for="' . $i . '_star_service" class="rating-star"></label>';
}
echo '</div></div>';
echo '<input id="rating_full" type="hidden" name="rating" value="0"/>';
echo '<p class="comment-form-title">' .
'<label for="title">' . __('Title of your review', 'am') . '</label>' .
'<input id="comment_title" name="comment_title" type="text" placeholder="If you could say it in one sentence, what would you say?"/>';
echo '</p>';
echo '<label class="label_file label_file_upload"><span>' . __('Add your photo (optional)', 'am') . '</span><input type="file" name="file_upload" accept=".png, .jpg, .jpeg, .webp"></label>';
echo '<label class="label_file label_file_proof"><span>' . __('Proof of purchase', 'am') . '</span><input type="file" name="file_proof" accept=".png, .jpg, .jpeg, .webp"></label>';
echo '<label class="label_checkbox label_checkbox_confirm"><input type="checkbox" name="checkbox_confirm"><span class="checkmark"></span>
<span class="checkbox-txt">Eos tollit ancillae ea, lorem consulatu qui ne, eu eros eirmod scaevola sea. Et nec tantas accusamus salutatus, sit commodo veritus te, erat legere fabulas has ut. Rebum laudem cum ea, ius essent fuisset ut. Viderer petentium cu his.</span></label>';
echo '<input type="hidden" name="comment_nonce" value="' . wp_create_nonce('comment_nonce') . '" />';
}
$comment_args = array(
'comment_notes_before' => '',
'logged_in_as' => '',
'id_form' => 'comment_form_review',
'id_submit' => 'submit',
'class_container' => 'comment-respond',
'class_form' => 'comment_form_review',
'title_reply' => __('Write a review of ', 'am') . get_the_title(),
'title_reply_to' => __('Write a review of %s ', 'am') . get_the_title(),
'title_reply_before' => '<p id="reply-title" class="comment-reply-title h3">',
'title_reply_after' => '</p>',
'comment_notes_after' => '',
'comment_field' => '<p class="comment-form_textarea">
<label for="comment"><span class="comment_title">' . _x('Your review', 'noun') . '</span></label>
<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="required" placeholder="Write your review to help others learn about this online business"></textarea>
</p>',
'label_submit' => 'Save personal info',
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
);
comment_form($comment_args);
?>
</div>
</div>
Ищу что-то по типу ---> if ($comment->comment_parent == 0) { показывай стандартную } а если отвечаешь на уже сформированый отзыв, то другую .
Вот так идет разделение валидации форм под разные темплейты
// 2. Validation add_filter('pre_comment_on_post', 'custom_verify_comment'); function custom_verify_comment($commentdata) { $is_review_template = is_page_template('template-parts/write-review-block.php'); $is_reply_template = is_page_template('template-parts/write-review-reply-block.php'); if ($is_review_template) { // if (empty($_POST['comment_title'])) { // wp_die('Please, write Title for message!'); // } if (empty($_POST['rating_product'])) { wp_die('Please select a product rating!'); } if (empty($_POST['rating_service'])) { wp_die('Please select a service rating!'); } // Проверка Nonce if (!isset($_POST['comment_nonce']) || !wp_verify_nonce($_POST['comment_nonce'], 'comment_nonce')) { wp_die('Nonce verification failed!'); } } if ($is_reply_template) { // Проверка Nonce if (!isset($_POST['comment_nonce']) || !wp_verify_nonce($_POST['comment_nonce'], 'comment_nonce')) { wp_die('Nonce verification failed!'); } } return $commentdata; }