echo date("d-m-Y : G-i",strtotime('2011-02-26 09:47:11');
Formatting date values returned from MYSQL table to more readable format including time
March 1st, 2011 | posted in Blog, PHP, Tips & Tricks | No Comments »List All Hooked Functions in WordPress
February 18th, 2011 | posted in Blog, PHP, Wordpress | No Comments »
function list_hooked_functions($tag=false){
global $wp_filter;
if ($tag) {
$hook[$tag]=$wp_filter[$tag];
if (!is_array($hook[$tag])) {
trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
return;
}
}
else {
$hook=$wp_filter;
ksort($hook);
}
echo '<pre>';
foreach($hook as $tag => $priority){
echo "<br />>>>>>\t<strong>$tag</strong><br />";
ksort($priority);
foreach($priority as $priority => $function){
echo $priority;
foreach($function as $name => $properties) echo "\t$name<br />";
}
}
echo '</pre>';
return;
}
[/php]
source: http://www.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
List All Hooked Functions
Detect Ajax Request in PHP
December 22nd, 2010 | posted in Blog, PHP | No Comments »if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo "yes";
exit;
}
Adding a class to first and last menu items to WordPress menu
December 13th, 2010 | posted in Blog, PHP | No Comments »Add this code to your functions.php file:
function addFirstLastClass($pageList) {
// pattern to focus on just lis
$allLisPattern = '/<li(.*)<\/li>/s';
preg_match($allLisPattern,$pageList,$allLis);
$liClassPattern = "/<li[^>]+class=\"([^\"]+)/i";
// first let's break out each li
$liArray = explode("\n", $allLis[0]);
// count to get last li
$liArrayCount = count($liArray);
preg_match($liClassPattern, $liArray[0], $firstMatch);
$newFirstLi = str_replace($firstMatch[1], $firstMatch[1] . " first-menu-item", $liArray[0]);
if($liArrayCount > 1){
$lastLiPosition = $liArrayCount - 1;
preg_match($liClassPattern, $liArray[$lastLiPosition], $lastMatch);
$newFirstLi = str_replace($firstMatch[1], $firstMatch[1] . " first-menu-item", $liArray[0]);
$newLastLi = str_replace($lastMatch[1], $lastMatch[1] . " last-menu-item", $liArray[$lastLiPosition]);
}
// replace first and last of the li array with new lis
// rebuild newPageList
// set first li
$newPageList = $newFirstLi . '';
$i = 1;
while ($i < $lastLiPosition) {
$newPageList .= $liArray[$i];
$i++;
}
// set last li
$newPageList .= $newLastLi;
// lastly, replace old list with new list
$pageList = str_replace($allLis[0], $newPageList, $pageList);
return $pageList;
}
add_filter('wp_nav_menu', 'addFirstLastClass');
Thanks to Eliot Kristan
Recent Comments