douniwan_0025 2013-06-18 22:01
浏览 153
已采纳

防止直接访问Wordpress插件中的php文件

I am building a Wordpress plugin that should be used on my site only. I have placed it at the regular place under wp-content/plugins/myPlugin. In that directory I have placed an index.php to prevent directory listing and also hide the fact that there is a directory with the name myPlugin by sending the request to 404-page of wordpress. The code:

include ('../../../wp-load.php');
header("HTTP/1.0 404 Not Found - Archive Empty");
$wp_query->set_404();
require TEMPLATEPATH . '/404.php';
exit;

This though do not hinder anyone from accessing my php file on myurl.com/wp-content/plugins/myPlugin/myPlugin.php. How can I achieve the same 404 for this and other php files in my plugin? It is important to note that these files should be accessible via Wordpress admin though. Maybe wordpress admin sets some global variable when I am accessing a php file via myurl.com/wp-admin/admin.php?page=myPlugin/myPlugin.php ?

  • 写回答

2条回答 默认 最新

  • dongtun1872 2013-06-19 05:22
    关注

    Adding to Sammitch's answer, that's what you can use for WordPress:

    defined('ABSPATH') or die("Your message here");
    

    ABSPATH is defined in wp-load.php:

    /** Define ABSPATH as this file's directory */
    define( 'ABSPATH', dirname(__FILE__) . '/' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误