If you’ve been running a WordPress blog for any length of time and you use – or used to use – the more tag, you’ve probably got some of your posts with the tag and some without the tag.
That’s how most of my archive pages are at this point, anyway.
I chalk it up to my own inconsistency but I got tired of finding a post, manually editing it, then moving on.
WordPress can auto-generate excerpts by truncating your post content, but the results are rarely what you want. Incomplete sentences, leftover shortcodes, broken HTML. If you’ve ever looked at an archive page or an RSS feed and wondered why the summary looks off, that’s why.
I’ve previously written about using Laravel Herd as my preferred PHP development environment. Outside of my day-to-day work, I’m also working with a couple of friends on a project that includes an iOS app that talks to a REST API via headless WordPress backend.
The web app is built using a set of tools from Roots including Radicle:
Radicle is an opinionated starting point for WordPress projects with the Roots stack.
In short, Radicle allows us to use features of Laravel within WordPress. But one of the challenges with my set up is getting Laravel Herd and Radicle to actually work.
Turns out, the solution isn’t that hard. And if you’re in a similar situation, here’s how to work with Radicle with Laravel Herd.
Roots Radicle with Laravel Herd
Project Set Up
First, I’m operating on the assumption that you have your project is already linked and secured with Herd.
In our case, we’re using a monorepo that contains both the iOS app and the web application. The web app in question is located in projects/monorepo-name/apps/wordpress. So I’ve issued the usual commands add that directly to Herd.
Secondly, I’ve got the .env file configured so that it has all of the necessary information for the database, various WP environmental variables, salts, and other information required to stand up the web app.
The Actual Problem
Third, and this was the most problematic, I had to add a custom driver that would allow Radicle to work with Laravel Herd. The path to custom drivers on your machine may vary but if you’re running the latest version of macOS and haven’t customized the Herd installation then it should look something like this:
Note that if the Drivers directory doesn’t exist, create it. Then touch a file named RadicleValetDriver.php in that directory and add the the following code (you shouldn’t need to change any of it):
<?php
namespace Valet\Drivers\Custom;
use Valet\Drivers\BasicValetDriver;
class RadicleValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return file_exists($sitePath.'/public/content/mu-plugins/bedrock-autoloader.php') &&
file_exists($sitePath.'/public/wp-config.php') &&
file_exists($sitePath.'/bedrock/application.php');
}
/**
* Determine if the incoming request is for a static file.
*
* @return string|false
*/
public function isStaticFile(string $sitePath, string $siteName, string $uri)/* : string|false */
{
$staticFilePath = $sitePath.'/public'.$uri;
if ($this->isActualFile($staticFilePath)) {
return $staticFilePath;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*/
public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
{
$_SERVER['PHP_SELF'] = $uri;
if (strpos($uri, '/wp/') === 0) {
return is_dir($sitePath.'/public'.$uri)
? $sitePath.'/public'.$this->forceTrailingSlash($uri).'/index.php'
: $sitePath.'/public'.$uri;
}
return $sitePath.'/public/index.php';
}
/**
* Redirect to uri with trailing slash.
*
* @return string
*/
private function forceTrailingSlash(string $uri)
{
if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') {
header('Location: '.$uri.'/');
exit;
}
return $uri;
}
}
Note this is running on PHP 8.4 so you may need to adjust your function signatures and other features if you’re running on a significantly lower version (though I didn’t really test thing on anything lower than 8).
Once done, you should be able to load your project in the web browser. If not, restarting Herd’s services should do the trick. And, on the off change you still have an error, the stack trace should be easy enough to follow to see where the problem lies.
Given a vanilla Herd set up and Radicle integration with your WordPress project, this custom driver should be all you need to get everything working with as little effort as possible.
For years, I’ve kept track of various resources that I’ve found useful. Having them here makes it easy to refer to them in the future should the need arise (don’t you refer back to your old posts? /s).
It also makes it easy for others to find them if they’re searching for them either in traditionalways or via some of the new ways we have to search (that latter of which is why I find value in still sharing content).
Anyway, over the last two weeks, there have a been four things I’ve found that I hope to look more into in the future. And if not, at least they’re here for posterity.
WP API Privacy. The default WordPress installation from wordpress.org automatically transmits extraneous information via various HTTP calls that occur in the admin. Some of this data may be cause for concern from a privacy perspective. This plugin seeks to limit that information, attempting to further protect your privacy in the process (via Duane Storey).
WordPress Plugin Attestation. Add this action to your deployment workflow to generate a build provenance attestation of the plugin ZIP file on WordPress.org (via John Blackbourne). For what it’s worth, “attestation” is just the verification that the software comes from where it claims to originate.
RAVE for WordPress. RAVE for WordPress is an automated tool which compares the contents of published packages of WordPress with the canonical source code to verify they have not been tampered with (via John Blackbourne).
Git Updater Lite. “Since Git Updater already gathers and parses this data, Git Updater Lite only needs to query an update server run by the developer” (via Andy Fragen).
And if you stumble across this post and are interested in anything I’ve written in the past week, you can find that below:
If you’re using WordPress and you’re looking for an extremely quick way to add this functionality to your local installation, add the following code to an mu-plugin …
Earlier this year, I swapped my local development environment over to Herd (along with a couple of other changes such as DBngin which is worth covering in another post).
There’s a lot to like about it one of which is how easy it is to begin capturing outgoing emails from whatever application you’re using.
Herd Pro provides an SMTP mail server on your local machine that catches all outgoing emails instead of sending them to the world. It displays them in Herds own email client and provides rich debugging capabilities for all types of emails.
Emails From WordPress in Laravel Herd
If you’re using WordPress and you’re looking for an extremely quick way to add this functionality to your local installation, add the following code to an mu-plugin:
<?php
/**
* Initializes the PHPMailer instance before it is used to send an email.
*
* This action hook is used to configure the PHPMailer instance with the necessary
* SMTP settings, such as the host, authentication, port, username, and password.
*
* @param PHPMailer $phpmailer The PHPMailer instance being initialized.
*/
add_action('phpmailer_init', function ($phpmailer) {
$phpmailer->isSMTP();
$phpmailer->Host = '127.0.0.1';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 2525;
$phpmailer->Username = 'WordPress';
$phpmailer->Password = '';
});
For example, I have a file – herd-mail.php – located in mu-plugins. Once this is added, any outgoing email from WordPress will be immediately captured and funneled to Herd’s email inbox for review.
Notes
PHPMailer is part of WordPress core so there’s no need to install a third-party library).
Kinsta offers premium managed WordPress hosting for everyone, small or large. Powered by Google Platform and strengthened by Cloudflare, they take performance to the next level. All hosting plans include 24/7/365 support from their team of WordPress engineers. Get startedwith a free migration today.