Category Archives: Php

Modify WP-Cache to avoid caching Password Protected Post

This will allow the post to be seen after password is entered correctly.
Changes are made to wp-cache-phase2.php.

function wp_cache_ob_callback($buffer) {
..
/* we avoid caching incomplete files */
if (is_404() || !preg_match(’/(||)/i’,$buffer) ) {
$new_cache = false;
return $buffer;
}
// dun cache password protect post post_password)) {
$new_cache = false;
return $buffer;
}

Showing Digg Popular Stories

Digg Popular Stories are now shown at the bottom of some of the categories and browse tag pages.
The categories include Diversion, Game, Science, Sports, Technology, World, Php and Python. The tags include Astronomy, environment, nba, php, python, Microsoft and video.
I wrote python scripts to retrieve the popular stories provided by Digg api and format the [...]

Related Tags Navigation added

I am using plugin Simple Tagging. I made a slight modification to STP_RelatedTags and outputRelatedTags functions and uses STP_RelatedTags to show the related tags to the current tag being viewed. Basically, if a post is tagged with A and B, then tag A and B are related.
I also use the below to generate the browse [...]

Showing Only WordPress Top Categories

My sub-categories links are not working! I decided to show only the top categories on my sidebar. The following describes how I do it:
Modify function get_categories in category.php

Add show_top option in $defaults.

$defaults = array(’type’ => ‘post’, ‘child_of’ => 0, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’,
‘hide_empty’ => true, ‘include_last_update_time’ => false, ‘hierarchical’ => 1, ‘exclude’ => [...]

Zend Gdata PUT request

Reference at Zend_Gdata.
Currently, GData only allow POST as request method and not PUT, issue link
PUT is needed! We can just use the existing post method. Here is what I modify (for the time being)

public function post($xml, $uri = null)
{
return $this->request($xml, $uri, ‘POST’);
}
public function put($xml, $uri = null)
{
return $this->request($xml, $uri, ‘PUT’);
}
public function request($xml, $uri = [...]

Global variable in Drupal module

There is something different in a variable between a variable in a Drupal module and a variable in a normal php file.
normal php

$_User = “user”;
function test() {
global $_User;
..
}

Drupal module

global $_User;
$_User = “user”;
function test() {
global $_User;
..
}

In Drupal module, I need the additional global $_User; Why?

Installing Drupal Module

Reference at Installing contributed modules.
I need to remember where to Enable the module. Version 5.x users go to administer > site building > modules.