Customize wordpress comment form - reply link - php

I'm building a theme for Wordpress on my own and I'm having som problems with my comment form. I want to change the text of the reply"button" (actually it's not a button, it's an a-class with onclick function). Now the default is "reply", but I want to change it to something else. How do a do that?
My php-file looks like this:
<?php
/**
* The template for displaying Comments.
*
* The area of the page that contains comments and the comment form.
*
*/
/*
* If the current post is protected by a password and the visitor has not yet
* entered the password we will return early without loading the comments.
*/
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die('Please do not load this page directly. Thanks!');
if (post_password_required()) {
?>
<p class="nocomments">Det här inlägget är lösenordsskyddat. Knappa in lösenordet för att se inlägget.</p>
<?php
return;
}
?>
<div id="commentsbox" class="post">
<?php if (have_comments()) : ?>
<h3 id="comments">
<?php comments_number('Inga kommentarer',
'En kommentar',
'% kommentarer'); ?>
än så länge.</h3>
<ol class="commentlist">
<?php wp_list_comments(array(
'avatar_size' => 70)); ?>
</ol>
<div class="comment-nav">
<div class="alignleft">
<?php previous_comments_link() ?>
</div>
<div class="alignright">
<?php next_comments_link() ?>
</div>
</div>
<?php else : ?>
<?php if (comments_open()) : ?>
<?php else : ?>
<p class="nocomments">Kommentarer är avstängda</p>
<?php endif; ?>
<?php endif; ?>
<?php if (comments_open()) : ?>
<div class="commentform_wrapper">
<div class="post-info">
</div>
<div id="comment-form">
<?php $comment_args = array( 'title_reply'=>'Vänligen lämna dina synpunkter och kommentarer:',
'title_reply_to' => __( 'Svara %s' ),
'cancel_reply_link' => __( 'Stäng svar' ),
'label_submit'=>'Skicka',
'reply_text' => 'Svara',
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Namn' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email">' .
'<label for="email">' . __( 'Mejl' ) . '</label> ' .
( $req ? '<span>*</span>' : '' ) .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />'.'</p>',
'url' => '' ) ),
'comment_field' => '<p>' .
'<label for="comment">' . __( 'Kommentarer' ) . '</label>' .
'<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
'</p>',
'comment_notes_after' => '',
);
comment_form($comment_args); ?>
</div>
</div>
<?php endif; ?>
</div>
The code that I want to reach looks like this, when inspecting with firebug:
<a class="comment-reply-link" onclick="return addComment.moveForm("div-comment-3", "3", "respond", "40")" href="/?p=40&replytocom=3#respond">Reply</a>

Add into functions.php :
function custom_comment_reply($content) {
$content = str_replace('Reply', 'Reply to this comment', $content);
return $content;
}
add_filter('comment_reply_link', 'custom_comment_reply');
Change " Reply" - "Reply to this comment" .

Related

Delete WordPress post from front end

I have duilt a custom post type and added it to a tab on the profile page. I want to add a button to delete the post if the post author is logged in. I tried several methods but couldn't find a way to delete it since I am not trying to delete it from the single post page. Can anyone direct me on how to achieve this?
//function to print publish button
function show_publish_button(){
Global $post;
//only print fi admin
echo '<form id="myForm" name="front_end_publish" method="POST" action="">
<input type="hidden" name="pid" id="pid" value="'.$post->ID.'">
<button type="submit" name="submit" id="submit" value="delete" class="btn" style="margin-left:2px;background:#f5f5f5;"><i class="fa fa-fw fa-times"></i>delete</button>
</form>';}
// Adding Manage Event TAB content
function manage_events_content() {
$type = 'events';
$args = array (
'post_type' => $type,
'name' => $title,
'author' => bp_displayed_user_id(),
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 10,
'ignore_sticky_posts'=> 1,
);
$temp = $wp_query; // assign ordinal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post();
echo '<div style="background-color:#fff; padding: 20px; border-radius: 10px; margin: 20px">
<div>
<div>
<h4 style="font-weight: 400; font-size: 15px; text-transform: capitalize">Event Name:
<a style="color:#5a5a5a;" href="' . get_the_permalink() . '">' . get_the_title() . '</a>
</h4></div>
<div>
<h4>
Number of tickets available: <span>' . get_post_meta(get_the_ID(), "number-of-ticket-available", true) . '</span>
</h4>
<h4>
Number of tickets available: <span>' . get_post_meta(get_the_ID(), "number-of-confirmed-attendees", true) . '</span>
</h4>
</div>
<div>
<h4>
Start Date: <span>' . get_post_meta(get_the_ID(), "event-anfang", true) . '</span>
</h4>
<h4>
End Date: <span>' . get_post_meta(get_the_ID(), "event-ende", true) . '</span>
</h4>
</div>' . show_publish_button() . '
</div>
</div>';
endwhile;
else :
echo '<h4>You dont have any events</h4>';
endif;
$wp_query = $temp;
}

How to fix Warning: Use of undefined constant active - assumed 'active' (this will throw an Error in a future version of PHP)

I'm currently working on a WirdPress Theme project using Bootstrap v5.0.2 and PHP 7.3.28.
I'm tryng to insert the Bootstrap Carousel Component in a custom widget but when I debug the code I recive this "Warning: Use of undefined constant active - assumed 'active' (this will throw an Error in a future version of PHP) in ... on line 70"
This is the line that give me the error:
echo ' class="';if ( $the_query->current_post == 0 ) : active ;endif; '"> ';
I try to change active in $active or 'active' but it doen't works.
Because I'm a newbie in PHP I don't understand what I'm doing wrong.
I hope someone can help me to solve this problem.
Thanks
This is the whole code:
<?php
// Register and load the widget
function tabulas_slider_widget() {
register_widget( 'Tabulas_Slider_Widget' );
}
add_action( 'widgets_init', 'tabulas_slider_widget' );
// Creating the widget
class Tabulas_Slider_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
parent::__construct(
// Base ID of widget
'Tabulas_Slider_Widget',
// Widget name will appear in UI
esc_html__('Last Post Slider', 'tabulas'),
// Widget description
array( 'description' => esc_html__( 'Display the 3 last post published with featured image in the form of a Slider', 'tabulas'), )
);
}
/**
* Front-end display of widget.
*
* #see WP_Widget::widget()
*
* #param array $args Widget arguments.
* #param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
// WP_Query arguments
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
);
// The Query
$the_query = new WP_Query ( $args );
echo ' <div id="carouselExampleCaptions" ';
echo ' class="carousel slide" ';
echo ' data-bs-ride="carousel" ';
echo ' data-bs-interval="10000"> ';
echo ' <div class="carousel-indicators"> ';
if ( $the_query->have_posts() ) :
echo $args['before_widget'];
if ( $title ){
echo $args['before_title'] . $title . $args['after_title'];
}
echo ' <ol class="carousel-indicators"> ';
while ( $the_query->have_posts() ) : $the_query->the_post();
echo ' <li data-target="#ExampleCarouselID" ';
echo ' data-slide-to="';$the_query->current_post;'" ';
echo ' class="';if ( $the_query->current_post == 0 ) : active ;endif; '"> ';
echo ' </li> ';
endwhile;
echo ' </ol> ';
rewind_posts();
echo ' <button type="button" ';
echo ' data-bs-target="#carouselExampleCaptions" ';
echo ' data-bs-slide-to="0" ';
echo ' class="active" ';
echo ' aria-current="true" ';
echo ' aria-label="Slide 1">';
echo ' </button> ';
echo '<button type="button" ';
echo ' data-bs-target="#carouselExampleCaptions" ';
echo ' data-bs-slide-to="1" ';
echo ' aria-label="Slide 2">';
echo ' </button> ';
echo '<button type="button" ';
echo ' data-bs-target="#carouselExampleCaptions" ';
echo ' data-bs-slide-to="2" ';
echo ' aria-label="Slide 3">';
echo '</button>';
echo '</div>';
echo ' <div class="carousel-inner"> ';
while ( $the_query->have_posts() ) : $the_query->the_post();
$thumbnail_id = get_post_thumbnail_id();
$thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, 'full', true );
$thumbnail_meta = get_post_meta( $thumbnail_id, '_wp_attatchment_image_alt', true );
echo ' <div class="carousel-item ';
if ( $the_query->current_post == 0 ) : active ;endif; '"> ';
if ( has_post_thumbnail() ) {
echo '<a href="';the_permalink(); echo '">';
the_post_thumbnail('full');
echo '</a>';
}
echo '<div class="carousel-caption d-none d-md-block">';
echo '<h5>';
the_title();
echo '</h5>';
echo '</div>';
echo '</div>';
endwhile;
wp_reset_query();
echo '</div>';
echo '<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">';
echo '<span class="carousel-control-prev-icon" aria-hidden="true">';
echo '</span>';
echo' <span class="visually-hidden">';esc_html_e( 'Previous', 'tabulas' );
echo '</span>';
echo '</button>';
echo '<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">';
echo '<span class="carousel-control-next-icon" aria-hidden="true">';
echo '</span>';
echo '<span class="visually-hidden">';esc_html_e( 'Next', 'tabulas' );
echo '</span>';
echo '</button>';
echo '</div>';
echo $args['after_widget'];
wp_reset_postdata();
endif;
}
You must echo 'active' and end of line:
echo ' class="';if ( $the_query->current_post == 0 ) : echo 'active' ;endif; echo '"> ';

Wordpress: Show up 'comment_form()' instead 'comment_reply_link()' in custom 'wp_list_comments()'

I'm developing my own code to display the comment list and comment form.
What I need is to replace 'reply' button (only when is shown), with a comment form, next to the commentary to make the reply.
All the code I have so far is the following. Can someone help me fix it? Thanks.
<?php
$postid = XXX;
$comment_send = 'Send';
$comment_reply = 'Leave a Message';
$comment_reply_to = 'Reply';
$comment_author = 'Name';
$comment_email = 'E-Mail';
$comment_body = 'Comment';
$comment_url = 'Website';
$comment_cookies_1 = ' By commenting you accept the';
$comment_cookies_2 = ' Privacy Policy';
$comment_before = 'Registration isn\'t required.';
$comment_cancel = 'Cancel Reply';
$comments_args = array(
'fields' => array(
'author' => '<p class="comment-form-author"><br /><input id="author" name="author" aria-required="true" placeholder="' . $comment_author .'"></input></p>',
'email' => '<p class="comment-form-email"><br /><input id="email" name="email" placeholder="' . $comment_email .'"></input></p>',
'url' => '<p class="comment-form-url"><br /><input id="url" name="url" placeholder="' . $comment_url .'"></input></p>',
'cookies' => '<input type="checkbox" required>' . $comment_cookies_1 . '' . $comment_cookies_2 . '',
),
'label_submit' => __( $comment_send ),
'title_reply' => __( $comment_reply),
'cancel_reply_link' => __( $comment_cancel ),
'comment_field' => '<p class="comment-form-comment"><br /><textarea id="comment" name="comment" aria-required="true" placeholder="' . $comment_body .'"></textarea></p>',
'comment_notes_before' => __( $comment_before),
'comment_notes_after' => ''
);
comment_form( $comments_args, $postid );
?>
<ol class="commentlist">
<?php wp_list_comments(array('callback' => 'custom_comments_format'), get_comments(array('post_id' => $post_id))); ?>
<?php function custom_comments_format($comment, $args, $depth){ ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author">
<?php echo get_avatar( $comment, 56 ); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author()) ?>
</div>
<div class="comment-moderation">
<?php if ($comment->comment_approved == '0') : ?>
<p><?php _e('Your comment is awaiting moderation.') ?></p>
<?php endif; ?>
</div>
<div class="comment-meta commentmetadata">
<p ><?php printf(__('%1$s at %2$s'), get_comment_date('j F, Y'), get_comment_time()) ?><?php edit_comment_link(__('(Edit)'),' ','') ?></p>
</div>
<div class="user-comment">
<?php comment_text() ?>
</div>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php } ?>
</ol>
Ps: The relation between a form and a reply comment is the comment_parent input. I can stack a new form instead the reply button, but I dont know how to set the comment_parent id into the comment_form( $comments_args, $postid ); as I did before to customize the form itself.
<input type="hidden" name="comment_parent" id="comment_parent" value="XXX">
<div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
<?php
if($depth < $args['max_depth']){
$comments_args = array(
'comment_field' => '<input type=\'hidden\' name=\'comment_parent\' id=\'comment_parent\' value=\''.get_comment_ID().'\' />'
);
comment_form( $comments_args, $postid );
}
?>
</div>
Following my own steps, ive sloved the problem now its DONE like this.
<div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
<?php
if($depth < $args['max_depth']){
$postid = $comment->comment_post_ID;
$comments_args['submit_field'] = '<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Send"> <input type="hidden" name="comment_post_ID" value="'.$postid.'" id="comment_post_ID"> <input type="hidden" name="comment_parent" id="comment_parent" value="'.get_comment_ID().'"> </p>';
comment_form( $comments_args, $postid );
}
?>
</div>

How to put an echo inside a div that's inside an echo

I am trying to call Buddy Press' avatar and replace my Newspaper theme's avatar in the menu. How do I put this code:
echo bp_core_fetch_avatar( array(
'item_id' => bp_loggedin_user_id(),
'width' => 21,
'height' => 21,
'class' => 'avatar',
)
);
Inside the
<div class="td-avatar-container"></div>
class?
<?php
//get current logd in user data
global $current_user;
echo '
<div class="td-logged-wrap">
<div class="td-menu-avatar">
<div class="td-avatar-container">' . bp_core_fetch_avatar ($current_user->ID, 80) . '</div>
</div>
<div class="td-menu-username">' . $current_user->display_name . '</div>
<div class="td-menu-logout">' . __td('Logout', TD_THEME_NAME) . '</div>
</div>
';
Thanks! I keep getting white screens, and this is the very last thing I need for this feature to go live! Any help would be greatly appreciated.
You can stop and start PHP within html any time.
<div class="td-logged-wrap">
<div class="td-menu-avatar">
<div class="td-avatar-container">
<?php echo' . bp_core_fetch_avatar ($current_user->ID, 80) . '; ?>
</div>
</div>
<div class="td-menu-username"><a href="
<?php echo' . bp_core_get_user_domain($current_user->ID) . '; ?>
" class="td_user_logd_in"><?php echo' . $current_user->display_name . '; ?>
</a></div>
<div class="td-menu-logout"><?php echo' . __td('; ?>Logout<?php echo', TD_THEME_NAME) . '; ?>
</div>
This doesn't quite answer your question, but will help you see why you are having the problem.
Change the following in the wp-config.php in order to see the errors and you can debug from there:
define('WP_DEBUG', true);

Updating database based on checkbox Codeigniter

I'm trying to update a database column using a checkbox. The idea is that I want to only display certain things on the homepage, so the checkbox should send either 0 or 1 to the DB. If the record has 0 in the first page column, it shouldn't appear on the homepage, if it has 1 it should appear.
I tried setting something up, but it doesn't work as intended (it just refreshes the page with no effect)
The checkbox:
<?php echo form_checkbox(array('name' => 'first_page', 'class'=>'checkbox-inline', 'value' => 1)); ?>
Controller:
if(null != ($this->input->post('first_page'))) {
$first_page = 1;
$book_id= $this->input->post('id'); (the id is sent to the controller via an extra hidden input field)
$this->book_model->first_page($first_page, $book_id);
}
Model:
$this->db->set ( "first_page", $first_page);
$this->db->where ( "book_id", $book_id);
$this->db->update ( "books" );
return;
Full form:
<?php echo form_open('admin/modifica_autor'); ?>
<?php echo form_hidden('id', $item->id_carte); ?>
<?php echo form_hidden('id_autor', $item->id_autor)?>
<label for="titlu_nou">Titlu:</label>
<?php echo form_input(array('name' => 'titlu_nou_carte', 'class'=>'form-control', 'value' => $item->titlu)); ?> <br>
<label for="autor_nou">Autor:</label>
<select name='autor_nous' class="form-control"><?php
foreach ( $autori2 as $row ) {
echo '<option value="' . $row->id_autor . '">' . $row->nume_autor . '</option>'; }
?></select><br>
<label for="domeniu_nou">Domeniu:</label>
<select name='domeniu_nou' class="form-control"><?php
foreach ( $domenii as $row ) {
echo '<option value="' . $row->id_domeniu . '">' . $row->nume_domeniu . '</option>';
}
?></select><br>
<label for="pret_nou">Pret:</label>
<?php echo form_input(array('name' => 'pret_nou', 'class'=>'form-control', 'value' => $item->pret.' LEI')); ?><br>
<label for="descriere_noua">Descriere:</label>
<?php echo form_textarea(array('name' => 'descriere_noua', 'class'=>'form-control textarea', 'value' => $item->descriere)); ?><br>
<label for="prima_pagina">Afisare pe prima pagina:</label>
<?php echo form_checkbox(array('name' => 'prima_pagina', 'class'=>'checkbox-inline', 'value' => 1)); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<?php echo form_submit(array('name'=>'submit_autor','value' => 'Modifica', 'class'=>'btn btn-default')); ?>
<?php echo form_close(); ?>

Categories