• I’m writing my first plugin for displaying church services. When the user goes to the Manage Church Services section, created by the plugin, they see a list of church services in a table. If they want to edit one of these services, they click the edit link and are taken to a new page with an edit form on it. The form works and the record updates fine, but I would like them to be returned to the first manageservices.php page after the update has been done and I’m having problems with this.

    I thought that I could use

    $location = "edit.php?page=wpchurchservices/manageservices.php";
      wp_redirect($location);
      exit();

    But I get the following error message:

    Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\standrews\wp-admin\admin-header.php:16) in C:\wamp\www\standrews\wp-includes\pluggable.php on line 341

    So I’ve no idea where to go from here. I’m learning PHP whilst doing this, so not a great programmer.

Viewing 3 replies - 1 through 3 (of 3 total)
  • This error is caused because something has been output. This could be as little as a space. If the head has been output this will cause this. Also make sure there is no whitespace at the beginning or end of your file. If you would like me to look at the code let me know. [email protected]

    I would be interested to know if/how you’ve solved this issue!

    I have the same problem and when you look at the error message, you see that the HTML that has been output happens in wp-admin/admin-header.php before the plugin function that attempts to redirect is called which means that it seems to be out of the control of plugin authors…

    Or have I missed something?

    Thanks,

    Eric

    Hmmm… Digging into the code, I think that the best way to solve this kind of issue is to separate the plugin code so that everything that can lead to redirections are perfomed in an action registered as “load-<page-hook>”.

    This can be done by stuff such as:


    $page_hook = get_plugin_page_hook( plugin_basename(__FILE__), 'edit.php');
    add_action('load-'.$page_hook, 'my_function');

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘my first plugin – redirecting after update’ is closed to new replies.