The MU forums have moved to WordPress.org

Cannon Modify Headers - query.php:390 (7 posts)

  1. AphelionZ
    Member
    Posted 14 years ago #

    (FYI this is wordpress mu 2.8.2 - I forgot to select the version number when I was posting this)

    Hello all,

    I'm developing a plugin which makes use of the wp_redirect function. You can see the relevant code here:

    However, when I try to run that code I get this error.

    Cannot modify header information - headers already sent by (output started at /path/to.site/wp-includes/query.php:390) in /path/to/site/wp-content/plugins/post_shock/postshock_core.php on line 53

    Now, I checked query.php and nothing on line 390 seems to be creating any whitespace or sending any header info at all, so I suspect the problem might be deeper. Any ideas or thoughts would be appreciated!

  2. SteveAtty
    Member
    Posted 14 years ago #

    And what is on line 53 of postshock_core.php?

    You've got a blank line after a closing ?> somewhere

  3. AphelionZ
    Member
    Posted 14 years ago #

    I swore I fixed all those but I'll go through with a fine toothed comb and report back.

  4. AphelionZ
    Member
    Posted 14 years ago #

    Yeah, even if i remove all the code except my action hook and the redirect it still gives me that warning and breaks the code. I even removed my closing php tag and everything. My plugin has no whitespace now.. so something has got to be going on in the core :p

  5. SteveAtty
    Member
    Posted 14 years ago #

    So what happens if you remove your hook and the redirect?

  6. AphelionZ
    Member
    Posted 14 years ago #

    I got it running now with no warnings, but it still doesn't redirect for some reason - and its not calling any errors! Here's the code in question:

    add_action('init', 'search_egg_redirect', 0);
    
    function search_egg_redirect() {
    	global $wpdb;
    	$query = $wpdb->prepare($_GET['s']);
    
    	if(!empty($query)) {
    		$term_row = $wpdb->get_row('SELECT term,page_id FROM pshock_searcheggs WHERE TERM="' . $query . '" LIMIT 1');
    		if($term_row->term) {
    			wp_redirect('http://google.com');
    		}
    	}
    }
  7. dsader
    Member
    Posted 14 years ago #

    Don't use wp_redirect in plugin.

    Instead workaround:

    // wp_redirect('http://google.com');
    $location = "http://google.com";
    echo "<meta http-equiv='refresh' content='0;url=$location' />";

    http://core.trac.wordpress.org/ticket/2860
    http://wordpress.org/support/topic/179091

About this Topic

  • Started 14 years ago by AphelionZ
  • Latest reply from dsader