What if you want to remove the icon and replace it with a “…”? How would you do that? Think about it. Think about the code from the last episode. You have the default text coming into your callback. That means you can concatenate that string and append the dots after the incoming text.
Labs
Labs are hands-on coding projects that you build along with Tonya as she explains the code, concepts, and thought processes behind it. You can use the labs to further your code knowledge or to use right in your projects. Each lab ties into the Docx to ensure you have the information you need.
Each lab is designed to further your understanding and mastery of code. You learn more about how to think about its construction, quality, maintainability, programmatic and logical thought, and problem-solving. While you may be building a specific thing, Tonya presents the why of it to make it adaptable far beyond that specific implementation, thereby giving you the means to make it your own, in any context.
Change the “Continue reading” Text
Our next customization is to change the “read more” text, which by default is “Continue reading”. You might want it to say “Learn more”, “Read more”, “Discover more”, or whatever. The choice is yours. In this episode, you and I will walk through how to: Identify the ID for the text. Discover that it’s a filterable event, meaning you need to know the event’s name and then register your callback to it. Identify what the event’s name is for the above ID. The “read more” text is rendered using beans_output() function. Looking at its documentation, notice that it accepts an […]
Customizing the “Read More” Link in Beans
A common theme customization is to change the “read more” link. The default in the Beans framework is “Continue reading »”. But what if you want to read “Discover more”? How would you do that? Or what if you it to look like a button? How about changing the icon to something else? In this hands-on coding lab, you will 9+ customizations in your Beans child theme to fit your project’s needs while you learn about Beans and UIKit.
Wrap it Up
WooHoo! You did it! I’m so proud of you. Whew that was a long, long lab. But it was more than just building a reusable meta box module. My intent was to help you learn about: the Reusable Mindset – developing how you think about software, quality, and costs Architecture – developing how you layout your code Advanced programming concepts for filtering, merging, recursively merging and replacing, and remapping of arrays, as well as assigning a callable to a variable and then invoking it. Tell me what you think Now I want to hear from you. What do you think? […]
Hook into WordPress
We need to hook into a filter event within WordPress to change the stylesheets’ and scripts’ URL. How do we find this hook? Let’s talk about a strategy first. And then let’s look in WordPress Core to see where it’s fired and what arguments we will get when our code runs.
Custom Post Type Generator – Registration
Next, you and I need to build a registry mechanism for our custom post type generator. We need a way for plugins to hook into our custom module and pass each custom post type’s configuration to us for processing. Let’s talk about the different approaches to achieve this feature. There are different strategies that we can use: Use the WordPress event-driven engine by building a custom filter We could build a configuration store. For the custom post type, let’s build a custom filter event. Later for the taxonomy, we’ll build a configuration store. Why? I want to give you two […]
Callbacks and Namespacing
In WordPress, we register callbacks to events by using add_action or add_filter. In the last episode, you learned that you must specify the fully qualified name to invoke a function (i.e. run it) outside of the namespace. This applies to add_action or add_filter. In this episode, you will learn why as well as a shorthand version using the magic constant __NAMESPACE__.
“Object Not Available” Strategies
There are times when you can’t get a hold of the object in order to remove a method callback from that object. The author wrote it such that s/he did not expose the object for you. What do you do? How can you get that object in order to do your work and unregister its callback? Here are strategies in order: Talk to the author and see s/he will add a filter or action to pass the object to you. If it’s open source, submit a pull request to add the filter/action code. Evaluate if you have to use this […]
Wrap it Up
Let’s review what you learned in this lab about registering and unregistering callbacks for both static and object methods. You looked into WordPress Core and saw that it is using call_user_func_array to call each of the registered callbacks for a given event hook. You learned strategies for working with 3rd party code including WooCommerce. If the WordPress Event registrations confused you, go take this lab. Congratulations for completing this lab!
Design Strategy
When you are registering and unregistering callbacks within an object, you typically do this task as part of the object’s initialization process. Instead of putting all of the init tasks into the constructor, break it out. Put the callback registration into a separate method called init_events().