传递文件的完整路径
/wp-content/plugins/your-plugin/errors.txt
到
fopen
具有
plugin_dir_path()
:
$file = plugin_dir_path( __FILE__ ) . '/errors.txt';
$open = fopen( $file, "a" );
以下是一个最小示例:
add_action( 'get_header', 'mail_me_errors' );
function mail_me_errors() {
if ( is_404() ) {
email_admin( $_SERVER['REQUEST_URI'] );
}
}
function email_admin( $location ) {
$time = date( "F jS Y, H:i", time()+25200 );
$ban = "#$time\r\n$location\r\n";
$file = plugin_dir_path( __FILE__ ) . '/errors.txt';
$open = fopen( $file, "a" );
$write = fputs( $open, $ban );
fclose( $open );
}