cables of electronic devices

Smart defaults and your WordPress plugin settings

Posted on

in ,

When building WordPress plugins, there are likely options you’d like your users to be able to adjust. Turning features on or off, changing text labels, customizing colours, etc. Many of these settings land on a settings screen within WP Admin or in a meta box on a post type. Lets focus today on the settings screen idea, and introducing smart defaults.

Smart defaults are pre-configured values for the settings of a WordPress plugin. In WordPress itself, we see smart defaults for the site title, site tagline, and many other features within WP Admin. These can all be adjusted, though they start with a pre-defined value. These pre-defined values are the smart defaults.

When installing a WordPress plugin, the plugin should “just work”. No additional setup required. How a plugin is configured is part of the user experience for that plugin.

The user has spent time and energy selecting your plugin. There’s no need to make them work harder to get the plugin to do what they need on their site.

A large settings screen of many configuration options adds to the cognitive overhead of getting a plugin working. As the developer who builds that plugin every day, it’s easy to forget that others are seeing these settings for the first time.

Each setting is precious. Decide if it truly needs to be there. Fewer settings is a kinder approach to configuring your plugin.

Smart defaults in practice

If your settings screen has a checkbox to turn on a feature, decide if that checkbox should be off or on by default, and set that as the default value. If a colour field is available, set the default colour to something neutral that works with most themes.

Is the settings screen even entirely necessary for your plugin? If your plugin has one or two additional fields, consider adding them to an existing screen within WP Admin. The key decider here is also to ask whether the place you’re adding your settings is the logical place your user will look when wanting to tweak the configuration of your plugin.

Settings → Configuration

Settings are actually configurations. Reframing this concept helps to build understanding that your plugin configuration is optional and shouldn’t be required in order to make the plugin work.

It’s really easy to add a setting. It’s much harder to take that setting away. Once your users are using your plugin, other features may depend on the settings in your plugin. Taking a setting away will break the experience for your user, which creates more work for them to get their site working again.

Configuration using code

One approach to building out a settings screen over time is to start with only the absolute essentials, and to add code-level customization options to turn certain features off or on. This is also particularly useful for agencies and site builders who want to customize a plugin though don’t want the overhead of another settings screen the site owner can modify, potentially breaking the site. Adding one or two lines of code isn’t a concern for an agency or builder.

A great approach to this is to use the magic __return_true() and __return_false() functions built into WordPress. Here’s the function reference for __return_true(). When combined with apply_filters(), it’s possible to turn features off or on with one line.

In your plugin code, you may decide to wrap a boolean in something like this:

$activate_featurename = false;apply_filters( 'my_awesome_plugin_activate_featurename', $activate_featurename );

This allows another developer to add a line like this to their site:

add_filter( 'my_awesome_plugin_activate_featurename', '__return_true' );

User feedback to build your configuration screen

If there is enough feedback that this feature should have a checkbox, consider adding it to your settings screen. This is a useful approach for features which are in active development, or should only be used by developers and builders. Get user feedback from the forums on WordPress.org, from social media, and by speaking with the users of your plugin. There are likely features and settings you haven’t yet considered, which would add value for your users.

WordPress tips in your inbox ✨

More WordPress thoughts and tips, right in your inbox.

We don’t spam! Read our privacy policy for more info.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *