Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am writing my first plugin and to access/save options I follow codex.wordpress.org/Creating_Options_Pages I basically copied the example from 'See It All Together' in a separate file mhomepage_admin_menu.php

The main code of the plugin goes like

if ( is_admin() ){ // admin actions
    add_action('admin_menu', 'add_plugin_admin_page' );
    add_action('admin_init', 'register_mhomepage_settings' );

} else {
  // non-admin enqueues, actions, and filters
}

function register_mhomepage_settings() { // whitelist options
  register_setting( 'mhomepage_option_group', 'left_right_margin_option' );
  register_setting( 'mhomepage_option_group', 'top_margin_option' );
  register_setting( 'mhomepage_option_group', 'include_comments_option' );
}  

function add_plugin_admin_page($plugin_name) {
    add_menu_page( 'mHomePage', 'mHomePage', 'manage_options', 'mhomepage/mhomepage_admin_menu.php', '', '', 6 );

}

and the beginning of mhomepage_admin_menu.php looks like

<div class="wrap">
<h2>Your Plugin Name</h2>

<form method="post" action="options.php">
    <?php settings_fields( 'mhomepage_option_group' ); ?>
    <?php do_settings( 'mhomepage_option_group' ); ?>
    <table class="form-table">

I have to questions

  • Q1: how to fix the error?
  • Q2: what is the correct file name in <form method="post" action="options.php">? Is that mhomepage_admin_menu.php?
share|improve this question
    
You have not provided a callback function for your page in the add_menu_page call, it should reference a function to execute when that page is requested. You've registered a slug for the page(4th param), but no function to call(5th param - it should refer to a function and not a file - even though you've included neither in the above code). –  t31os Aug 18 '13 at 13:04
    
Additionally, that is_admin conditional at the top of your code is not required, those actions only run on the admin end, so the conditional is unnecessary. –  t31os Aug 18 '13 at 13:06
    
A quote from codex.wordpress.org/Function_Reference/add_menu_page : $menu_slug (string) (required) The slug name to refer to this menu by (should be unique for this menu). If the function parameter is omitted, the menu_slug should be the PHP file that handles the display of the menu page content This part is working fine, not sure what you are pointing out here. –  Radek Aug 18 '13 at 23:32
add comment

2 Answers 2

up vote 1 down vote accepted

Q1: [H]ow to fix the error?

Stop calling the do_settings() function in this line. It is not a WordPress function and it is apparently not a function that you have defined. Perhaps you meant to use one of these functions.

<?php do_settings( 'mhomepage_option_group' ); ?>

Q2: [W]hat is the correct file name in <form method="post" action="options.php">?

options.php
share|improve this answer
    
Q2: if I used your code I get The requested URL /wp-admin/mhomepage/mhomepage_admin_menu.php was not found on this server. The php file is in the plugin directory. –  Radek Aug 18 '13 at 6:07
    
Q2: If I use simply options.php I can save :-) I will accept your answer if you update it ... –  Radek Aug 18 '13 at 6:10
    
Okay. Thank you. –  Charles Clarkson Aug 18 '13 at 6:26
add comment

Check WP Error Fix plugin http://wordpress.org/plugins/wp-bug-tracker/. It can fix this type of error automatically. I'm using it and it works great.

share|improve this answer
    
A bug-tracking plugin isn't the solution to fix something, it just do the detection. –  Mayeenul Islam Oct 29 '13 at 13:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.