Forums

[resolved] I am trying to add an Admin Menu to plugin and it screws up (2 posts)

  1. Vistory
    Member
    Posted 2 years ago #

    This is the code from WORD PRESS CODEX

    <?php
    add_action('admin_menu', 'my_plugin_menu');

    function my_plugin_menu() {
    add_options_page('My Plugin Options', 'My Plugin', 8, 'your-unique-identifier', 'my_plugin_options');
    }

    function my_plugin_options() {
    echo '<div class="wrap">';
    echo '<p>Here is where the form would go if I actually had options.</p>';
    echo '</div>';
    }
    ?>

    I copy it, and literally and it does not work.

    When I made adjustments it does not work.

    I get these messages

    Warning: Cannot modify header information - headers already sent by (output started at /home/kieran/public_html/sampletucson/wp-content/plugins/permalinkboxcontroller.php:12) in /home/kieran/public_html/sampletucson/wp-login.php on line 287

    Warning: Cannot modify header information - headers already sent by (output started at /home/kieran/public_html/sampletucson/wp-content/plugins/permalinkboxcontroller.php:12) in /home/kieran/public_html/sampletucson/wp-login.php on line 299

    Warning: Cannot modify header information - headers already sent by (output started at /home/kieran/public_html/sampletucson/wp-content/plugins/permalinkboxcontroller.php:12) in /home/kieran/public_html/sampletucson/wp-includes/pluggable.php on line 689

    I tried using __FILE__ as the identifier and that did not work either.

    HELP!

    I think 2.8 is not compatible with old menu codes.

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    Try this, i know this works because i've just pulled it from a basic plugin i have running on 2.8...

    <?php
    add_action('admin_menu', '_add_options');
    
    function _add_options() {
    	if (function_exists('current_user_can')) {
    		if (!current_user_can('manage_options')) return;
    	}
    	else {
    		global $user_level;
    		get_currentuserinfo();
    		if ($user_level < 8) return;
    	}
    	if (function_exists('add_options_page')) {
    		add_options_page('Title for the page', 'TheMenuTitle', 8, __FILE__, 'yourfunction');
    	}
    }
    
    function yourfunction() {
    
    	echo 'Hello World';
    }
    
    ?>

    Hope that helps...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags