Forums

[resolved] Get 'Headers Already Sent' error when logging in for new plugin (2 posts)

  1. MeltingDog
    Member
    Posted 1 year ago #

    I am trying to create my first plugin. So far it actually works fine but for one error:

    I get a 'Headers Already Sent' PHP message when I try to login to wp-admin.

    If I remove the plugin file from the wpcontent/plugins directory, login as usual, then replace the plugin file it works fine - this just seems to occur with login in and out.

    My (abridged) code is:

    <?php
    /*
    Plugin Name: Product Manager
    Plugin URI: http://www.tech-knowledge.com.au
    Description: Add, edit and remove products
    Version: 1.0
    Author: Me
    Author URI: http://www.tech-knowledge.com.au
    License: Restricted
    */
    
    if ( is_admin() ){
    /* Call the html code */
    add_action('admin_menu', 'prodmanager_admin_menu');
    
    function prodmanager_admin_menu() {
    add_options_page('Product Manager', 'Product Manager', 'administrator',
    'product-manager', 'prodmanager_html_page');
    }
    }
    
    function prodmanager_html_page() {
    ?>
    
    <div>
    
    <h2>Product Manager</h2>
    <!--usual HTML and PHP Code-->
    </div>
    ?>

    Let me know if you would like to see it all.

    Any advice would be really, really appreciated!

    Thanks!

  2. MeltingDog
    Member
    Posted 1 year ago #

    HI all,

    I have found the issue. I had a closing php tag: ?> at the end of my code. This should not occur in plaugins

Topic Closed

This topic has been closed to new replies.

About this Topic