为什么在Wordpress钩子中使用__FILE__?

时间:2013-09-11 21:17:31

标签: php

我正在查看Wordpress插件的代码,以了解他们在激活插件时如何创建和添加数据库表。

    // Activation hook for creating the initial DB table
    register_activation_hook(__FILE__, 'add_db_table');

add_db_table是一个创建表的函数,我理解并且如何创建该函数,但register_activation_hook的目的是在激活插件时添加它。我真的很想知道为什么他们使用__FILE__

我只想完全理解,谢谢!

1 个答案:

答案 0 :(得分:1)

http://codex.wordpress.org/Function_Reference/register_activation_hook

register_activation_hook [ WordPress Functions ]
register_activation_hook ( $file, $function ) 

Parameters: 
    (string) $file The filename of the plugin including the path.
    (callback) $function the function hooked to the 'activate_PLUGIN' action.

为什么WordPress函数使用filename作为参数:

function register_activation_hook($file, $function) {
    $file = plugin_basename($file);
    add_action('activate_' . $file, $function);
}
相关问题