Дополнительное поле в комментариях WordPress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <?php // Показываем поле Название предприятия: function add_city_comment_form_field($default) { $commenter = wp_get_current_commenter(); $default['fields']['email'] .= '<p class="comment-form-author">' . '<label for="city">Название предприятия:</label> <span class="required">*</span> <input id="city" name="city" size="30" type="text" /></p>'; return $default; } // Проверяем, что поле Название предприятия заполнено пользователем: function verify_comment_city_data($commentdata) { if (!isset($_POST['location'])) : wp_die('Ошибка: пожалуйста заполните обязательное поле (Название предприятия).'); endif; return $commentdata; } // Показываем поле Название предприятия в комментариях: function attach_city_to_author($author) { $city = get_comment_meta(get_comment_ID(), 'location', true); if ($location) $author .= " ($location)"; return $author; } // Сохраняем значение поля Название предприятия в базу данных: function save_comment_city_data($comment_id) { add_comment_meta($comment_id, 'location', $_POST['location']); } add_filter('comment_form_defaults', 'add_city_comment_form_field'); // показываем поле add_filter('preprocess_comment', 'verify_comment_city_data'); // проверяем данные поля add_filter('get_comment_author_link', 'attach_city_to_author'); // показываем поле в комментариях add_action('comment_post', 'save_comment_city_data'); // сохраняем данные поля ?> |