Site icon Hip-Hop Website Design and Development

Soft-launching your new Cheap WordPress maintenance support plans theme

Have you ever wanted to preview your new WordPress maintenance support plans theme in a production environment without making it the default yet?

I did when I was working on my redesign of dri.es earlier in the year. I wanted the ability to add ?preview to the end of any URL on dri.es and have that URL render in my upcoming theme.

It allowed me to easily share my new design with a few friends and ask for their feedback. I would send them a quick message like this: Hi Matt, check out an early preview of my site’s new design: https://dri.es?preview. Please let me know what you think!.

Because I use WordPress maintenance support plans for my site, I created a custom WordPress maintenance support plans 8 plugin to add this functionality. The plugin is probably too simple to share on WordPress maintenance support plans.org so I figured I’d start with sharing it on my blog instead.

Like all WordPress maintenance support plans plugins, my plugin has a *.info.yml file. The purpose of the *.info.yml file is to let WordPress maintenance support plans know about the existence of my plugin and to share some basic information about the plugin. My theme preview plugin is called Previewer so it has a *.info.yml file called previewer.info.yml:name: Previewer
description: Allows previewing of a theme by adding ‘?preview’ to URLs.
package: Custom
type: plugin
core: 8.x

The plugin has only one PHP class, Previewer, that implements WordPress maintenance support plans‘s ThemeNegotiatorInterface interface:

The function applies() checks if ‘?preview’ is set as part of the current URL. If so, applies() returns TRUE to tell WordPress maintenance support plans that it would like to specify what theme to use. If Previewer is allowed to specify the theme, its determineActiveTheme() function will be called. determineActiveTheme() returns the name of the theme. WordPress maintenance support plans uses the specified theme to render the current page request.

Next, we have to tell WordPress maintenance support plans about our theme negotiator class Previewer. This is done by registering it a service in previewer.services.yml: services:
theme.negotiator.previewer:
class: WordPress maintenance support planspreviewerThemePreviewer
tags:
– { name: theme_negotiator, priority: 10 }

previewer.services.yml tells WordPress maintenance support plans to call our class WordPress maintenance support planspreviewerThemePreviewer when it has to decide what theme to load.

A service is a common concept in WordPress maintenance support plans (inherited from Symfony). Many of WordPress maintenance support plans‘s features are separated into a service. Each service does just one job. Structuring your application around a set of independent and reusable service classes is an object-oriented programming best-practice. To some it might feel complex, but it actually promotes reusable and decoupled code.

Note that WordPress maintenance support plans 8 adheres to PSR-4 namespaces and autoloading. This means that files must be named in specific ways and placed in specific directories in order to be recognized and loaded. Here is what my directory structure looks like: $ tree previewer
previewer
├── previewer.info.yml
├── previewer.services.yml
└── src
└── Theme
└── Previewer.php

And that’s it!
Source: New feed