Wordpress Hide or Disable Comment Box Conditionally With PHP - wordpress

I want to allow user only one comment in a post.
I check/validate my user comments with preprocess_comment filter hook. And stop for multiple comments.
But I can not hide the comment form box after user make the comment.
when a user comment in a post then the comment box will disable/hide from the page.
Help please

You may create your custom comment.php template of course comment form also in your theme.
Check this link
https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comment-template/
End of the page:
https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comment-template/#the-end
<?php
if( YOUR_CONDITION_FUNCTION_OR_LOGIC() ){
comment_form();
}
?>
Hope it helps you.

Related

how can i add comments to to a custom page

I am trying to display the comments of a post in a custom page in wordpress. I want to display all the comments including sub-comments. There is any way to display the comments of corresponding post?the_comments() shows all the comments in the database. Can I use get_the_commets($args)?
get_comments() would do the trick for you.
$comments = get_comments(array('post_id'=>YOUR_ID));
will return you an array of comments for particular post.
You can check get_comments page for more options

How to highlight comments in WordPress admin panel?

I want to highlight author comments in admin panel of WordPress engine. I have many comments on my blog every day, and it's hard sometimes in admin panel to find my own comment.
This can be achieved with a targeted action hook and a bit of CSS:
add_action( 'admin_head-edit-comments.php', 'colored_comments_so_15232115' );
function colored_comments_so_15232115()
{
?>
<style>.comment-author-USER_LOGIN { background-color: #DFDB83 }</style>
<?php
}
Replace USER_LOGIN with your login name. And surely, you could add as many users/background-colors as needed.
This CSS is only printed in the Comments page (/wp-admin/edit-comments.php) by using the hook admin_head-$hook_suffix.
You can also use a plugin: Comment Moderation Highlights
note: I'm the plugin developer.
Set it so that it looks for your email addresss, pick a color and save. All your comments will be Highlighted within the comments admin.

modify BuddyPress adminbar only in admin pages

I have modified the buddypress admin bar by creating the following plugin which adds a simple text link to the bar:
function bp_adminbar_currentsite_menu() {
global $bp;
?>
<li>
<!-- Insert your link url or relative url, and your link text below -->
EXAMPLE LINK TEXT
</li>
<?php
}
// Call The Function Above
add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999);
However, I do NOT want the above link to be shown when logged into the wordpress admin backend (so for example when an admin is editing a post). I thought about just doing a php_self check to see if it contained "/wp-admin/" but figured that there has to be a more elegant wordpress/buddypress hook here.
How can I get the above code to only show when you are viewing a normal blog page, NOT in the admin area?
Thanks
using is_admin() is the answer. It is a wordpress function that checks to see if you are looking at admin pages or not.

Drupal 7 anonymous comments, disable homepage field

In Drupal 7 comments, how can I hide/disable homepage field for anonymous commenters?
Whilst there are lots of answers here none of them provide all of the code in one easy to copy and paste block:
/**
* Implements hook_form_FORM_ID_alter().
*
* Remove homepage field from comments form.
*/
function THEMENAME_form_comment_form_alter(&$form, &$form_state) {
$form['author']['homepage']['#access'] = FALSE;
}
Put this code in your themes template.php replacing THEMENAME with the name of your theme.
Open the file themes/<your_theme>/templates/comment-wrapper.tpl.php in your drupal installation folder, and add this line before the HTML code:
<?php $content['comment_form']['author']['homepage'] = null; ?>
or at least before
<?php print render($content['comment_form']); ?>
With that you're deactivating the homepage field in the form that is displayed to the user.
You can also do what #Robert says and choose "Anonymous posters may not leave their contact info", but you'd be allowing comments without email information as well. If you just want to hide the homepage field from the form and keep the email (for example, to use Gravatar), this bit of hacking should do the trick. If your website has more than one theme, make sure you do it in every theme that displays the comments form.
In a suitable form_alter() hook, do this:
$form['author']['homepage']['#access'] = FALSE;
This is better than using unset() or setting $form['author']['homepage'] to null as described in other answers, because the comment_form_validate() function throws ugly errors.
All credit to Art Williams
Administration » Structure » Content types » (Your content type) » Comment Settings » Anonymous commenting » Anonymous posters may not / may /must leave their contact info.
Here's the three-line custom module solution. I usually keep a custom_site_tweaks module for this type of thing per site.
function CUSTOM_form_comment_node_blog_post_form_alter(&$form, &$form_state, $form_id) {
unset($form['author']['homepage']);
}
BTW: This is a great way to de-incentivize spam posts.

adding single.php page to wordpress or if condition for main page or post detail page

I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul

Resources