WordPress: Useful Default Configuration Settings Via Plugin

Everybody who installs WordPress quite often knows the problem: You always have to do the same adjustments, for example deleting the Hello World post. That cost time and money. Our friend Thomas Scholz alias toscho had a simple but genius idea, he puts all needed option settings in a Plugin. Just activate the Plugin, deactivate it and delete it. Done!

You can adjust and expand the options as you like. A good overview is the wp-admin/options.php.

<?php
/*
Plugin Name: Toscho's basic settings
Plugin URI: http://toscho.de/2010/wordpress-grundeinstellungen-per-plugin-setzen/
Description: Some useful default configuration settings. See 'wp-admin/options.php' for more options.
Version: 0.2
Author: Thomas Scholz
Author URI: http://toscho.de
*/

function set_toscho_defaults()
{
    $o = array(
        'avatar_default'            => 'blank',
        'avatar_rating'             => 'G',
        'category_base'             => '/thema',
        'comment_max_links'         => 0,
        'comments_per_page'         => 0,
        'date_format'               => 'd.m.Y',
        'default_ping_status'       => 'closed',
        'default_post_edit_rows'    => 30,
        'links_updated_date_format' => 'j. F Y, H:i',
        'permalink_structure'       => '/%year%/%postname%/',
        'rss_language'              => 'de',
        'timezone_string'           => 'Etc/GMT-1',
        'use_smilies'               => 0,
    );

    foreach ( $o as $k => $v )
    {
        update_option($k, $v);
    }

    // Delete dummy post and comment.
    wp_delete_post(1, TRUE);
    wp_delete_comment(1);

    return;
}
register_activation_hook(__FILE__, 'set_toscho_defaults');
?>

Here you can download the Plugin by toscho.

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
}

Warning Message For Self Customized Plugins

Now and then you have to modify an existing Plugin for your own special needs. But you still get a message if an update exists for the original Plugin. If you modified the Plugin several month ago and you forgot about it, so you update the Plugin and all your modifications are gone. Most of the time you have a backup, but even though it's annoying to upload the customized Plugin again after you realized the original Plugin is not exactly what you want. Therefore you can paste a little function in the specified Plugin to display a warning right after the update message. So you won't forget, that you modified this Plugin a while ago.

plugin-modified-warning-small

function my_update_notice() {
	$info = __( 'ATTENTION! Plugin was modified.', MY_TEXTDOMAIN );
	echo '<span class="spam">' . strip_tags( $info, '<br><a><b><i><span>' ) . '</span>';
}

if ( is_admin() )
	add_action( 'in_plugin_update_message-' . plugin_basename(__FILE__), 'my_update_notice' );

Recents Drafts All Authors

It's not uncommon that a blog runs by different authors, so it may be useful if you can have a quick look at the drafts of all authors. In our joint blog WP Engineer we created a feed, which keeps us up to date if a new draft of all authors were created.

The work of every author is different and the dashboard is the center of information. Therefore we have decided to supplement a widget in the Dashboard, which shows the last five drafts of all authors. I enhanced the existing Plugin Draft Feed.

  • It provides a feed of all drafts
  • And the last 5 drafts of all authors in the Dashboard.

Continue reading …