使用插件删除WordPress的license.txt

Rya*_*yan 2 php wordpress wordpress-plugin

我想写一个插件HTTP 404在用户请求时 返回license.txt,action钩子是什么(有效和有效的阻止方式)?

更新:

因为我无法控制Web服务器,所以我必须将其作为插件执行

J. *_*ong 8

Solution is actually pretty straightforward. You need to create plugin which writes to .htaccess.

  1. In the /wp-content/plugins create licence_redirect folder.
  2. In that folder create licence_redirect.php file.
  3. Paste code below to this licence_redirect.php php file:
<?php
/*
Plugin Name: Licence redirect
Description: Redirects license.txt. to 404
Author: J. Wrong
Version: 0.1
*/
?>
<?php
function lr_flush_rewrites() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

function lr_add_rewrites() {
    global $wp_rewrite;
    $lr_wp_rules = array(
        'license\.txt$' => '[R=404,L]',
    );

    $wp_rewrite->non_wp_rules = $lr_wp_rules + $wp_rewrite->non_wp_rules;
}

register_activation_hook( __FILE__, 'lr_flush_rewrites' );
add_action('generate_rewrite_rules', 'lr_add_rewrites');
Run Code Online (Sandbox Code Playgroud)
  1. 安装并激活插件.
  2. 在管理员面板中,转到设置 - >永久链接
  3. 按保存更改从现在开始,license.txt请求将被重定向到404.如果您无法在服务器上创建文件夹,则需要压缩插件的文件夹并使用WP admin上传.干杯......现在正在计算赏金:P