WordPress Pulse? – Heartbeat API

With WordPress 3.6, there will be a new API - Heartbeat. On Ticket 23216 in Trac all discussions and information be gathered together. Because Heartbeat may also have influences for users, here are some words and clues. Heartbeat is introduced to various activities, such as Autosave, locks of articles and to handle logon and logoff notifications. In parallel, the API can also be used for own developments.
Continue reading …

First or Last Page in Page-Structures of WordPress

Now and then little snippets are pretty useful. For a fix in a Premium-Theme, I needed a kind of evaluation, where I am in the site structure and with little effort I was able to expand the classes and react with CSS.

The following code shows the basic for it and get_pages() is the key from the core of WordPress to get to these results. This function provides the necessary result of using the parameter and the output via the parameter sort_order provides the sequence and identification of the first page, which is then either the first or last page in this structure.
Continue reading …

Use WordPress Cron

WordPress-Christmas-14WordPress has its own cron to automatically and scheduled run certain themes. Therefore WordPress provides several functions to use the cron.

In our first example we send every hour a mail with the help of the WordPress function wp_mail(). FYI, this is just a possibility, please don't do it on your system!

As default, WordPress can handle 3 time keys, which you can call with the function wp_schedule_event.

// send automatic scheduled email
if ( ! wp_next_scheduled('my_task_hook') ) {
	wp_schedule_event( time(), 'hourly', 'my_task_hook' ); // hourly, daily and twicedaily
}

add_action( 'my_task_hook', 'my_task_function' );
function my_task_function() {
	
	wp_mail( 
		'example@yoursite.com', 
		'Automatic mail', 
		'Hello, this is an automatically scheduled email from WordPress.'
	);
}

If you use the cron in a Plugin or theme, then don't forget to deactivate the cron if you don't need it anymore.

delete_action( 'my_task_hook', 'my_task_deactivate' );
// clean the scheduler
function my_task_deactivate() {
	
	wp_clear_scheduled_hook( 'my_task_hook' );
}

But not always are 3 time values enough. Luckily you can expand the control via a filter.

add_filter( 'cron_schedules', 'filter_cron_schedules' );
// add custom time to cron
function filter_cron_schedules( $schedules ) {
	
	$schedules['once_half_hour'] = array( 
		'interval' => 1800, // seconds
		'display'  => __( 'Once Half an Hour' ) 
	);
	
	return $schedules;
}

Feed Cache in WordPress

WordPress already offers the possibility of own functions to read feeds and use it in your blog. Since version 2.8 of WordPress, a new feature is in use for that. So there are two ways to work with feeds in WordPress, and in both functions, the data is cached. But this is not always wanted, so I show how to take influence on caching of the two functions.
Continue reading …

Easier And Better Solutions To Get Pictures On Your Posts

WordPress makes it pretty easy to upload picture on posts and pages. Thereby are various data stored, which can be used.
Again and again, you can read tutorials on how to bring photos to posts, normally this is a solution via the custom fields. But there is a different and simpler solution, I think. The maintenance of custom fields is not always necessary.
Therefore, I would like to show some solutions that are, in my opinion, much better and can be expanded in many ways.

Continue reading …