SlideShare a Scribd company logo
drewf.us/wcabq13
THERE’S A FILTER FORTHAT
Drew Jaynes | WCABQ ’13
drewf.us/wcabq13
WHO I AM
Drew Jaynes
Web Engineer, 10up
Core Contributor
WordPress Docs Team
drewf.us/wcabq13
WHAT IS A FILTER?
A filter is a function that:
1.Takes a specific WordPress value
2. (maybe) modifies it
3. Spits the resulting value back out
drewf.us/wcabq13
OK ... ?
drewf.us/wcabq13
apply_filters()
drewf.us/wcabq13
apply_filters()
– 1,300+ filter hooks in core (3.6+)
– Filter values of all types, modify default behavior
– Multiple filters run per hook, based on priority
drewf.us/wcabq13
ADDING OR REMOVING FILTERS
add_filter( 'hook_name', 'callback', #priority, #args );
– When removing a filter, the hook, callback and priority must
match exactly. Fails silently.
remove_filter( 'hook_name', 'callback', #priority );
– Define priority any time. Define the args count + 1 if
additional args are passed from the filter hook
drewf.us/wcabq13
ALLTOGETHER NOW
// $value is filterable
apply_filters( ‘hook_name’, $value, (optional) $args );
function callback( $value, $arg ) {
// do stuff
return $value;
}
add_filter( 'hook_name', 'callback', 10, 2 );
drewf.us/wcabq13
CONTENT
drewf.us/wcabq13
‘enter_title_here’
Args:(string $enter_title_here, WP_Post $post)
– Match title prompt text to your custom post type
– Adds polish to the experience
Filter ‘Enter title here’ placeholder text
drewf.us/wcabq13
‘post_updated_messages’
Args:(array $messages)
– Not handled by WordPress out of the box
– Use with custom post types
– Customize ‘Post updated’,‘Post deleted’, etc.
Filter post updated|published|trashed|etc. messages.
drewf.us/wcabq13
‘admin_post_thumbnail_html’
Args:(string $content, int $post->ID)
‘media_view_strings’
Args:(array $strings, WP_Post $post)
Filter HTML output of Featured Image meta box
Filter media strings localized for JavaScript
drewf.us/wcabq13
WORKFLOW
drewf.us/wcabq13
‘the_editor_content’
Args:(string $content)
– Pre-fab post template
– Check if the content is empty
Filter the content in the editor (new and existing posts)
drewf.us/wcabq13
‘custom_menu_order’
Args:(bool false)
Enable/disable custom admin menu ordering
‘menu_order’
Args:(array $menu_order)
Filter the top-level menu order in the admin menu
drewf.us/wcabq13
‘custom_menu_order’
// enable custom menu order
add_filter( ‘custom_menu_order’, __return_true’ );
drewf.us/wcabq13
‘menu_order’
function change_menu_order( $menu_order );
return array(
'index.php',
'separator1',
'edit.php', 'edit.php?post_type=page',
'users.php', 'upload.php',
'edit-comments.php',
'separator2',
'themes.php', 'plugins.php',
'tools.php', 'options-general.php',
'separator-last'
);
}
add_filter( ‘menu_order’, ‘change_menu_order’ );
drewf.us/wcabq13
‘default_hidden_meta_boxes’
Args:(array $hidden, WP_Screen $screen)
– Standardize UX for all users
– Doesn’t prevent future user changes
Contextually filter meta boxes hidden by default
drewf.us/wcabq13
‘post_types_to_delete_with_user’
Args:(array $post_types_to_delete, int $id)
– Overrides ‘delete_with_user’ post type setting
Filter which post types to delete with a user
drewf.us/wcabq13
FRONT-END
drewf.us/wcabq13
‘the_content’
(string $content)
– Frequently used and abused in themes and plugins
– Litmus test: is it content?
Filter the post content
drewf.us/wcabq13
‘post|body_class’
Args:(array $classes)
– Reliant on themes using post|body_class() in templates
– Style things in specific contexts, e.g. post_type, post format, etc.
Filter body classes or post classes
drewf.us/wcabq13
‘excerpt_length’
Args:(int $number)
– Commonly filtered by themes, default is 55 characters
Filter the length (in characters) of the excerpt
drewf.us/wcabq13
‘show_admin_bar’
(bool true)
// Disable Toolbar
add_filter( ‘show_admin_bar’, ‘__return_false’ );
Show/hide theToolbar on the front-end
drewf.us/wcabq13
‘disable_captions’
(bool false)
// Disable captions
add_filter( ‘disable_captions’, ‘__return_true’ );
Disable/enable image captions
drewf.us/wcabq13
DEVELOPMENT
drewf.us/wcabq13
‘plugins|themes_api_*’
– Different result object, arguments, or complete overhaul
Filter plugin or theme installer pages
‘plugins|themes_api_args’
‘plugins|themes_api’
‘plugins|themes_api_result’
drewf.us/wcabq13
‘enable_post_by_email_configuration’
Args:(bool false)
// disable post by email
add_filter(
‘enable_post_by_email_configuration’,
‘__return_false’
);
Enable/disable Post by Email
drewf.us/wcabq13
MOAR DEV FILTERS
‘request’
Args:(array $query_vars)
Directly filter the current request’s query vars
‘shortcode_atts_$shortcode’
Args:(array $out, array $pairs, array $atts)
Filter a shortcode’s default attributes (3.6+)
– Output atts, default atts, user-defined atts
drewf.us/wcabq13
MOAR DEV FILTERS
‘wp_xmlrpc_server_class’
Args:(string $class)
Filter the class used for handling XML-RPC requests
‘xmlrpc_methods’
Args:(array $methods)
Register custom XML-RPC methods
drewf.us/wcabq13
QUESTIONS?

More Related Content

PPT
Nashvile Symfony Routes Presentation
PDF
TYPO3 CKEditor for integrators
PDF
JavaScript patterns
PPTX
WordPress plugin #3
PPTX
2.routing in zend framework 3
PDF
Add loop shortcode
KEY
Advanced Shell Scripting
ZIP
First Steps in Drupal Code Driven Development
Nashvile Symfony Routes Presentation
TYPO3 CKEditor for integrators
JavaScript patterns
WordPress plugin #3
2.routing in zend framework 3
Add loop shortcode
Advanced Shell Scripting
First Steps in Drupal Code Driven Development

What's hot (20)

PPTX
Анатолий Поляков - Drupal.ajax framework from a to z
PDF
Code igniter parameter passing techniques
TXT
Codigo taller-plugins
PDF
Laying the proper foundation for plugin and theme development
PDF
WordPress Configuration tips
PDF
Alfredo-PUMEX
PDF
Binary Studio Academy 2016: Laravel Routing
PDF
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
PDF
Coffeescript - Getting Started
PPTX
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
PPTX
Drupal sins 2016 10-06
PPTX
Amp Up Your Admin
PPT
e computer notes - Including constraints
PDF
Codeigniter : Custom Routing - Manipulate Uri
KEY
Keeping It Simple
PPT
My sql presentation
PDF
Friendlier, Safer WordPress Admin Areas
PDF
WordPress Capabilities Magic
PPTX
18. images in symfony 4
PDF
jQuery 實戰經驗講座
Анатолий Поляков - Drupal.ajax framework from a to z
Code igniter parameter passing techniques
Codigo taller-plugins
Laying the proper foundation for plugin and theme development
WordPress Configuration tips
Alfredo-PUMEX
Binary Studio Academy 2016: Laravel Routing
Puppet Camp Atlanta 2014: Continuous Deployment of Puppet Modules
Coffeescript - Getting Started
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
Drupal sins 2016 10-06
Amp Up Your Admin
e computer notes - Including constraints
Codeigniter : Custom Routing - Manipulate Uri
Keeping It Simple
My sql presentation
Friendlier, Safer WordPress Admin Areas
WordPress Capabilities Magic
18. images in symfony 4
jQuery 實戰經驗講座
Ad

Viewers also liked (6)

PDF
Trying Out Tomorrow’s WordPress Today
PDF
Getting Creative with WordPress Queries
PDF
It Takes a Village to Make WordPress
PDF
Core Docs: Sentencing WordPress to 11-years-to-life
PDF
Setting Up WordPress: A NUX Case Study
PDF
Anatomy of the WordPress Loop
Trying Out Tomorrow’s WordPress Today
Getting Creative with WordPress Queries
It Takes a Village to Make WordPress
Core Docs: Sentencing WordPress to 11-years-to-life
Setting Up WordPress: A NUX Case Study
Anatomy of the WordPress Loop
Ad

Similar to There's a Filter For That (20)

PDF
sfDay Cologne - Sonata Admin Bundle
PPTX
Magento Live Australia 2016: Request Flow
PDF
Using and reusing CakePHP plugins
PDF
Advanced symfony Techniques
PDF
Как получить чёрный пояс по WordPress? v2.0
PDF
What's new in jQuery 1.5
PPTX
Beyond DOMReady: Ultra High-Performance Javascript
PDF
Empowering users: modifying the admin experience
PDF
WordPress REST API hacking
PDF
"Angular.js Concepts in Depth" by Aleksandar Simović
PDF
ACL in CodeIgniter
PDF
Rails 3 overview
PPT
Easy rest service using PHP reflection api
PDF
Django Class-based views (Slovenian)
ODP
Aura Project for PHP
PDF
Alfredo-PUMEX
PDF
Alfredo-PUMEX
PDF
Alfredo-PUMEX
PDF
The Settings API
PDF
Best Practices in Plugin Development (WordCamp Seattle)
sfDay Cologne - Sonata Admin Bundle
Magento Live Australia 2016: Request Flow
Using and reusing CakePHP plugins
Advanced symfony Techniques
Как получить чёрный пояс по WordPress? v2.0
What's new in jQuery 1.5
Beyond DOMReady: Ultra High-Performance Javascript
Empowering users: modifying the admin experience
WordPress REST API hacking
"Angular.js Concepts in Depth" by Aleksandar Simović
ACL in CodeIgniter
Rails 3 overview
Easy rest service using PHP reflection api
Django Class-based views (Slovenian)
Aura Project for PHP
Alfredo-PUMEX
Alfredo-PUMEX
Alfredo-PUMEX
The Settings API
Best Practices in Plugin Development (WordCamp Seattle)

More from DrewAPicture (6)

PDF
WordPress Development in a Modern PHP World
PDF
WordPress Development in a Modern PHP World
PDF
Getting Creative with WordPress Queries, Again
PDF
How to Win Friends and Influence WordPress Core
PDF
Putting the (docs) Cart Before the (standards) Horse
PDF
Customizer-ing Theme Options: A Visual Playground
WordPress Development in a Modern PHP World
WordPress Development in a Modern PHP World
Getting Creative with WordPress Queries, Again
How to Win Friends and Influence WordPress Core
Putting the (docs) Cart Before the (standards) Horse
Customizer-ing Theme Options: A Visual Playground

Recently uploaded (20)

PDF
⚡ Prepping for grid failure_ 6 Must-Haves to Survive Blackout!.pdf
PPTX
Attitudes presentation for psychology.pptx
PDF
Red Light Wali Muskurahat – A Heart-touching Hindi Story
PPTX
Learn how to use Portable Grinders Safely
PDF
Attachment Theory What Childhood Says About Your Relationships.pdf
PDF
Quiet Wins: Why the Silent Fish Survives.pdf
PDF
SEX-GENDER-AND-SEXUALITY-LESSON-1-M (2).pdf
PPTX
Emotional Intelligence- Importance and Applicability
PDF
The Power of Pausing Before You React by Meenakshi Khakat
PPTX
show1- motivational ispiring positive thinking
DOCX
Boost your energy levels and Shred Weight
PDF
Elle Lalli on The Role of Emotional Intelligence in Entrepreneurship
PPTX
Learn about numerology and do tarot reading
PPTX
cấu trúc sử dụng mẫu Cause - Effects.pptx
PPTX
Commmunication in Todays world- Principles and Barriers
PPTX
Understanding the Self power point presentation
PPTX
Presentation on interview preparation.pt
PDF
Top 10 Visionary Entrepreneurs to Watch in 2025
PPTX
How to Deal with Imposter Syndrome for Personality Development?
PPTX
SELF ASSESSMENT -SNAPSHOT.pptx an index of yourself by Dr NIKITA SHARMA
⚡ Prepping for grid failure_ 6 Must-Haves to Survive Blackout!.pdf
Attitudes presentation for psychology.pptx
Red Light Wali Muskurahat – A Heart-touching Hindi Story
Learn how to use Portable Grinders Safely
Attachment Theory What Childhood Says About Your Relationships.pdf
Quiet Wins: Why the Silent Fish Survives.pdf
SEX-GENDER-AND-SEXUALITY-LESSON-1-M (2).pdf
Emotional Intelligence- Importance and Applicability
The Power of Pausing Before You React by Meenakshi Khakat
show1- motivational ispiring positive thinking
Boost your energy levels and Shred Weight
Elle Lalli on The Role of Emotional Intelligence in Entrepreneurship
Learn about numerology and do tarot reading
cấu trúc sử dụng mẫu Cause - Effects.pptx
Commmunication in Todays world- Principles and Barriers
Understanding the Self power point presentation
Presentation on interview preparation.pt
Top 10 Visionary Entrepreneurs to Watch in 2025
How to Deal with Imposter Syndrome for Personality Development?
SELF ASSESSMENT -SNAPSHOT.pptx an index of yourself by Dr NIKITA SHARMA

There's a Filter For That