• clarke1866

    (@clarke1866)


    For more details, please see this post. This is the shortform:

    I need help on inserting the proper code into the wordpress admin backend to allow a user to edit the various options of my created plugin. I have read extensively on the subject, but since I am a learning php from scratch (with very limited programming background) I am just going in circles. It seems the wordpress codex is written by developers for developers, which is fine, except that I am missing some key chunks of basic knowledge (for example, why do I need to define my own functions?). Anyway:

    How can I insert my options form into wordpress? — My present form is self submitting, and writes the configuration to an ini file in the plugins’ own directory (flat file).

    From my research I have figured out that I need something like the following code in a file in the /wp-content/plugins/ directory:

    /*
    Plugin Name: WP-My Name
    Plugin URI: someurl
    Description: Blah.
    Version: 0.001
    Author: Me
    Author URI: someurl
    */

    add_options_page(__("Plugin Test Page"), __('PlugTest'), 5, plugdir(__FILE__) .'form.php');

    At which point the form.php would take over by including and reading the ini file, and various other files in the plugdir.

    The problem is that this doesn’t work. What am I doing wrong? I have tried looking at other authors methods, but frankly what they do is way over my head. I need a simple example.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    Thread Starter clarke1866

    (@clarke1866)

    Thanks for the reply, but I have already read and tried those examples, and they don’t seem to work. To make it simple, what code would I need to surround the following code to allow for it to be displayed in the admin backend:

    echo “really stupid example”;
    die;

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    I’m not a plugin developer, so I’m really not sure. Spam Karma and WP-ContactForm both add options to the Options menu, but both use different methods. You may want to dissect them and see how they accomplish that.

    http://www.unknowngenius.com/blog/wordpress/spam-karma/

    http://ryanduff.net/wp-plugins/wp-contactform/

    demuretwilight

    (@demuretwilight)

    maybe you already totally realize this (are are having a different problem), but just in case:
    php code all has to be enclosed by tags <? and ?> (or you can use <?php and ?>)

    so

    echo “really stupid example”;
    die;

    won’t do what you want unless you enclose it:

    <?
    echo “really stupid example”;
    die;
    ?>

    Thread Starter clarke1866

    (@clarke1866)

    Thanks, I do. But me and these forums have a disagreement on pasting code, so I don’t paste the ?’s anymore. Thanks for the reply!

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    If you want to post code, post it in backticks (the key to the left of the 1 key).

    Ex:

    <?php
    echo "really stupid example";
    die;
    ?>

    Thread Starter clarke1866

    (@clarke1866)

    Macmanx, do you knno that nowhere does it say what backticks are! Thanks for filling me in!
    ‘<?php
    echo “Knowing is half the battle”
    ?>’

    lisch

    (@lisch)

    I tried copying the text directly from <http://codex.wordpress.org/Adding_Administration_Menus&gt;, and it adds all the right menu items, but the actual pages are blank. That is, they have the proper headers and footers, but none of the content that should be there.

    It’s as though the hook functions are never being called.

    I have WordPress 1.5, PHP 4.3.10.

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    Those are just examples. You cannot copy/paste and expect them to work. You need to define page_title, menu_title, access_level, file, and [function].

    lisch

    (@lisch)

    The example provides values for those arguments, or do I misunderstand? I am referring to the big example at the bottom of the page I referenced. It defines functions for the options page, manage page, etc. It calls add_options_page, add_management_page, etc., providing arguments for the page_title, menu_title, etc., parameters.

    When I install the file in the plugins directory, and activate the plugin, the correct menu items are added, so the basic calls to add_options_page, etc., work just fine. The problem is that the functions that are registered in those calls do not seem to be called. When I select the Test pages for the Top level, Options, etc., I get a page with a standard header and footer, but nothing in between.

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    Ah, it looks like you’ve fallen to bug #902: http://mosquito.wordpress.org/view.php?id=902

    You can either download the patch provided, grab the latest /wp-admin/menu-header.php file from http://trac.wordpress.org/ , or wait for WordPress v1.5.1.

    I’d recommend grabbing the latest /wp-admin/menu-header.php file from http://trac.wordpress.org/ .

    lisch

    (@lisch)

    Thank you! Thank you! Thank you!
    It works now.

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    You’re welcome. Sorry I didn’t think about that sooner.

    Thread Starter clarke1866

    (@clarke1866)

    I’ll give this a try too. Thanks for the update.

    Thread Starter clarke1866

    (@clarke1866)

    Ok I updated menu-header.php, cut and pated the code from http://codex.wordpress.org/Adding_Administration_Menus, and I still don’t get it. What am I doing wrong? Here is my code:

    /*
    Plugin Name: Menu Test
    Plugin URI: http://wordpress.org
    Description: Menu Test II
    Author: Nobody
    Author URI: http://example.com
    */

    // mt_add_pages() is the sink function for the 'admin_menu' hook
    function mt_add_page() {
    // Add a new menu under Options:
    add_options_page('Test Options', 'Test Options', 8, __FILE__, 'mt_options_page');
    }

    // mt_options_page() displays the page content for the Test Options submenu
    function mt_options_page() {
    echo "<h2>Test Options</h2>";
    }

    // Insert the mt_add_pages() sink into the plugin hook list for 'admin_menu'
    add_action('admin_menu', 'mt_add_page');

    A link in the options backend to test menu is provided however, upon viewing it the error is “Invalid plugin page.”

    I’m stumped. All I want is a menu page in the backend that will echo "this text is your menu page or some such thing";.

    Any help? Thanks again for all your previous help.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Adding admin menu functionality’ is closed to new replies.