Link to home
Start Free TrialLog in
Avatar of blatantwaste
blatantwasteFlag for United States of America

asked on

How to resolve this error caused by plugin: Warning: Cannot modify header information****

Alright, I've been beating my brains out trying to fix this one but it's not getting any better.

I'm working with someone on a plugin that will insert a social bookmarking menu into each wordpress post. It allows them to choose which sites they'd like to display, as well as whether to display the menu before or after each post.

The problem is, the plugin will activate fine. However, once it's activated nobody can comment without it throwing a mysql error:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\wordpress\wp-content\plugins\wp-social-bookmark-menu\wp-social-bookmark-menu.php:1) in C:\xampplite\htdocs\wordpress\wp-includes\pluggable.php on line 850

Now, even though it gives that error... It actually still posts the comment. Also, if you try to deactivate the plugin you get the same error, but if you refresh when you get the error it shows that the plugin has been deactivated.

I'm using Xampp and wordpress 2.7.1


I know that this error is most generally caused by excess whitespace betweeen php code blocks... but I can't find any extra space before or after the <? or ?>

I've attached the full code for the plugin below:
<?php
/*
Plugin Name: wp social bookmark menu
Plugin URI: http://wordpress.org/extend/plugins/wp-social-bookmark-menu/
Description: Add a social bookmarking links. Thanks to <a target="_blank" href="http://eight7teen.com/about">eight7teen</a> for original ideaa and base code. See <a href="options-general.php?page=wp-social-bookmark-menu.php">configuration panel</a> for more settings. For more info and plugins visit <a href="http://labs.saidmade.com">Labs Saidmade</a>
Version: 1.0
Author: Giovambattista Fazioli
Author URI: http://www.undolog.com
*/
 
//if(basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) die();
define('PLUGINNAME','WP-SOCIAL-BOOKMARK-MENU');
define('OPTIONSKEY','WP-SOCIAL-BOOKMARK-MENU');
define('OPTIONSTITLE','Social Bookmark Menu');
define('VERSION','1.0');
define('WP_CONTENT_URL', get_option('siteurl').'/wp-content');
define('WP_PLUGINS_PATH',WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)).'/');
 
 
/**
 * INIT OPTIONS
 *
 * The default options are stored in this array (key => default value)
 * The global plugin variables have a $wpp_ prefix (wordpress plugin)
 */
$wpp_options = array(
'position' => 'onthebottom','bookmark' => array('scriptstyle','blinklist','delicious','digg','furl','reddit','yahoomyweb','stumbleupon','technorati','mixx','myspace','designfloat','facebook')
);
 
/**
 * Add to Wordpress options database
 */
add_option(OPTIONSKEY, $wpp_options, OPTIONSTITLE);
 
/**
 * re-Load options
 */
$wpp_options = get_option(OPTIONSKEY);
 
 
// ________________________________________________________________________________________ OPTIONS
 
/**
 * ADD OPTION PAGE TO WORDPRESS ENVIRORMENT
 *
 * Add callback for adding options panel
 *
 */
function wpp_options_page() {
	if (function_exists('add_options_page')) {
		add_options_page(OPTIONSTITLE, OPTIONSTITLE, 8, basename(__FILE__), 'wpp_options_subpanel');
	}
}
 
/**
 * Draw Options Panel
 */
function wpp_options_subpanel() {
	global $wpp_options, $_POST;
	$any_error = "";										// any error flag
	if(isset($_POST['flag_save'])) {						// have to save options
		$any_error = 'Your settings have been saved.';
		
		/**
		 * Check for any missing or wrong POST value
		 */
		if($_POST['position'] == '') {		
			$any_error = 'Some field is empty! Check and try again!';
			} else {
			$wpp_options['position'] = $_POST['position'];
			$wpp_options['bookmark'] = $_POST['bookmark'];
			update_option(OPTIONSKEY, $wpp_options);
	}
}
	
	/**
	 * Show error or OK
	 */
	if($any_error != '') echo '<div id="message" class="updated fade"><p>'.$any_error.'</p></div>';
	
	/**
	 * INSERT OPTION
	 *
	 * You can include a separate file: include ('options.php');
	 *
	 */
?><div class="wrap">
    <h2>WP Social Bookmark Menu</h2>
	
	<form name="wp-social-bookmark-menu" id="wp-social-bookmark-menu" action="" method="post">
		<input type="hidden" name="flag_save" value="1" />
		  
		  <table width="300" cellpadding="4" cellspacing="0">
 
		  <tr>
		  <td align="right" valign="top" nowrap><label for="position">Position:</label> </td>
		  <td>
		  	  <input <?php echo (($wpp_options['position'] == "onthetop")? 'checked="checked"' : ""); ?> name="position" id="position" type="radio" value="onthetop" /> On the top<br/>
		  	  <input <?php echo (($wpp_options['position'] == "onthebottom")? 'checked="checked"' : ""); ?> name="position" id="position" type="radio" value="onthebottom" /> On the bottom
		  </td>
		  </tr>
		  
		  <tr>
		   <td align="right" valign="top" nowrap><label for="position">Choose Bookmark:</label> </td>
		  <td>
		  	  <input <?php echo (@in_array("scriptstyle", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="scriptstyle" /> Script & Style <span class="scriptstyle"></span><br/>
			  <input <?php echo (@in_array("blinklist", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="blinklist" /> Blinklist <span class="blinklist"></span><br/>
			  <input <?php echo (@in_array("delicious", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="delicious" /> del.icio.us <span class="delicious"></span><br/>
			  <input <?php echo (@in_array("digg", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="digg" /> Digg this! <span class="digg"></span><br/>
			  <input <?php echo (@in_array("furl", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="furl" /> Furl <span class="furl"></span><br/>
			  <input <?php echo (@in_array("reddit", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="reddit" /> Reddit <span class="reddit"></span><br/>
			  <input <?php echo (@in_array("yahoomyweb", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="yahoomyweb" /> Yahoo MyWeb <span class="yahoomyweb"></span><br/>
			  <input <?php echo (@in_array("stumbleupon", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="stumbleupon" /> StumbleUpon <span class="stumbleupon"></span><br/>
			  <input <?php echo (@in_array("technorati", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="technorati" /> Technorati <span class="technorati"></span><br/>
			  <input <?php echo (@in_array("mixx", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="mixx" /> Mixx <span class="mixx"></span><br/>
			  <input <?php echo (@in_array("myspace", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="myspace" /> MySpace <span class="myspace"></span><br/>
			  <input <?php echo (@in_array("designfloat", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="designfloat" /> DesignFloat <span class="designfloat"></span><br/>
			  <input <?php echo (@in_array("facebook", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="facebook" /> Facebook <span class="facebook"></span><br/>
		  </td>	
		  
		  <tr>  
		  <td colspan="2"><div class="submit"><input type="submit" value="Save Settings" /></div></td>
		  </tr>
		  	  
		  </table>
		</form>
 
		<h3>Links</h3>
	  	<p>Visit <a target="_blank" href="http://www.undolog.com">Undolog.com</a>, <a target="_blank" href="http://labs.saidmade.com">labs.saidmade.com</a> and <a target="_blank" href="http://www.saidmade.com"><img align="absmiddle" src="http://labs.saidmade.com/images/sm-a-80x15.png" border="0" /></a> for more information about author and WordPress Plugin</a>
				
	</div>
<?php
}
 
 
 
 
 
/**
 * Filter
 */
function position_menu($content) {
	global $wpp_options;
	//
	$title = get_the_title();
	$perma = get_permalink();
	$social = '<div class="wp-social-bookmark-menu"><ul class="socials">'.
	(in_array("scriptstyle", $wpp_options['bookmark'])?
	'<li class="script-style"><a href="http://scriptandstyle.com/submit?url='.$perma.'&title='.$title.'" title="Submit this to Script & Style"> </a></li>' : '').
	
	(in_array("blinklist", $wpp_options['bookmark'])?
	'<li class="blinklist"><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&Url='.$perma.'&Title='.$title.'" title="Share this on Blinklist"> </a></li>' : '').
	
	(in_array("delicious", $wpp_options['bookmark'])?
	'<li class="delicious"><a href="http://del.icio.us/post?url='.$perma.'&title='.$title.'" title="Share this on del.icio.us"> </a></li>' : '').
	
	(in_array("digg", $wpp_options['bookmark'])?
	'<li class="digg"><a href="http://digg.com/submit?phase=2&url='.$perma.'&title='.$title.'" title="Digg this!"> </a></li>' : '').
	
	(in_array("furl", $wpp_options['bookmark'])?
	'<li class="furl"><a href="http://www.furl.net/storeIt.jsp?t='.$title.'&u='.$perma.'" title="Share this on Furl"> </a></li>' : '').
	
	(in_array("reddit", $wpp_options['bookmark'])?
	'<li class="reddit"><a href="http://reddit.com/submit?url='.$perma.'&title='.$title.'" title="Share this on Reddit"> </a></li>' : '').
	
	(in_array("yahoomyweb", $wpp_options['bookmark'])?
	'<li class="yahoo"><a href="http://myweb2.search.yahoo.com/myresults/bookmarklet?t='.$title.'&u='.$perma.'" title="Save this to Yahoo MyWeb"> </a></li>' : '').
	
	(in_array("stumbleupon", $wpp_options['bookmark'])?
	'<li class="stumble"><a href="http://www.stumbleupon.com/submit?url='.$perma.'&title='.$title.'" title="Stumble upon something good? Share it on StumbleUpon"> </a></li>' : '').
 
	(in_array("technorati", $wpp_options['bookmark'])?
	'<li class="technorati"><a href="http://technorati.com/faves?add='.$perma.'" title="Share this on Technorati"> </a></li>' : '').
	
	(in_array("mixx", $wpp_options['bookmark'])?
	'<li class="mixx"><a href="http://www.mixx.com/submit?page_url='.$perma.'&amp;title='.$title.'" title="Share this on Mixx"> </a></li>' : '').
	
	(in_array("myspace", $wpp_options['bookmark'])?
	'<li class="myspace"><a href="http://www.myspace.com/Modules/PostTo/Pages/?u='.$perma.'&amp;t='.$title.'" title="Post this to MySpace"> </a></li>' : '').
	
	(in_array("designfloat", $wpp_options['bookmark'])?
	'<li class="designfloat"><a href="http://www.designfloat.com/submit.php?url='.$perma.'&amp;title='.$title.'" title="Submit this to DesignFloat"> </a></li>' : '').
	
	(in_array("facebook", $wpp_options['bookmark'])?
	'<li class="facebook"><a href="http://www.facebook.com/share.php?u='.$perma.'&amp;t='.$title.'" title="Share this on Facebook"> </a></li>' : '').
	
	'</ul></div>';
	if($wpp_options['position'] == "onthetop") return $social.$content;
	else return $content.$social;
}
 
add_action('wp_head', 'add_styles');
function add_styles() {
	echo "\n".'<!-- Start Of Code Generated By WP-Social-Bookmark-Menu '.VERSION.' -->'."\n";
	if(@file_exists(TEMPLATEPATH.'/styles.css')) {
		wp_register_style('wp-social-bookmark-menu', get_stylesheet_directory_uri().'/styles.css', false, VERSION, 'all');
	} else {
		wp_register_style('wp-social-bookmark-menu', plugins_url('wp-social-bookmark-menu/styles.css'), false, VERSION, 'all');
	}
	wp_print_styles('wp-social-bookmark-menu');
	echo '<!-- End Of Code Generated By WP-Social-Bookmark-Menu '.VERSION.' -->'."\n";
}
 
 
function bookmark_styles() {
echo "<style type='text/css'>
form#wp-social-bookmark-menu span {
background:url(".WP_PLUGINS_PATH."sprite-trans.png) no-repeat;
display:inline-block;
height:29px;
width:50px;
}	
span.scriptstyle { background-position:-400px bottom !important; }
span.mixx { background-position:-250px bottom !important; }
span.facebook { background-position:-450px bottom !important; }
span.flickr { background-position:-250px bottom !important; }
span.myspace { background-position:-200px bottom !important; }
span.blinklist { background-position:-600px bottom !important; }
span.yahoomyweb { background-position:-650px bottom !important; }
span.delicious { background-position:left bottom !important; }
span.stumbleupon { background-position:-50px bottom !important; }
span.reddit { background-position:-100px bottom !important; }
span.digg { background-position:-500px bottom !important; }
span.furl { background-position:-300px bottom !important; }
span.technorati { background-position:-700px bottom !important; }
span.designfloat { background-position:-550px bottom !important; }
</style>";
}
 
add_action('admin_head', 'bookmark_styles');
add_action('admin_menu', 'wpp_options_page');
add_filter('the_content', 'position_menu');
?>

Open in new window

Avatar of blatantwaste
blatantwaste
Flag of United States of America image

ASKER

I just realized it would probably be more helpful just to post a zip folder with the entire plugin rather than just the php code portion, so you can download the plugin from here: http://eight7teen.com/uploads/wp-social-bookmark-menu.zip
ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
These "invisible" characters are known as the BOM, it is normal that these exist in unicode encoded files.

http://unicode.org/faq/utf_bom.html#bom4

EF BB BF == 239, 187, 191
Not sure if ASCII is the same as ANSI, but my text editor didn't have an option for ASCII... So I saved it in ANSI format and it's working fine now. Thank you!