WordPress
  • 14 May 2021
  • 5 Minutes to read
  • Dark
    Light
  • PDF

WordPress

  • Dark
    Light
  • PDF

WordPress CI/CD with BuildMaster

WordPress is a an open-source content management system (CMS) written in PHP. It is the most popular CMS on the market, because it is simple, fast, reliable, and secure. Furthermore, WordPress removes the need to have a developer build your website or blog; it is typically managed instead by a Marketing team. It is also very easy to customize WordPress using their theme and plugin directories.

WordPress in Organizations

Since WordPress is open-source, it can be hosted multiple ways. While some organizations host it on their internal or private cloud infrastructure, most leverage professional-grade WordPress hosting services such as Pressable, Pantheon, and WP Engine.

The most immediate benefit of professional-grade WordPress hosting providers is that they mostly remove the need for IT to be involved hardware and server management for WordPress. With minimal training, the marketing team can then become responsible for:

  • Upgarding WordPress itself using the control panel
  • "Cloning" WordPress instances to allow for
    • Site testing
    • Upgrades that don't affect production
    • Testing custom plugins and themes without affecting production
    • Blue/Green development of complex new content

This ultimately helps to shift the "ownership" of the organization's website from the IT department to the Marketing department. However, it's still important for IT to be involved to some extent, both to facilitate customizations and enable best practices in modern marketing (aka "MarketingOps").

Enabling MarketingOps with WordPress and BuildMaster

MarketingOps is a buzzword, and there's standard definition of it. But like DevOps, MarketingOps is about using automation and process improvement to facilitate better communication and faster changes.

WordPress simplifies building and maintaining a website, and at its core, it is very reliable and secure because it's maintained by the WordPress team. However, there still may be a lot of risk in using the very popular third-party themes and plugins, because they are managed by the community. Concerns include:

  • Unknown maintenance of plugins and themes
  • Unknown third-party tools used to build plugins or themes
  • Unclear what data may be inadvertently exposed to your end-users

Because not all themes in the directory will fit your look and feel and to avoid security concerns, many organizations will task a development team (either inside the company or at a marketing agency) with building custom themes and plugins to meet their visual and security needs.

Where BuildMaster Helps

BuildMaster facilitates both the technological side of MarketingOps -- the process of building, testing, and releasing custom themes and plugins -- AND the communication aspect of MarketingOps. BuildMaster is a communication and automation tool because it will:

  • Allow developers to build and maintain the customization of WordPress while still allowing your Marketing team to own the website and content
  • Segregate your testing environments from your production environment, which allows for different versions of the themes and plugins to be built and tested prior to being to production
  • Automate the communication between development and marketing
  • Notify the right people or group at the right time (e.g., when a plugin is ready)
  • Require the proper approvals are met before changes are elevated between environments

Configuration in Source Control

The first step is to put your WordPress theme or plugin code into source control. The next step is to create a delivery pipeline for your custom Wordpress theme or plugin. BuildMaster integrates with a variety of source control systems, but we'll use GitHub for our examples in this document.

Example: Getting Your Code from GitHub

To begin a custom WordPress build in BuildMaster, create a GitHub project secure resource. After creating a GitHub project secure resource, you can get the source code as follows:

GitHub::Get-Source
(
    From: InedoWordPressTheme,
    CommitHash => $CommitId,
);
Set-BuildVariable CommitId
(  
    Value: $CommitId  
);

This will also create a build-scoped variable to record the commit used.

Creating Artifacts

A build artifact is essentially a zip file that is captured at the first stage of a pipeline and then deployed to each subsequent stage. Build artifacts ensure that the exact same code is deployed to each environment.

To create an artifact that can be used in WordPress:

Create-Artifact InedoWordPressTheme
(
    From: $WorkingDirectory
);

Leveraging Custom Build Tools

Because of the languages used to extend WordPress (i.e., PHP, CSS, JavaScript, etc.), code is not compiled. However, you may want to use custom tools to aid in your CSS and Javascript development.

Some standard tools you might use are:

  • CSS Pre-compilers (LESS, SASS, etc.)
  • CSS Linters (CSSLint, StyleLint, etc.)
  • JavaScript Linters (JSLint, ESLint, etc.)
  • JavaScript Trans-pilers (TypeScript, CoffeeScript, etc.)

These tools all have CLIs that are used to compile or parse the code. To execute these in BuildMaster, simply use an Exec command.

An example using the less.js for Windows Pre-Compiler:

set $LessFile = style.less;
Exec
(
    FileName: {LESS_HOME}\lessc,
    Arguments: $LessFile $Replace(.less, $LessFile, .css, true),
    WorkingDirectory: $WorkingDirectory
);
   

Deploying your Theme or Plugin

Custom themes and plugins in WordPress are normally installed by manually uploading them via the Administration screens. Best practice dictates that you should make a clone of your production site and test new changes to themes and plug-ins on the clone first to avoid breaks and downtime in your live Production environment.

BuildMaster streamlines this process by notifying the user that is in charge of testing each environment. This can be tracked using the Perform-ManualOperation, which will halt the deployment until the specified user certifies that they performed the specified task.

For example:

InedoCore::Send-Email
(
    To: "email@email.com, email2@email.com",
    Text: A new Theme is ready to be installed in $Environment
);

Perform-ManualOperation
(
    Name: Install Theme in $Environment
);

Automating Using WP-CLI

WordPress has added official support for a command line interface (CLI). The WP-CLI can be used to automate deployments of themes and plugins to WordPress as well as other development tasks. Many WordPress hosting providers support or plan to support the WP-CLI. You will need to check with your hosting provider if they support the WP-CLI.

Exec
(
    FileName: {PHP_HOME}\php,
    Arguments: wp-cli.phar theme install {URL_OF_ZIP} --activate
)

Refer to the WordPress installation document to installing the WP-CLI.

Tagging Applied Theme or Plugin

At the last stage of your pipeline, it's a good idea to apply a tag to the exact code that was elevated. This can be done using the commit captured in the first stage:

GitHub::Tag
(
    From: InedoWordPressTheme,
    Tag: $ReleaseNumber.$BuildNumber,
    Branch: $Branch,
    CommitHash: $CommitId
);

Was this article helpful?