Posts Tagged ‘’

Wordpress: add_action

Friday, July 4th, 2008

Hooks a function on to a specific action. See Plugin API for a list of hooks for action.

To email some friends whenever an entry is posted on your blog:
function email_friends($post_ID) {
$friends = ‘,’;
mail($friends, “sally’s blog updated” , ‘I just put something on my blog:’);
return $post_ID;
add_action(’publish_post’, ‘email_friends’);


(string) The name of the action you wish to hook onto.

(callback) The name of the function you wish to be called. Note: any of the syntaxes explained in the PHP documentation for the ‘callback’ type are valid.

How important your function is. Alter this to make your function be called before or after other functions. The default is 10, so (for example) setting it to 5 would make it run earlier and setting it to 12 would make it run later.

How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. For example, the action comment_id_not_found will pass any functions that hook onto it the ID of the requested comment.

Easy WordPress and Google Calendar Integration

Tuesday, July 1st, 2008

The Wordpress Google calendar plugin allows for the integration of a Google calendar into a Wordpress blog. This section describes how to install the plugin and get it working.
1. Request Google GDATA API key (see link below)
2. Upload the contents of the ZIP file to the /wp-content/plugins/ directory
3. Activate the plugin through the Plugins menu
4. Configure your GDATA API key in the plugin options panel
5. Configure a Google calendar in the plugin options panel
6. Configure the option to render the description field as Wiki markup
7. Create a page and add the ’show-wpng-calendar’ custom field with the number of weeks you want to be displayed
8. Add the widget to your sidebar and configure the title and number of events to display

wordpress relative url

Monday, June 30th, 2008

edit wp-includes/functions.php

function get_option( $setting ) {
	global $wpdb;

	if (in_array($setting, array('siteurl', 'home'))) {
		if (ereg('(wp-includes)', $_SERVER['PHP_SELF'], $r)) {
			return ('http://'.$_SERVER['SERVER_NAME'].(
					$_SERVER['PHP_SELF'], 0,
					strpos($_SERVER['PHP_SELF'], $r[0])
		} else if (ereg('wp-admin', $_SERVER['PHP_SELF'])) {
			return 'http://'.$_SERVER['SERVER_NAME']
			. dirname(dirname($_SERVER['PHP_SELF']));
		} else {
				if (file_exists($_SERVER_SCRIPT_FILENAME.'/wp-content')) {
				if ($_SERVER_SCRIPT_FILENAME == '.') break;
			return 'http://'.$_SERVER['SERVER_NAME'].$_SERVER_PHP_SELF;