GH-28 Refactor code to add setting fields from an array#32
GH-28 Refactor code to add setting fields from an array#32sudhir-yadav wants to merge 5 commits intomainfrom
Conversation
| foreach ( $script_settings as $option_name => $settings ) { | ||
|
|
||
| add_settings_field( | ||
| $settings[ 'id' ], | ||
| $settings[ 'title' ], | ||
| $settings[ 'callback' ], | ||
| $settings[ 'page' ], | ||
| $settings[ 'section' ] | ||
| ); | ||
|
|
||
| register_setting( 'rt-scripts-optimizer-settings', $option_name ); |
There was a problem hiding this comment.
Hi @sudhir-yadav @pradeep910, This is the exact same code that we had earlier just shorten by adding a foreach loop. I think we need to register only 1 settings and fetch other settings by array key. Something similar to below code.
// Define default array
$defaults = array(
'setting_1' => 'default_value_1',
'setting_2' => 'default_value_2',
);
// Register the setting
register_setting( 'my_settings_group', 'my_array_setting', array(
'type' => 'array',
'default' => $defaults,
) );
// Update code that uses the setting
$options = get_option( 'my_array_setting', $defaults );
$setting_1 = $options['setting_1'];
$setting_2 = $options['setting_2'];
Of course we need to handle for the settings that are saved with standalone options after implementing above. This is my suggestion, and it would best because we need to call just one option and that would be stored in an array we can fetch by array key.
There was a problem hiding this comment.
Also settings callback would be same, there would be no change, just option fetch from settings key.
|
@hbhalodia Rechecking this, is the changes relevant and settings work with all our features or we can archive this? |
Hi @pradeep910, I guess this are still relevant, and can be updated, but need to make sure it account backward compatibility. We can assign to someone which can take up this PR or create a new one for Issue - #28 |
This PR refactors the current settings to a single array of fields in one setting.