How to get Popup and onClick work together on Google Chrome Extension

Firstly, if you try to use a popup in your manifest.json and find out that your chrome broweraction onclick listener doesn't seems to work. You are in the right place then. And if you read properly on Google Chrome Extension API page, the following onclick will not work properly with popup if you have define it on your manifest.json file.

chrome.browserAction.onClicked.addListener(function(Tab tab) {...});

Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.

Well, i have another solution for you if you want both popup and onclick on Google Chrome extension to work together.

Popup and onclick working together on Google Chrome extension

Here is probably what you are doing. You are most likely placing your onclick event handler on your background.html file and awaiting for click of your chrome extension to do something within the onclick. And maybe sending them to your popup display. You soon realize that if the popup options is set on your manifest, your onclick won't work. Now, in order to make everything work, just use the popup instead of both as popup will overwrite the onclick event handler and you want the display to be out. What you should do is to paste the code from your background.html to your popup as you shouldn't have the need for a background.html as you are not communicating with many extension. Therefore, you should really either use popup or an onclick but not both 🙂

You might have guess, i was the dumb one here who did the above and realize i'm dumb. *shy* . hahaha. Hope it helps 🙂

How to enable gzip on your cpanel shared hosting

I've explained how to install memcache, htmltidy and csstidy on your centos machine. However,  the most important thing that every webmaster should know and enable would be your gzip. By default, cpanel did not enable gzip for you. You will have to access your cpanel to enable gzip yourself. This can significantly increase your website speed and its a must to do list if you are a webmaster. In order to enable your gzip, you will have to access your cpanel. Once you are in your cpanel, find the following icon.

and click on the following option.

And click update. It is that simple to enable gzip for your shared hosting and speed up your website!

 

Setup WordPress Subversion in Mac

Well, it has been sometimes since i updated this blog actually. In fact, it has been terribly long that i updated some of my plugins (2 years to be exact). I've been busy with setting up Yii framework couponic site and modifying the system as much as possible till i lost track of time. Since i get the time to breath today, i might as well update my plugins. However, i've already forgotten how to do it. Moreover, i am currently using a Macbook air which really gives me zero idea how to connect to my wordpress plugin subversion repository. But i managed to do it anyway and just thought of writing it down a quick tutorial.

For anyone who forgotten how to connect to the repo, here is how you do it. Firstly, you will need a subversion client a.k.a svn client. For windows, you have tortisesvn where you can find the tutorial i wrote two years ago. For Mac, i use versionapps (only 30 days trial :(). Download it and start installing. Once, it is installed, fire up your version apps.  You will be asked for the following few items

The username and password would be your wordpress plugin details. For the location url, just visit your WordPress plugin and click on the tab "Admin". Within there, there is a link call "SVN Repo" as shown below,

You should see the link as shown below,

copy it and pass it into the sub repo and you are done.

Now, just checkout your repo and start doing work! xD

How to resend username and password to user in WordPress using retrieve_password function

Well, there are no such method where you can resend your existing user a reset password from your side. they must actually click on the "lost password" link and fill up the form in order to retrieve the activation email to reset their password. The method was retrieve_password() which is located in wp-login.php. Hence, you won't be able to use this method and even if you can, you will need to post it over from a form in order to utilized this method. The most easiest way to reuse this method is to recreate it by removing certain condition so that it makes life easier for you.

In my case, my system already has the user email addresses. Hence, all i need to do was to remove the checking for email address and start sending verification from the user whether they wish to reset their password.

/**
 * Handles sending password retrieval email to user.
 *
 * @uses $wpdb WordPress Database object
 *
 * @return bool|WP_Error True: when finish. WP_Error on error
 */
function retrieve_password($user_email) {
	global $wpdb, $current_site;

	$errors = new WP_Error();

	// redefining user_login ensures we return the right case in the email
	$user_login = $user_email;

	do_action('retreive_password', $user_login);  // Misspelled and deprecated
	do_action('retrieve_password', $user_login);



	$key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s", $user_login));
	if ( empty($key) ) {
		// Generate something random for a key...
		$key = wp_generate_password(20, false);
		do_action('retrieve_password_key', $user_login, $key);
		// Now insert the new md5 key into the db
		$wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
	}
	$message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
	$message .= network_site_url() . "\r\n\r\n";
	$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
	$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
	$message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
	$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";

	if ( is_multisite() )
		$blogname = $GLOBALS['current_site']->site_name;
	else
		// The blogname option is escaped with esc_html on the way into the database in sanitize_option
		// we want to reverse this for the plain text arena of emails.
		$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

	$title = sprintf( __('[%s] Password Reset'), $blogname );

	$title = apply_filters('retrieve_password_title', $title);
	$message = apply_filters('retrieve_password_message', $message, $key);

	if ( $message && !wp_mail($user_email, $title, $message) )
		wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') );

	return true;
}

The above method take in an email address and send out the email to the user to request a reset of password. You can change the message to your liking but you will need to know the user password in order to use this method. Hope it helps.

Move cpanel mysql to other directory safely

This is also for my personal need in the future whenever i setup a cpanel server for my TWOPIZ HOSTING. There is a way to move mysql to other directory other than the one defined by cpanel. Firstly, you will need to backup everything on /var/lib/mysql folder. Once you have done that, you will have to follow the below instruction.


cd /var/lib
service chkservd stop
service mysql stop
mv mysql /home
ln -s /home/mysql mysql
service mysql start
service chkservd start

The backup apps will still work normally as the mysql folder still exist on /var/lib just that now it is pointing to the /home directory where the size is the largest.