DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Alert Theme Users To Required Plugins

Paul Underwood user avatar by
Paul Underwood
·
Feb. 07, 13 · Interview
Like (0)
Save
Tweet
Share
2.86K Views

Join the DZone community and get the full member experience.

Join For Free

One of things that I've said about premium WordPress themes before is the amount of features that are included in the theme options panel page. Most of these theme options have so many settings which aren't needed, or there is already a well known WordPress plugin that performs this action.

The best example of this is SEO settings, there are premium WordPress themes that allow you to put in SEO settings into your theme options panel. This is marketed at being a great feature of the theme as you don't need install a new WordPress plugin to do this for you. But I feel this isn't a benefit to the theme and it's just added bloat to the theme that the user really shouldn't use.

I'm saying this because people should be using a WordPress plugin to perform this functionality, mainly because if the user changes the theme then they have now lots all the SEO settings for their site. Other benefits is that these massive plugins are continuously being updated adding better functionality to your site.

I understand the benefit of having the SEO settings in the theme options panel as the user only has to go to one place to customise their whole site but I feel we as developers need to provide the best WordPress experience to users. This includes using WordPress best practises and separating functionality and styling. The reason to have functionality in a plugin is so that it will work exactly the same no matter what theme you are using.

An example is if you want to add Google analytics to your website, use a plugin so that if you change your theme you still have this functionality.

The problem that theme developers have is that a user downloads a theme and might not be a developer or used WordPress before and won't understand that they need to download certain plugins to get the best out of their site. Then the user will install the theme without these additional plugins and complain that certain common website functionality is not included, this functionality might of not been included on purpose.

But if you don't include SEO settings in your theme options panel you need to educate the user on what they should be using. There are a few really good SEO plugins for WordPress, all-in-one SEO, headspace2, SEO Ultimate, SEO Rank Reporter, Google XML Sitemaps, or the plugin I use Yoast WordPress SEO plugin. I would recommend the user of the theme to download the plugin Yoast WordPress SEO and use this for all there SEO settings.

Display An Alert Message To Install Certain Plugins

In this tutorial we are going to go over the steps on how theme developers can provide the user with alert messages to tell the user to download certain plugins to increase the functionality of their site.

For this feature we can use two built in features of WordPress, the first is using a function is_plugin_active() and the second is using the action admin_notices.

The function is_plugin_active() does exactly as it's named it will return a boolean value on if the plugin you are searching for is active. All you have to do is pass in the path to the plugin and WordPress will let you know if this plugin is activated. If this check returns false we can then use the action admin_notices to display a message to the user to download this certain plugin.

required_plugins

Add the following to your functions.php file to alert your user to download certain plugins.

add_action('admin_notices', 'showAdminMessages');
function showAdminMessages()
{
	$plugin_messages = array();
	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
	// Download the Yoast WordPress SEO plugin
	if(!is_plugin_active( 'wordpress-seo/wp-seo.php' ))
	{
		$plugin_messages[] = 'This theme requires you to install the Yoast WordPress SEO plugin, <a href="http://wordpress.org/extend/plugins/wordpress-seo/">download it from here</a>.';
	}
	// Download the Disqus comment system
	if(!is_plugin_active( 'disqus-comment-system/disqus.php' ))
	{
		$plugin_messages[] = 'This theme requires you to install the Disqus comment system plugin, <a href="http://wordpress.org/extend/plugins/disqus-comment-system/">download it from here</a>.';
	}
	// Download the WordPress popular posts plugin
	if(!is_plugin_active( 'wordpress-popular-posts/wordpress-popular-posts.php' ))
	{
		$plugin_messages[] = 'This theme requires you to install the WordPress Popular Post plugin, <a href="http://wordpress.org/extend/plugins/wordpress-popular-posts/">download it from here</a>.';
	}
	if(count($plugin_messages) > 0)
	{
		echo '
<div id="message" class="error">';
			foreach($plugin_messages as $message)
			{
				echo '
<strong>'.$message.'</strong>
';
			}
		echo '</div>
';
	}
}




WordPress SEO

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Why Every Fintech Company Needs DevOps
  • Spring Cloud: How To Deal With Microservice Configuration (Part 1)
  • PostgreSQL: Bulk Loading Data With Node.js and Sequelize
  • Top Five Tools for AI-based Test Automation

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: