| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Disable Author Archives |
| 4 |
* Plugin URI: https://wordpress.org/plugins/disable-author-archives |
| 5 |
* Description: Disables author archives and makes the web server return status code 404 ('Not Found') instead. |
| 6 |
* Version: 1.3.5 |
| 7 |
* Author: freemp |
| 8 |
* Author URI: https://profiles.wordpress.org/freemp |
| 9 |
* Text Domain: disable-author-archives |
| 10 |
* License: GPL v2 or later |
| 11 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 15 |
|
| 16 |
/* Return status code 404 for existing and non-existing author archives. */ |
| 17 |
add_action( 'template_redirect', |
| 18 |
function() { |
| 19 |
if ( isset( $_GET['author'] ) || is_author() ) { |
| 20 |
global $wp_query; |
| 21 |
$wp_query->set_404(); |
| 22 |
status_header( 404 ); |
| 23 |
nocache_headers(); |
| 24 |
} |
| 25 |
}, 1 ); |
| 26 |
|
| 27 |
/* Remove author links. */ |
| 28 |
add_filter( 'user_row_actions', |
| 29 |
function( $actions ) { |
| 30 |
if ( isset( $actions['view'] ) ) |
| 31 |
unset( $actions['view'] ); |
| 32 |
return $actions; |
| 33 |
}, PHP_INT_MAX ); |
| 34 |
add_filter( 'author_link', function() { return '#'; }, PHP_INT_MAX ); |
| 35 |
add_filter( 'the_author_posts_link', 'get_the_author', PHP_INT_MAX ); |
| 36 |
|
| 37 |
/* Remove users from default sitemap. */ |
| 38 |
if ( class_exists( 'WP_Sitemaps' ) ) |
| 39 |
add_filter( 'wp_sitemaps_add_provider', |
| 40 |
function( $provider, $name ) { |
| 41 |
if ( $name === 'users' ) |
| 42 |
return false; |
| 43 |
return $provider; |
| 44 |
}, PHP_INT_MAX, 2 ); |