Unexpected ')' error during uninstall

Hi,

Even though this is the ‘program your site’ subforum, I’ve got an unprogram my site question :slight_smile:

I installed a plugin on my WordPress site which I immediately decided I didn’t want and deactivated and then deleted it. It appears that the coder’s uninstall file has been badly written though, because I get this when I confirm the delete:

Parse error: syntax error, unexpected ')' in /home/my_folder/public_html/mywebsite.com/wp-content/plugins/badly_coded_junk/uninstall.php on line 21

I went to that uninstall.php file in my cPanel and tried deleting what looked like superflous )s, but nothing seemed to work. And the link to their website in my plugin directory leads to a 404. Joy. I really don’t know anything about PHP. Is there anything you can see from the following that they’ve done wrong that I can fix so I can get rid of this thing?

Thanks a lot.

<?php

if (!defined('ABSPATH') &&
	!defined('WP_UNINSTALL_PLUGIN') &&
	!current_user_can('delete_plugins'))
	exit();

if (blah_delete_options('logo_image', 'logo_text', 'logo_href', 'field_bgcolor', 'page_bgcolor', 'stp_db_version'))
	echo 'Options have been deleted from the database.';
else
	echo 'An error has occurred while trying to delete the options from the database.';
	
blah_drop_stp_datamodel();
	
// deletes all of our options from the options table
function blah_delete_options() {
	$args = func_get_args();
	$num = count($args);
	
	if (num == 1) {
		return delete_option($args[0]) ? TRUE : FALSE);
	} elseif {
		foreach ($args as $option) {
			if (!delete_option($option))
				return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}

//drops the addresses table from the database
function blah_drop_stp_datamodel() {
	global $wpdb;
	global $stp_db_version;
	
	$table_name = BLAH_STP_ADDRESSES_TABLE;
	
	if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") = $table_name) {
	
		$sql = "DROP TABLE " . $table_name . ";";
		        
		// load the Wordpress upgrade library
		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

		// so we can use the database migration functionality
		dbDelta($sql);
	}
}

First of all, he is doing a check with [COLOR="Red"]elseif[/COLOR] and using normal braced syntax (PHP only allows [COLOR="Red"]elseif[/COLOR] if you are using “braceless syntax”). Secondly he has a stray “)” on the return statement at line 20 causing the error.

Here is the revised code:

if (!defined('ABSPATH') &&
	!defined('WP_UNINSTALL_PLUGIN') &&
	!current_user_can('delete_plugins'))
	exit();

if (blah_delete_options('logo_image', 'logo_text', 'logo_href', 'field_bgcolor', 'page_bgcolor', 'stp_db_version'))
	echo 'Options have been deleted from the database.';
else
	echo 'An error has occurred while trying to delete the options from the database.';
	
blah_drop_stp_datamodel();
	
// deletes all of our options from the options table
function blah_delete_options() {
	$args = func_get_args();
	$num = count($args);
	
	if (num == 1) {
		return delete_option($args[0]) ? TRUE : FALSE;
	} else {
		foreach ($args as $option) {
			if (!delete_option($option))
				return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}

//drops the addresses table from the database
function blah_drop_stp_datamodel() {
	global $wpdb;
	global $stp_db_version;
	
	$table_name = BLAH_STP_ADDRESSES_TABLE;
	
	if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") = $table_name) {
	
		$sql = "DROP TABLE " . $table_name . ";";
		        
		// load the Wordpress upgrade library
		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

		// so we can use the database migration functionality
		dbDelta($sql);
	}
} 

I see an extra ) in this line:

if (num == 1) {
return delete_option($args[0]) ? TRUE : FALSE);
}

sorry, I was typing this answer the same time TheRaptor posted his reply, which is probably much more informative. :slight_smile:

That’s not entirely true, elseif is always valid (also in braced syntax); you may always use it, but in braceless syntax you must use it (as else if is not valid in braceless syntax).

See PHP: elseif/else if - Manual

:slight_smile:

I’ve only always seen else used in braced syntax and elseif used in braceless syntax. Interesting, thats something I didn’t know.

TheRaptor :slight_smile: that was awesome! Beautiful stuff. That was the most fun I’ve had all day, nuking that thing right from their own code. Unbelievable that they released that without even bughunting the uninstall.

Thank you. I appreciate that. Worked perfectly.