我试图让我的插件的 register_settings 更干净一些。现在看起来是这样的:
add_action( 'admin_init', 'hpblogposts_register_settings' );
function hpblogposts_register_settings() {
register_setting( 'hpblogposts_settings_options_group', 'linkid01' );
register_setting( 'hpblogposts_settings_options_group', 'linktext01' );
register_setting( 'hpblogposts_settings_options_group', 'linkalt01' );
register_setting( 'hpblogposts_settings_options_group', 'linkid02' );
register_setting( 'hpblogposts_settings_options_group', 'linktext02' );
register_setting( 'hpblogposts_settings_options_group', 'linkalt02' );
register_setting( 'hpblogposts_settings_options_group', 'linkid03' );
register_setting( 'hpblogposts_settings_options_group', 'linktext03' );
register_setting( 'hpblogposts_settings_options_group', 'linkalt03' );
register_setting( 'hpblogposts_settings_options_group', 'linkid04' );
register_setting( 'hpblogposts_settings_options_group', 'linktext04' );
register_setting( 'hpblogposts_settings_options_group', 'linkalt04' );
register_setting( 'hpblogposts_settings_options_group', 'linkid05' );
register_setting( 'hpblogposts_settings_options_group', 'linktext05' );
register_setting( 'hpblogposts_settings_options_group', 'linkalt05' );
register_setting( 'hpblogposts_settings_options_group', 'linkid06' );
register_setting( 'hpblogposts_settings_options_group', 'linktext06' );
register_setting( 'hpblogposts_settings_options_group', 'linkalt06' );
}
对于每个“组”设置 register_settings 被调用 3 次。我试图让它更容易:
add_action( 'admin_init', 'hpblogposts_register_settings' );
function csHpBlogPostsSimplyRegisterSettings($id) {
register_setting( 'hpblogposts_settings_options_group', 'linkid'+$id );
register_setting( 'hpblogposts_settings_options_group', 'linktext'+$id );
register_setting( 'hpblogposts_settings_options_group', 'linkalt'+$id );
}
function hpblogposts_register_settings() {
csHpBlogPostsSimplyRegisterSettings('01');
csHpBlogPostsSimplyRegisterSettings('02');
csHpBlogPostsSimplyRegisterSettings('03');
csHpBlogPostsSimplyRegisterSettings('04');
csHpBlogPostsSimplyRegisterSettings('05');
csHpBlogPostsSimplyRegisterSettings('06');
}
但它不能以这种方式工作(不保存值)。
知道我在哪里犯了错误吗?