LAMP How To – Open Source At Work

Only Passion Matters

Entries for the ‘Think PHP’ Category

using set_transient in wordpress

set_transient is an excellent caching mechanism in wordpress. However one thing to note is that it depends on the caching plugin that is installed. So for example, if the plugin caching mechanism is memcache, the cache will be stored in memcache instead of in the db. Hence clearing the memcache from the plugin will clear [...]

PHP: usort magic

usort is very useful when one wants to combine or manipulate the results especially received from the db.
say for example we have an array named $displayProduct and we want to sort by the associative array call ‘order’

usort($displayProduct, function($a, $b) {return ($a['order'] < $b['order']) ? -1 : 1; });

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 [...]

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 [...]