我有很多自定义帖子类型,我想在同一个函数中创建它们,所以在创建自定义帖子类型时,有没有方法向函数发送参数。
我在想这样的事情:
function custom_poster($pluralName, $singularName) {
// Create custom post type
}
add_action( \'init\', \'custom_poster\' );
我有很多自定义帖子类型,我想在同一个函数中创建它们,所以在创建自定义帖子类型时,有没有方法向函数发送参数。
我在想这样的事情:
function custom_poster($pluralName, $singularName) {
// Create custom post type
}
add_action( \'init\', \'custom_poster\' );
如果不考虑向后兼容性(仅在PHP 5.3及更高版本下运行时有效),可以使用匿名函数:
add_action( \'init\', function() {
$pluralName = \'PluralName\';
$singularName = \'SingularName\';
custom_poster( $pluralName, $singularName );
}
);
或关闭$singularName = \'Singular Name\';
$pluralName = \'Plural Name\';
add_action( \'init\', function() use ($singularName, $pluralName) {
custom_poster( $pluralName, $singularName );
} );