I m 创建一个简单的 WordPress 插件, 该插件将在 设置 菜单中设置一个选项页面, 供客户端添加业务细节 。
我登记我所有田地的地址是:
// Lets set an array for the inputs:
$fields = array (
array( "name", "Business Name:"),
array( "tagline", "Business Tagline:"),
array( "logo", "Business Logo:"),
array( "owner_name", "Owner s Name:"),
array( "owner_title", "Owner s Title"),
array( "address", "Address:"),
array( "city", "City:"),
array( "province", "Province:"),
array( "country", "Country:"),
array( "phone", "Phone:"),
array( "secondary_phone","Secondary Phone:"),
array( "fax", "Fax:"),
array( "toll_free", "Toll Free:"),
array( "email", "Email:"),
array( "website", "Website:"),
);
foreach($fields as $field) {
//id, title (label), callback, page, section(from add_settings_section), args
add_settings_field("business_{$field[0]}", $field[1], "business_{$field[0]}_setting", __FILE__, main_section );
}
此简单的环绕在数组中的设置, 添加所有我需要的字段, 并用 < code> business@$field > 设置回调函数的引用 。 [0] __ 设置 。
然后,我必须给每一个人创建回调功能,比如:
function business_name_setting() {
$options = get_option( plugin_options );
echo "<input name= plugin_options[business_name] type= text value= {$options[ business_name ]} />";
}
我假设有更优雅的方式这样做, 因为单凭个人创造所有回声 将是极其多余的, 当它们基本上会是相同的时。