WordPress Plugin add_option feature

Dear WP Developers,

I am currently making a wordpress plugin that have lots settings options for user, i added many settings options by using this function: add_option("myfieldID", '', '', 'yes');

Now after 60% plugin development i have around 20 settings options so i am little confuse is this way i am making plugin right or i have to use register_settings fuction, If i am doing wrong plz correct me.

Currently i am calling plugin activation hook and during activation function i add options settings fields.

 /* plugin activation*/
register_activation_hook(__FILE__,'YT_allinOne_install'); 

function YT_allinOne_install() {
add_option("myfieldID", '', '', 'yes');
add_option("myfieldID2", '', '', 'yes');
add_option("myfieldID3", '', '', 'yes');
add_option("myfieldID4", '', '', 'yes');
}

Is this way right or wrong? Plz guide me accordingly thanks

You should check WordPress documentation. Function add_option is saving specified value into database wp_options table. This code will save set of options and values into database, nothing more.

Yeah this is clear, but i saw few plugins code that use REGISTER_SETTINGS instead add_options so i’m confuse which one should i use, second this plugin going to sell on the codecanyon so i want don’t want any rejection after such long effort :slight_smile:

I prefer not to use WordPress settings API. When plugin has large number of options, it is better for use an maintenance to have own API for working with settings. But, there are plenty of tutorials on the internet on how to do that. Here is the Plugins Development Guide and section on settings API: https://developer.wordpress.org/plugins/settings/settings-api/

Better to use one string to keep the data at the same place.

String? not clear what you mean i am asking which one is better add_option or register_settings for wordpress plugin option panel.