I don’t know if one is faster or slower than the other, but I would suggest that using apply_filters()
is the better approach, because it is cleaner, and more intuitive (in the sense of doing things the “WordPress way”).
EDIT
If you’re doing comparison tests, shouldn’t you compare the time required to execute the following:
This:
<?php
if ( ! function_exists( 'taco_party' ) ) {
function taco_party( $salsa = true ) {
return $salsa;
}
}
function taco_party( $salsa = true ) {
return $salsa;
}
?>
Versus This:
<?php
function taco_party( $salsa = true ) {
return apply_filters( 'taco-party', $salsa );
}
function hot_salsa() {
$salsa = true;
return $salsa;
}
add_filter( 'taco-party', 'hot_salsa' );
?>
It’s not just the time required to check for the existence of the function or filter, but rather the time required to do something.
Related Posts:
- Sanitize and data validation with apply_filters() function
- How many filter/action hooks are healthy?
- Filter specific shortcode output?
- Insert new element to array with add_filter
- remove_filter( ‘the_content’, ‘wpautop’ ); only for certain post types
- Valid characters for actions, hooks and filters
- How to hook into unregistering a widget instance?
- How can I extend the Gutenberg table block transform to allow colspans/rowspans on pasted table elements?
- How do I use the ‘http_request_host_is_external’ filter
- get_option() filtering and getting out of recursion
- Get excerpt from $post->post_content
- Customizing WordPress the_title with add_filter
- How can I send data to admin-ajax via JS Fetch?
- Detecting Embed URLs Within post_content
- add_filter on “the_excerpt” only works when post does not have excerpt
- How can I display image metadata?
- How to prepend text to the_content, but after img/shortcode
- Format content value from DB outside of WordPress filters
- Can’t change the title tag with wp_title filter
- How to filter ‘post_gallery’ after all other filters/plugins etc
- Can’t get wp_title filter working in twenty sixteen child theme
- Filter oembeds tags to modify iframe attributes
- Removing labels and tag on WordPress’s default login form
- How to add data- attribute to tag
- How to trigger the core WPLANG to make automatically set a language when the theme is activated? [duplicate]
- Making a class available via actions filters
- How to check a filter are applied
- How to remove google font in WordPress for only single page?
- How do I filter get_the_excerpt() but keep all of its functionality intact?
- Remove tags from the kses filter
- How to add a class to Tag cloud widget link?
- How to get all the predefined do_action() calls from an active theme
- Is there a get_post(s) filter that can alter/replace the output completely?
- WooCommerce Variable Product Price – Where is “From” text generated from?
- Using ‘posts_where’ on a query with a custom field
- How to add numeric slug for child page in WordPress 5.9?
- add_filter does not work as expected
- Custom Login Errors and variables I can use
- Filter taxonomy admin pagination
- ‘the_content’ filter removing html tags from post content
- Custom view counts not updating correctly
- Using wp_handle_upload() to Direct Specific Path by Using $overrides
- Filter to shorten column content on edit-tags.php
- Create Search Form to Filter Through Terms
- Formatting get_post content doesn’t allow JS content to function properly
- Proper after_setup_theme and wp_head cleanup
- Why doesn’t remove_action work in my plugin?
- Using a filter to modify Genesis wp_nav_menu
- Upload restrictions – upload_mimes – filter: Adding multiple MIMEs for a single extension and adding multiple extensions for a single MIME type?
- How can I change the email that is inside the default email texts of wordpress?
- the_excerpt filter doesn’t work as expected
- What is the earliest hook to modify post content?
- How to modify only part of a function through the filter
- Modify message displayed on post save
- Something is filtering my shortcodes… Can’t figure out what
- How can I apply filters in my class that extends Walker_Nav_Menu?
- Pass debug_backtrace() in WordPress filter
- How should I be using filters and is_single together?
- Remove actions/filters that are set with create_function()
- Remove get_template_part() from custom theme
- I need to hook and change language of facebook sdk
- change “missing attachment” text functions.php
- Use has_filter on comment_post
- Hook in a sidebar widget and add some markup
- return get_the_tag_list with whitespace removed
- How do I add tags to entire comments, not just their text
- ‘manage_users_custom_column’ is a filter, but ‘manage_posts_custom_column’ is an action. Why?
- comment_notification_text filter not working
- Line Breaks are stripped off when direction property is found
- Modify author url display in edit-comments.php
- WordPress remove_filter not working
- add_filter( ‘the_title’ gets through this if statement twice
- Changing the category for existing Gutenberg blocks
- Filter Post Title without affecting screen-reader-text
- Hook to change the site URL
- Modify WordPress Page Title ()
- How to add lazy field in content endpoint using Gutenberg blocks
- Strange behaviour of REGEX in a WordPress filter (trying to suppress emtpy paragraphs)
- Modify Contextual Help
- how to use apply filter for Class?
- How can I see exactly what arguments are being passed through a filter so that I may modify them?
- Widget image reorganize layout
- WordPress set featured image to first image of the post
- Set Microsoft Word links to open in new window/tab
- WordPress get_avatar filter to match logins
- Modify category listing API response
- Auto-generated excerpt with shortcode and read more button/text link
- Converting restricted html in comments to bbcode
- What is the proper/best way to have multiple add_filter for wp-job-manager-resume
- Change shortcode output (filter?)
- How do I add a class to all sidebars to let a Google Custom Search Engine know not to index the content?
- How to replace all images in all posts and pages with a different size?
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- using posts_where for meta data on pre_get_posts
- Updating User Profile on Registration
- can’t output gray scaled image I’ve created using add_image_size
- How properly write function to filter content in a template for plugin “multiple content blocks”
- ACF Load Field Groups Programmatically [closed]
- Why does using excerpt_more filter change link location?
- Adding filter to the Contact Form 7 response