WordPress: register_settings helper -
im trying make register_settings little bit cleaner plugin. looks way:
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' ); }
for each "group" of settings register_settings called 3 times. trying make easier:
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'); }
but doesnt work way (values not saved).
any idea have made mistake?
for one, when you're concatenating strings should use dot, not plus:
register_setting( 'hpblogposts_settings_options_group', 'linkalt' . $id );
Comments
Post a Comment