Check out my talk from WordCamp Kansas City on June 28, 2019. I’d love to know what you think!
Synopsis: In this talk, we’ll discuss how our decisions as designers and developers affect people’s lives, as well as practical ways our daily work can actually change the lives of others for good. If we really believe that WordPress is about democratizing publishing — empowering anyone to share their voice with the world — then our work must always reflect that value. This means that our creations must be accessible to those with differing levels of physical abilities, as well as those with differing levels of experience and those who speak other languages. Citing real-life examples, we’ll learn to think differently about building WordPress and look at practical ways to implement this in our daily work.
WordPress load times can be a serious concern if you’re working with a complicated page that has a lot of queries or API calls.
I’ve worked with several enterprise publishing sites, and site speed was always a concern because of the complex features that fill the page: related news, latest posts from several categories, news tickers, social media feeds, etc.
Loading so many features is a concern because hitting the database so many times so quickly can be a burden on the server, and when you factor in the limited number of API calls many services allow, we need a solution to store data for a brief period of time.
The nice thing is that you can set an expiration time for the transient. This means that if you need to only store the data temporarily, even if it’s just a few seconds, you can do that by adding the third parameter to the function.
// Store for 5 minutes. set_transient( 'jr3_transient', $value, 5 * MINUTE_IN_SECONDS );
Here’s a more fully-featured example:
Advanced Transient Names
It’s possible that you want to store the transient name based on the post being viewed, as may be the case if you are storing data for posts related to the present post. You can do this by adding the post ID to the transient name:
It’s important to note that transient names are limited to 191 characters. This can be an issue when storing a specific WP_Query call. I run into this when I’m doing taxonomy queries, which are notoriously slow. In order to save this data in a transient name, I actually use the query arguments to generate the transient name.
Since we don’t know for sure what the $genre_array and $publisher_array will hold, we can’t hard-code a static transient name.
To solve this, we’ll use the actual $wp_query_args array to generate the transient name. We do this using two methods.
First, we turn the array into a string format using maybe_serialize(), but this still leaves us with the issue of running into the 191-character limit on the transient name.
Second, to handily convert this potentially long serialized string into a shorter string, we convert it into an MD5 hash, which turns our long string into a 32-character string, allowing us room to prefix it.
This allows us to do something like this, ensuring that this specific query will be stored in the transient:
If you are working on a site with lots of queries, you really should be using transients. They are extremely hand for temporarily storing data, whether it be an array of posts, or the results of an API call (like fetching recent tweets). They are easy-to-use, and can be set up in just a few minutes.
Adding Custom Gutenberg editor styles in WordPress is a nice touch to any theme, as it allows authors to get a basic preview of their content before it gets published. It seems like a complicated task, but it’s actually pretty simple, once you get started.
It begins with registering and enqueueing a CSS file in your theme.
The CSS is a bit trickier because there are so many blocks and elements to cover. Here is an example that I’ve put together for this demo that can be a starting place for you.
After nearly 2 years, I’m proud to announce that Simple Custom CSS has received a big upgrade!
I was fortunate enough to work on the first iteration of the WP Customize Code Editor Control and associated “Additional CSS” Customizer section released in WP version 4.7. It was a huge learning experience, and my first major contribution to WP Core.
I’ve taken the lessons learned during that release to bring you a completely updated version of Simple Custom CSS!
I’ve updated Simple Custom CSS to now use the Customizer, allowing live previews of your CSS before you save any changes.
I’ve styled the WP_Customize_Code_Editor_Control to give a similiar experience to the Core “Additional CSS” section, meaning that the editor is full width/height so that you have more room to view your code than the default display of the edtor. And, just like Core, this supports CSSLint.
The Settings Page
The Simple Custom CSS Settings Page
The Settings page now supports CSSLint, which means that it will clearly point out syntax errors. I’ve also modified the colors there to show more contrast, and to more closely match the core WP CodeMirror styles.
I’ve also updated the packaged CodeMirror to the latest versions. These hadn’t been updated in nearly 4 years.
Eventually, I’m going to remove the plugin’s packaged CodeMirror scripts.WP core now includes the same CodeMirror scripts that have been used in the Simple Custom CSS settings page, but I’ve kept the plugin’s packaged CodeMirror JS just in case you’re running an older version of WP that doesn’t yet have CodeMirror support.
I also want to move the Customizer code to JS. I’ve seen a lot of others use Simple Custom CSS as a base for their plugins and theme tools (which I think is great!) and I want to keep it in PHP for a while so other developers can better follow how I’ve set it all up. I hope this will lead to more widespread adoption of the Code Editor Control.
Much further down the road, I want to remove the Settings page altogether. I’d like to see wider adoption of the Customizer for settings, plus at this point for the plugin it has become redundant to maintain both editors. When I do that, I’ll be sure to notify everyone in advance, and perhaps just point the “Appearance > Custom CSS” link to the Customizer Section directly. I’d love your feedback on this.
v1.0 of Simple Custom CSS
I built this plugin out of personal need back in August 2013, and at the time I had no idea how much of a help it would be to others in the WP Community.
It’s thanks to you that Simple Custom CSS has come so far! Your feedback and support have been so encouraging to me over the years, and I love having a way to give back to the Community that has given me so much.
I hope this update will make the plugin even more useful to you and give you a more powerful editing experience.