skip to Main Content

I have just started learning wordpress plugin development and got this error when I access the my plugin menu from admin.

Here is the code: importer.php

//*************** Admin function ***************
function oscimp_admin() {
    include('importer_admin.php');
}

function oscimp_admin_actions() {
    add_options_page("OSCommerce Product Display", "OSCommerce Product Display", 1, "OSCommerce Product Display", "oscimp_admin");
}

add_action('admin_menu', 'oscimp_admin_actions');

importer_admin.php

<div class="wrap">
<?php    echo "<h2>" . __( 'OSCommerce Product Display Options', 'oscimp_trdom' ) . "</h2>"; ?>

<form name="oscimp_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
    <input type="hidden" name="oscimp_hidden" value="Y">
    <?php    echo "<h4>" . __( 'OSCommerce Database Settings', 'oscimp_trdom' ) . "</h4>"; ?>
    <p><?php _e("Database host: " ); ?><input type="text" name="oscimp_dbhost" value="<?php echo $dbhost; ?>" size="20"><?php _e(" ex: localhost" ); ?></p>
    <p><?php _e("Database name: " ); ?><input type="text" name="oscimp_dbname" value="<?php echo $dbname; ?>" size="20"><?php _e(" ex: oscommerce_shop" ); ?></p>
    <p><?php _e("Database user: " ); ?><input type="text" name="oscimp_dbuser" value="<?php echo $dbuser; ?>" size="20"><?php _e(" ex: root" ); ?></p>
    <p><?php _e("Database password: " ); ?><input type="text" name="oscimp_dbpwd" value="<?php echo $dbpwd; ?>" size="20"><?php _e(" ex: secretpassword" ); ?></p>
    <hr />
    <?php    echo "<h4>" . __( 'OSCommerce Store Settings', 'oscimp_trdom' ) . "</h4>"; ?>
    <p><?php _e("Store URL: " ); ?><input type="text" name="oscimp_store_url" value="<?php echo $store_url; ?>" size="20"><?php _e(" ex: http://www.yourstore.com/" ); ?></p>
    <p><?php _e("Product image folder: " ); ?><input type="text" name="oscimp_prod_img_folder" value="<?php echo $prod_img_folder; ?>" size="20"><?php _e(" ex: http://www.yourstore.com/images/" ); ?></p>


    <p class="submit">
    <input type="submit" name="Submit" value="<?php _e('Update Options', 'oscimp_trdom' ) ?>" />
    </p>
</form>
</div>

Any one can figure out what I am doing wrong.

7

Answers


  1. Chosen as BEST ANSWER

    The problem is fourth parameter. I have removed the spaces from the fourth parameter with _ and it works.

    Thanks for your help...


  2. write your importer_admin.php file code inside oscimp_admin() function or use php file_get_contents function.

    Login or Signup to reply.
  3. I just tried to change the 4th parameter in add_options_page with basename(_FILE_); should be the same value with “importer.php” in your case. I don’t know exactly what it should be changed to, but it’s work!

    Good luck!

    Login or Signup to reply.
  4. The actual tutorial can be find HERE. And it should work with 2.9.2 version of WordPress, at least it works for me. But, when I try to run the code of the tutorial with version 3.1 it give me the same error. But as mention by Avinash the line

    add_options_page(“OSCommerce Product Display”, “OSCommerce Product Display”, 1, “OSCommerce Product Display”, “oscimp_admin”);
    

    Should be replace with

    add_options_page(“OSCommerce Product Display”, “OSCommerce Product Display”, 1, “OSCommerce_Product_Display”, “oscimp_admin”);
    

    and then it works properly. Hope it helps some one.

    UPDATE:

    As rightly stated by Francisco Corrales at below comment you may consider to Deactivate the Plugin & Activate it again if you are not seeing the changes.

    Login or Signup to reply.
  5. Yes, Forth parameter is Unique name, and for any Unique identifier it should contain space, That’s the issue 🙂

    Login or Signup to reply.
  6. On WordPress 3.6.1 not even underscores work anymore. The function should now be:

    function oscimp_admin_actions() {
        add_options_page("OSCommerce Product Display", "OSCommerce Product Display", 1, "OSCommerceProductDisplay", "oscimp_admin");
    }
    
    Login or Signup to reply.
  7. One possible cause of this error is actually registering admin menus on admin_init action hook, instead of admin_menu. This is not the case here, but it is good to share this information, since it took me hours to figure that out.

    So always register your menus like this (and remove spaces or any other non alphanumeric characters from the unique slug – the 4th parameter of the function add_options_page() ):

    Initially

    add_action('admin_menu', 'your_function');
    

    and then (check first if function exists)

    if (!function_exists('your_function')) {
        function your_function() {
            add_options_page(__("Option page name","your-text-domain"), __("Option page name","your-text-domain"), 'manage_options', 'your-page-unique-slug', 'other_function');
        }
    }
    

    Note the usage of __() function instead of directly placing the titles – it is necessary for internationalization of your plug-in (and it displays the quoted text if there are no internationalization files).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search