Set Featured Image not appearing in child theme

Some parent theme switched off certain features which would affect the child theme. For example, the parent theme might have this line:

add_theme_support( 'post-thumbnails' , array( 'post' ));

this means that there won’t be featured image support for post_type other than “post” in the child theme. If featured image support is needed, the child theme needs to overwrite this feature after the parent theme has been initialised. We need to use the “after_setup_theme” hook.

add_action( 'after_setup_theme', 'child_add_theme_support');
function child_add_theme_support(){
  add_theme_support( 'post-thumbnails', array( 'post', 'page', 'product' ) );
}      

The above code will then allow featured image in post, page and product for example.

woocommerce: getting paypal ipn to update order status of downloadable product to complete

Woocommerce has paypal functionality built-in to handle downloadble product. After the paypal IPN is setup, it should ping the merchant server on the status of the payment and update the order status from “pending” to “complete”. If you are seeing the “processing” status, it means that you haven’t check the right boxes when setting up the product. For any product that you want IPN to update from “pending” to “complete”, it needs to be both “virtual” and “downloadable”. So much for what virtual and dowloadable means… I realised that only after reading line 1161 in plugins/woocommerce/classes/class-wc-order.php

if ( $_product->is_downloadable() && $_product->is_virtual() )

I then realised woothemes does document this part a bit – http://wcdocs.woothemes.com/user-guide/managing-products/

git server setup

In the git server, create a new git user, ie

sudo git install git-core
sudo adduser git

create ssh dir under the git user and add your keys to it

su - git
mkdir .ssh
touch ~/.ssh/authorized_keys
chmod 700 ~/
chmod 600 /home/git/.ssh/*

* add any keys that you want to have access to ~/.ssh/authorized_keys after that.

To create new repo as a git user

cd ~
mkdir newrepo.git
cd newrepo.git
git init --bare

now in the client server, we want to do our first push to the remote server

git remote add origin git@server:newrepo.git
(assuming you already have all your files committed)
git push origin master

wordpress ajax login without plugin

most of the ajax wp-login plugins out there are offered as widgets. There are times when we we want a simple and encapsulated solution within the template files. All the javascript is encapsulated within the sidebar.php for example and we don’t need to clutter our plugin directory. This should be easily doable but I couldn’t find any quick snippets in google. perhaps most people were lazy and went for the plugin solution.

In sidebar.php for example

<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#my-submit").click(function() {
// turn loading screen on
jQuery('#login-result').toggle();
var input_data = jQuery('#my-login-form').serialize();
jQuery.ajax({
type: "POST",
url: "<?php echo site_url('wp-login.php','login_post'); ?>",
data: input_data,
success: function(msg) {
// if login incorrect, wordpress will redirect user to its own login form. We scan for an error term.
var reg1 = /login_error/g;
if (reg1.test(msg)) {
jQuery('#message').html("<?php _e('Your login credentials is not correct. Please try again.'); ?>");
}
else {
// login success. redirect users to some page.
jQuery(location).attr('href', '/my-account/');
}
}
});
// turn loading screen off
jQuery('#login-result').toggle();
// prevent actual submission of form
return false;
});
});
</script>

And the form can be as simple as

<form name="login-form" id="my-login-form" style="padding-left: 60px;">
<p id="message" style="color:red"></p>
<label style="padding-right:10px;">Username</label><input type="text" name="log" id="my-user-login" value="<?php if ( isset( $user_login) ) echo esc_attr(stripslashes($user_login)); ?>" />

<label style="padding-right:10px;">Password</label><input type="password" name="pwd" id="my-user-pass" value="" />

<div style="float:left;">
<label><input name="rememberme" type="checkbox" id="my-rememberme" value="forever" /><?php _e('Remember me', 'woocommerce'); ?></label>
</div>
<div style="float:left;padding-left: 30px;">
<a href="<?php echo esc_url( wp_lostpassword_url( home_url() ) ); ?>"><?php _e('Lost Password?', 'woocommerce'); ?></a>
</div>
<div style="clear:both; padding: 20px 90px;">
<input type="submit" name="wp-submit" id="my-submit" value="<?php _e('Log In'); ?>"/>
</div>
<?php wp_nonce_field('my-nonce'); ?>
<input type="hidden" name="testcookie" value="1" />
<!-- this is your img loader -->
<div id="login-result" style="position:absolute; top:300px; left: 670px;">
<img src="/wp-content/plugins/nextgen-gallery/images/ajax-loader.gif"/>
</div>
</form>

My Favourite Git Commands

I use git everyday and these are the commands that I cannot live without.

HouseKeeping

git status: This command must be used trillion times. Use it anytime to see where you are at.
git log: gives you a quick overview of previous commit
git log -p: gives you an overview of prevous commits + details of files changed.
git log --stats: list of files commited.
git log -p [hash]..[hash] [filename]: changes to a file between different commits, ie hashes.
git diff [hash]..[hash] [file]: see the difference in files between version.
git reset --hard [hash]: reset git to certain previous state, discarding all changes. leave hash out to reset to current HEAD.
git reset dir/files: unstage files.
git clean -df: remove all untracked files from working tree.
git commit --amend: edit the last commit comments.
git add [files]: stage the files to be committed.
git commit: commit the files.
git init --bare: create a new repository for files to be committed to it.
gitk: simple git gui to track commit changes. My favourite GUI.
git stash: save repo in a temp state. "git stash list" to check all the saved state you have.

Branching and Tagging

git checkout -b [new_branch_name] [origin_branch]: create a new branch from current branch and switch into it. if original branch is hosted remotely, can use origin/branch_name instead.
git checkout [filename/branch]: checkout the HEAD version of the file or switch branch.
git tag [your_own_version_number]: create a tag/snapshot of the current status. able to deploy based on the tag.
git describe: good when using tags. let you know where you are.
git branch -a: shows you all the branches and which branch you are in.
git checkout [hash] [file]: checkout an older version of the file.
git remote add origin git@blarblar.com:something/foo.git: add an origin

Forking
supposed you forked someone’s repo in github.

git remote add upstream git@github.com:username/repo.git : add a remote host(upstream) to follow. After this command, do a "git fetch upstream" to get all the remote branches.
git remote -v: gives you an overview of the remote hosts.
git merge upstream/master : merge upstream host with your master.

Pulling and Pushing

It is a good habit to always pull before working on the files, ie committing and pushing. It reduces the chances of conflicts later. Always use git status to track which branch you are in.

git pull [remote] [branch]: pull from remote master and merge to current branch. Make sure you are in local master branch as well. A short cut for this would be just "git pull".
git pull --rebase: pull changes but put your commits above the pulled commits. Good habit to prevent a merge commit upon pulling, again helping to maintain a clean git history.
git push [remote] [branch]: push your changes upstream to remote branch. A short cut for this would be "git push".
git merge [source_branch] [target_branch]: merge all changes from one branch to the another. Able to use the "no-ff" option to create a new commit upon merging. the no-ff option will also keep the branch history.
git merge --squash [source_branch] [target_branch]: good if you want to move all changes in the source branch to target branch as one commit.
git rebase [branch]: useful command to use in feature branch. when master branch is updated, we run this command in your feature branch, ie "git rebase master" to put your commits above the master commits - gives a clean history.
git cherry-pick [hash]: Pick and apply commit from a previous commit on any branch.
git rebase [hash]: compress commits in history. this is a dangerous move if you have multiple people working on the remote repo.
git rebase -i [hash]~[x]: allows you to squash or change commit text on historical commits, starting from [hash] or HEAD and move x commits before, eg HEAD~4.

quick magento tips

// get user ip
Mage::helper('core/http')->getRemoteAddr(true));

// get user session id
Mage::getModel("core/session")->getEncryptedSessionId());

// update database config on the fly
Mage::getModel('core/config')->saveConfig('payment/worldpaydirect/merchant_id', '1111111'); 
Mage::getConfig()->reinit();
Mage::app()->reinitStores();

wordpress caching and mobile theme plugins

when using caching plugin such as w3tc in wordpress, it will try to cache the mobile version as well and there could be a possibility that mobile users might see the desktop version and vice versa. So the idea is to disable the caching plugin for mobile agents:

if using w3tc, under page cache -> rejected user agents, enter the full list of mobile agents and w3tc will not cache pages requested by them.

android
blackberry9500
blackberry9530
cupcake
dream
incognito
iphone
ipod
mini
webOS
webmate
2.0 MMP
240×320
ASUS
AU-MIC
Alcatel
Amoi
Audiovox
AvantGo
BenQ
Bird
BlackBerry
Blazer
CDM
Cellphone
DDIPOCKET
Danger
DoCoMo
Elaine/3.0
Ericsson
EudoraWeb
Fly
HP.iPAQ
Haier
Huawei
IEMobile
J-PHONE
KDDI
KONKA
KWC
KYOCERA/WX310K
LG
LG/U990
Lenovo
MIDP-2.0
MMEF20
MOT-V
MobilePhone
Motorola
NEWGEN
NetFront
Newt
Nintendo Wii
Nitro
Nokia
Novarra
O2
Opera Mini
Opera.Mobi
PANTECH
PDXGW
PG
PPC
PT
Palm
Panasonic
Philips
Playstation Portable
ProxiNet
Proxinet
Qtek
SCH
SEC
SGH
SHARP-TQ-GX10
SIE
SPH
Sagem
Samsung
Sanyo
Sendo
Sharp
Small
Smartphone
SoftBank
SonyEricsson
Symbian
Symbian OS
SymbianOS
TS21i-10
Toshiba
Treo
UP.Browser
UP.Link
UTS
Vertu
WILLCOME
WinWAP
Windows CE
Windows.CE
Xda
ZTE
dopod
hiptop
htc
i-mobile
nokia
portalmmm
vodafone

Tips in Magento

Debugging Tips:

1. In your .htaccess, add

SetEnv MAGE_IS_DEVELOPER_MODE

2. Under system -> configuration -> advanced -> developer,

change current configuration scope dropdown on top left to main website, then debug -> turn template hints and block name hints to on.

3. We can log errors easily.

Mage::log($var);

4. To display popup errors,

Mage::throwException(“Your debug message here”);

5. To see a list of all events (useful when create events/observers in config.xml)

cd /app/code/core/Mage
grep -r -i Mage::dispatchEvent * 

Removing sensitive data from git

suppose one accidentally commited a file with sensitive data ages ago, others could actually retrieve the passwd easily since git keeps a history of the changes. So the idea is to remove the file from git altogether with file changed history, then recommit the affected file (without sensitive data this time) again.

do a git pull and git fetch –tags on original repo, then copy the repo to a tmp repo and apply the commands to the tmp repo like so:


git pull
git fetch --tags
git filter-branch --index-filter 'git rm --cached --ignore-unmatch wp-config.*' --tag-name-filter 'cat' HEAD --all
(if you have uncommited changes, you will get "Cannot rewrite branches with a dirty working directory." error. Do a git commit to fix the error.)

After that, copy the affected files (wp-config.* in this case) from the old repo back to the tmp repo and force push from the tmp repo.


git push origin master --force

do it for other branches affected.

If using github, the only way is to remove the repo and recreate a new one. In the tmp repo


git push origin master
(or push any other branches if need be)
git push --tags

see also http://help.github.com/remove-sensitive-data/ and http://kernel.org/pub/software/scm/git/docs/v1.6.0.6/git-filter-branch.html