Skip to content

Instantly share code, notes, and snippets.

@kirasiris
Last active July 23, 2019 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirasiris/c94ccc790cac76137ade53f1002e3961 to your computer and use it in GitHub Desktop.
Save kirasiris/c94ccc790cac76137ade53f1002e3961 to your computer and use it in GitHub Desktop.
/*
*
* BOOTSTRAP COMMENTS PARA EL ARCHIVO FUNCTIONS.PHP
*
*/
function bootstrap_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
?>
<?php if ( $comment->comment_approved == '1' ): ?>
<li class="media">
<div class="media-left">
<?php echo get_avatar( $comment, 40); ?>
</div>
<div class="media-body">
<h4 class="media-heading">
<?php comment_author_link() ?>
</h4>
<time>
<a href="#comment-<?php comment_ID() ?>">
<?php comment_date() ?> at <?php comment_time() ?>
</a>
</time>
<?php echo comment_author_links(); ?>
<?php comment_text(); ?>
<?php
comment_reply_link(array_merge(
$args, array(
'depth' => $depth,
'max_depth' => $args['max_depth'],
)
)
)
?>
</div>
</li>
<?php else : ?>
<p class="bg-success">Your comments is waiting for approvation</p>
<?php endif;
}
function comment_author_links() {
$comment_ID = get_comment_ID();
if (current_user_can('edit_post')) {
echo '<a href="'.admin_url("comment.php?action=cdc&c=$comment_ID").'" style="color: red">Delete</a> ';
echo '<a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$comment_ID").'" style="color: purple">Spam</a>';
}
}
/*
*
* ARCHIVO COMMENTS.PHP PARA LA CARPETA ROOT DE SU THEME
*
*/
<?php
// Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
?>
<?php if ( post_password_required() ) : ?>
<div class="alert alert-info" id="alerts" role="alert"><p>This post is protected with a password. Type the password to see the comments</p></div>
<?php return; endif; ?>
<?php if ( have_comments() && comments_open()) : ?>
<div class="clearfix"></div>
<h3 class="page-header">Comments</h3>
<div class="alert alert-success" id="alerts" role="alert"><?php comments_number('No comments', 'One comment', '% Comments' );?> &#8220;<?php the_title(); ?>&#8221;</div>
<ul class="list-unstyled">
<?php wp_list_comments( array( 'callback' => 'bootstrap_comment' ) ); ?>
</ul>
<?php elseif( !comments_open() ) : ?>
<div class="clearfix"></div>
<h3 class="page-header">Comments</h3>
<div class="alert alert-danger" id="alerts" role="alert"><p>The comments are closed</p></div>
<?php else : ?>
<div class="clearfix"></div>
<h3 class="page-header">Comments</h3>
<div class="alert alert-warning" id="alerts" role="alert"><p>No comment found</p></div>
<div class="alert alert-info" id="alerts" role="alert"><?php comment_form_title( 'Would like to comment?','Send a comment to %s' ); ?></div>
<ul class="list-unstyled">
<?php wp_list_comments( array( 'callback' => 'bootstrap_comment' ) ); ?>
</ul>
<?php endif; ?>
<?php
/*
* Adding bootstrap support to comment form,
* and some form validation using javascript.
*/
ob_start();
$commenter = wp_get_current_commenter();
$req = true;
$aria_req = ( $req ? " aria-required='true'" : '' );
$comments_arg = array(
'form' => array(
'class' => 'form-horizontal'
),
'fields' => apply_filters( 'comment_form_default_fields', array(
'autor' =>
'<div class="form-group">'
. '<label for="author">' . __( 'Name', 'wp_babobski' ) . '</label> ' . ( $req ? '<span>*</span>' : '' )
. '<input id="author" name="author" class="form-control" type="text" value="" size="30"' . $aria_req . ' />'
. '<p id="d1" class="text-danger"></p>'
.'</div>',
'email' =>
'<div class="form-group">'
.'<label for="email">' . __( 'Email', 'wp_babobski' ) . '</label> ' . ( $req ? '<span>*</span>' : '' )
. '<input id="email" name="email" class="form-control" type="text" value="" size="30"' . $aria_req . ' />'
. '<p id="d2" class="text-danger"></p>'
.'</div>',
'url' =>
''
)
),
'comment_field' =>
'<div class="form-group">'
. '<label for="comment">' . __( 'Comment', 'wp_babobski' ) . '</label><span>*</span>'
. '<textarea id="comment" class="form-control" name="comment" rows="5" aria-required="true"></textarea>'
. '<p id="d3" class="text-danger"></p>'
.'</div>',
'comment_notes_after' => '',
'class_submit' => 'btn btn-default'
); ?>
<?php comment_form($comments_arg);
echo str_replace('class="comment-form"','class="comment-form" name="commentForm" onsubmit="return validateForm();"',ob_get_clean());
?>
<script>
/* basic JavaScript form validation */
function validateForm() {
var form = document.forms.commentForm,
x = form.author.value,
y = form.email.value,
z = form.comment.value,
flag = true,
d1 = document.getElementById("d1"),
d2 = document.getElementById("d2"),
d3 = document.getElementById("d3");
if (x === null || x === "") {
d1.innerHTML = "<?php echo __('Name is required', 'wp_babobski'); ?>";
flag = false;
} else {
d1.innerHTML = "";
}
if (y === null || y === "") {
d2.innerHTML = "<?php echo __('Email is required', 'wp_babobski'); ?>";
flag = false;
} else {
d2.innerHTML = "";
}
if (z === null || z === "") {
d3.innerHTML = "<?php echo __('Comment is required', 'wp_babobski'); ?>";
flag = false;
} else {
d3.innerHTML = "";
}
if (flag === false) {
return false;
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment