I want to register an option when my plugin is activated to be used in the settings page.

My first attempt:

function jpsNews_activate_plugin() {
    register_setting( 'jps_settings_group', 'jps_test');
register_activation_hook(__FILE__, 'jpsNews_activate_plugin');

Second attempt:

function jpsNews_activate_plugin() {
    add_action( 'admin_init', 'jps_settings' );
register_activation_hook(__FILE__, 'jpsNews_activate_plugin');

function jps_settings() {
    register_setting( 'jps_settings_group', 'jps_test');

When i go to the database and search for that option, nothing is found. What am i missing? Can i do it like this?

Thanks in advance.


This is how i did the settings page:

function jps_mail_list_page_entry() {
    __('JPS Mailing List'),
    'JPS Mailing List',
add_submenu_page('jpsNews_mailinglist', 'Settings', 'Settings', 'manage_options', 
 'mailinglist-settings', 'snaq_mailing_settings');
add_action('admin_menu', 'jps_mail_list_page_entry');
  • Hi. I'm confused about what you are trying to do. This should be hooked into admin-init as far as I know, not plugin activation. – Jack Johansson Jul 4 '17 at 17:16
  • this is the first time im seeing this so im a litle confused also. Im trying to add an options page to my plugin and save those options in the database. As i said, i dont even know if its possible to do it on plugin activation. – eskimopest Jul 4 '17 at 17:56
  • Well your question is actually two questions. 1) How to add an option page 2) How to save some defaults values on activation. Right? – Jack Johansson Jul 4 '17 at 17:58
  • I know how to add a page. I already have a page for the settings (empty for now). I just cant create the options i want to use in that page. – eskimopest Jul 4 '17 at 18:02
  • 1
    Creating a plugin option page and saving/sanitizing the options takes more than that. here is my answer about a fully working option page. See if you can get it to work. – Jack Johansson Jul 4 '17 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.