Our themes and plugins use hooks to run code when an event fires. We use WordPress’ functions to add or remove a hooked callback, fire the event, or check the status. How do you unit test those interactions without loading WordPress? Meet Brain Monkey. Brain Monkey gives you the power to unit test hooks by simulating WordPress. In this lab, you’ll walk through building unit tests for hooks.
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.
Brain Monkey’s Hook Toolset
The Problem – Why We Need to Simulate WordPress
Testing Hooks with Brain Monkey
Testing a Filter Has a Callback
Testing a Callback is Registered to a Filter Hook
beans_apply_filters
The What Syntax mixed beans_apply_filters( string $id, mixed $value [, mixed $… ]] ); Beans Code Reference Description This function extends the power of WordPress’ apply_filter by: Using a smart unique ID Processing sub-hooks within the unique ID More coming soon…keep checking back. Parameters id The unique ID, is broken up into individual filter event name’s. Sub-hooks are specified using square brackets, such as ‘hook[_sub_hook]’. value The value which will be filtered by the registered callbacks. … optional Additional argument(s) to be passed to the registered callbacks. Return Values Returns the filtered value. Show It in Action More coming soon…keep […]
beans_open_markup_e
The What Syntax beans_open_markup_e( string $id, string|bool $tag [, string|array $attributes [, mixed $… ]] ); Beans Code Reference Description This function builds and renders the HTML for the specified opening tag’s HTML with the specified attributes (optional). It uses beans_open_markup and then echoes the return string out to the browser. It provides flexibility for 3rd party customization (i.e. child theme and/or plugins) to remove or change the HTML. The power of Beans is the ability to customize whatever you need via the unique ID and internal functionality. Using the specified $id, a child theme or plugin can register to […]
Dive into Beans’ beans_open_markup()
Let’s dive into the Bean’s framework to understand how the beans_open_markup() function works.
Wrap It in a Paragraph
Let’s say that you want the “read more” link or button to be wrapped in a <p> element. You want it as a separate paragraph. How would you do that? One approach is to use the WordPress “read more” link filter event. You’d register a callback and then wrap the HTML that Beans builds within a paragraph element.