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