Drupal 7 anonymous comments, disable homepage field - drupal

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.

Related

Restrict access to comments in WordPress using the plugin Restrict Content Pro

I would like to ask if someone can help me with this question. I can't find anywhere how to do it.
I have a website with Wordpress as a CMS. I use the plugin Restrict Content Pro to restrict access to exclusive content.
I share the post in freemium mode.
And now the question:
How could I restrict access to post comments?
I guess through something in the php code, but I don't know how.
Can anybody help me?
Thank you!
I don't use this plugin myself, but just found a good looking tutorial. Apparently, you restrict access to comments in the same way that you restrict access to anything else: By only outputting it in the theme files when the user has access to it. For example, the TwentyTwentyOne theme has a file "comments.php", which starts like this:
/*
* If the current post is protected by a password and
* the visitor has not yet entered the password,
* return early without loading the comments.
*/
if ( post_password_required() ) {
return;
}
$twenty_twenty_one_comment_count = get_comments_number();
?>
You can easily add another check beneath the password check:
/**
* Check if the user has access, don't output the comments if they don't.
*/
if ( !rcp_user_has_active_membership() ) {
return;
}
Of course, instead of returning you can also output something along the lines of "get a membership to see the comments".
The tutorial I found lists different ways to check for a membership, a paid membership and more special checks.
Two more things:
Be sure to check if there are other places where comments are displayed. That very much depends on how the WordPress theme is built.
Don't just change the theme if it comes from an external source, e.g. if it might receive updates in the future. In that case create a child theme and make your changes there instead. You can read more about child themes in the Theme Handbook.

Wordpress: Polylang and ACF Options page on ajax calls takes default language value

I'm working on a website, which is multilingual.
We're using Polylang and the ACF custom fields plugin.
Works fine in general, the issue is with the ACF Option pages.
The option pages are translated also in different languages.
The content we are taking from there is being displayed according to translation - in english on the english version of a page, french on the french etc.
The problem: We have a contact us form, where we take the recipients email address from the ACF option pages.
(We want to send it to a different recepient when its a different language.)
Here it always takes the email address from the default language option page and I don't understand why.
We are taking the email recipient for the ajax call with get field command, like on pages displaying content:
get_field('service_email', 'option' );
Anyone got an idea what could cause this? Or where to look?
In the end we found the solution. It took a bit of digging, but I hope this helps if anyone encounters the same issue.
We needed to add the following setup in the functions.php of our theme to have the ACF options pages also translated for the each language:
// Translating Options Page Compatibility
// add filter with the path to your acf installation
add_filter('acf/settings/default_language', 'my_settings_default_language');
add_filter('acf/settings/current_language', 'my_settings_current_language');
function my_settings_default_language( $lang ) {
if($lang == "") {
$lang = pll_default_language(); // pll_ is a polylang function
}
return $lang;
}
function jfrog_settings_current_language( $lang ) {
$lang = pll_current_language();
return $lang;
}
Side Note: We're using a theme installed version of ACF.
hope this helps, Cheers

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.

How to create a profile page in Wordpress Multisite

I can't find a way to create a front-end profile page for all users under Wordpress Multisite Network. I also wanted the profile page to be on the main site and not on sub-sites if possible. I don't want to use any social network plugins like buddypress.. I just want to create a page like http://mainsite.com/profile/username
Is there a way to accomplish this?
Maybe you might check out Buddypress which is a social layer on top of Wordpress and is able to do what you need (i.e. something like http://mainsite.com/profile/username).
Link: http://buddypress.org/
More specifically, in Buddypress the default behaviour is http://mainsite.com/members/username
I have noticed that you have edited the question and that you are looking for a way to accomplish this without any plugin. There are a series of tags in Wordpress to show the author's data. So basically you could create a page and then use the_author_meta tags. For example the following code echoes the first and last name of a user whose name is stored in $userID:
<?php
$pagename = $userID;
echo the_author_meta(user_firstname, $userID );
echo the_author_meta(user_lastname, $userID );
?>
Please note that the variable $pagename is empty in case you use a static page as home page, but it is not your case.
Source: https://codex.wordpress.org/Template_Tags/the_author_meta

How do I disable the personal contact form option in the user edit form?

I am a Drupal beginner. When users create their account, they have the option to have a personal contact form. Where do I go to disable that? It's not in permissions. It's not a bad option, but I know it will confuse the hell out of my site's users. It may even scare some away!
Tested in Drupal 7.
Place the following in template.php of your theme. Change MYTHEME to your theme name.
function MYTHEME_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_profile_form') {
$form['contact']['#access'] = FALSE;
}
}
Notice that access is set to false, instead of being unset(), i.e. removed. That way we're not interfering with the flow of data.
If you visit admin/build/contact/settings in Drupal 6 or 5 you can untick "Enable personal contact form by default"
A personal contact form is not something you get by default in Drupal. There are modules that can do this, you have probably activated such a module. Check what modules you have activated at admin/build/settings.
If you want to disable this for regular users only you should instead check you permission settings.
Disable the Contact module under 'Core - Optional'. Look through user permissions for anything related to 'contact' and uncheck it.
Personally recommend Webform to handle site wide contact forms. It will let you construct your form with a UI. Easiest way to get a Contact Us page.
Drupal 7
All answers NOT remove the section for personal contact option displayed (D7) at "user/%/edit"
For remove tab AND settings for Drupal 7:
/**
* Implements hook_form_alter().
*/
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
if ('user_profile_form' === $form_id) {
$form['contact']['#access'] = FALSE;
}
}
/**
* Implements hook_preprocess_page().
*/
function MY_MODULE_preprocess_page(&$variables) {
$menu_items = menu_get_item();
if('user/%/edit' === $menu_items['path']){
$variables['page']['content']['content']['content']['system_main']['contact']['#access'] = FALSE;
}
}
After:
Drupal 6:
If you want to have the site-wide contact form enabled, but not even display the option for a personal contact form to your users you must follow these steps:
Create a custom module
http://www.hankpalan.com/blog/drupal/make-custom-drupal-module
Add this code to your .module file:
function your_module_name_form_user_profile_form_alter(&$form, &$form_state) {
unset ($form['contact']);
}
Either check what modules you have set on drupal, or check the settings for contact forms. I believe it has the option for site wide contact form and user contact form.
Use Contact permissions.
It provides a permission:
"Have a personal contact form" which allows
administrators to configure which roles get the ability to have a
"Personal contact form".
Also the Simplify module has a separate option for that.

Resources