Set options on activation Themes

The Photo Blog Theme Greyfoto has been updated and I wanted to make sure that the settings of WordPress are as I need them for the theme. Therefore must be written some data in the database when activate. Currently there is no hook for this, as is known for Plugins. The discussion on WP-Hacker-List was just right on time, and possibly Theme Developers get these hooks, similar to Plugins in WordPress 2.9.

If you want to use the activation of the theme in order to set various settings, then the following snippet can be very useful, which came up in the discussion on the WP-Hacker-List. This works like a charm and should be useful for theme developers who want to enable the options upon activation.
Continue reading …

Add File Types for Mediathek

In WordPress 2.8.5 the whitelist of allowed MIME types for downloads will be valid for administrators the first time. This is a step towards security and you can, with the help of a constant, upload all data types.

Who has implemented several projects already with WordPress probably had experienced that a user doesn't have the rights to upload a specific format.

The Plugin Role Manager allows the uploading of all MIME types. But in my opinion this is not the perfect way, and therefore here is a small code snippet that takes adjusting according to the particular requirement.
Continue reading …

Check If Required Plugin Is Active

It might be, that your own written Plugin requires another stand alone Plugin to be active. For example if you like to offer a version with enhanced functionality of a Plugin. There are certainly a variety of usage and the implementation is not difficult.

For the implementation, we need the active Plugins, which are found in the database, table options, the active_plugins. Afterwards, I will simply look in the array, which contains the active Plugins, whether the required plugin included and active or not:

$plugins = get_option('active_plugins');
$required_plugin = 'debug_queries/debug_queries.php';
$debug_queries_on = FALSE;
if ( in_array( $required_plugin , $plugins ) ) {
	$debug_queries_on = TRUE; // Example for yes, it's active

Themes and automatic_feed_links

Since WordPress 2.8, there is the function automatic_feed_links() in the function.php. Which writes the link elements for the RSS protocols in the header of the document. The advantage of this feature is, you do not need to worry about whether a change comes in the Feed-protocoll in a new version of WordPress, removed or a new one is added.

If we develop a theme for the general public, you have 2 options. You use automatic_feed_links() and the theme does not work with WordPress prior to version 2.8, or you do not use this function and write the links as before, in your header.php.

I also have a 3rd alternative ;).

if (function_exists('automatic_feed_links')) {
} else {
    add_action('wp_head', 'wpe_feed_links', 2);

function wpe_feed_links() {
    echo '<link rel="alternate" type="application/rss+xml" title="'. get_bloginfo('name').' RSS Feed" href="'. get_bloginfo('rss2_url').'" />';
    echo '<link rel="alternate" type="application/atom+xml" title="'. get_bloginfo('name').' Atom Feed" href="'. get_bloginfo('atom_url').'" />';
    echo '<link rel="alternate" type="application/rss+xml" title="'. get_bloginfo('name').' '. __('The latest comments to all posts in RSS').'" href="'. get_bloginfo('comments_rss2_url').'" />';

First we look if the function automatic_feed_links() exists. If not (prior to WP 2.8), we use the hook wp_head and write the links in the header of the page. Thus we don't need to adjust the header.php anymore.