Plugin Directory

source: remove-comment-url/trunk/remove-comment-url.php @ 3122076

Last change on this file since 3122076 was 3122076, checked in by freewebmentor, 16 months ago

Added new feature to remove the existing links

File size: 1.0 KB
Line 
1<?php
2/*
3Plugin Name: Remove Comment URL
4Plugin URI: https://www.premtiwari.in/remove-comment-url/
5Description: Allows administrators to globally disable the URL/Website input field from the WordPress inbuilt comments form on their site.
6Author: Prem Tiwari
7Version: 1.2.0
8Author URI: https://www.premtiwari.in/
9*/
10
11/**
12 * Function to unset the website field from the comments form.
13 * @param Array $fields
14 * @return Array
15 */
16function rcu_disable_comment_url( $fields ) {
17    if ( isset( $fields['url'] ) ) {
18        unset( $fields['url'] );
19        return $fields;
20    }
21}
22//We hook our function rcu_disable_comment_url with the filter comment_form_default_fields.
23add_filter('comment_form_default_fields','rcu_disable_comment_url');
24
25// Filter to remove the existing links from the comments.
26add_filter( 'get_comment_author_url', function( $url, $comment_ID, $comment ) {
27  if ( ! is_admin()
28      && $comment->user_id !== get_post()->post_author
29      && ! user_can( $comment->user_id, 'manage_options' )
30  ) {
31      return '';
32  }
33  return $url;
34}, 10, 3 );
Note: See TracBrowser for help on using the repository browser.