• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
There's a Filter For That
 

There's a Filter For That

on

  • 8,440 views

Presented at WordCamp Albuquerque, Sept. 14, 2013.

Presented at WordCamp Albuquerque, Sept. 14, 2013.

Statistics

Views

Total Views
8,440
Views on SlideShare
2,257
Embed Views
6,183

Actions

Likes
0
Downloads
4
Comments
0

5 Embeds 6,183

http://werdswords.com 4998
http://snippets.khromov.se 1171
https://twitter.com 12
http://www.newsblur.com 1
http://translate.googleusercontent.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    There's a Filter For That There's a Filter For That Presentation Transcript

    • drewf.us/wcabq13 THERE’S A FILTER FORTHAT Drew Jaynes | WCABQ ’13 Saturday, September 14, 13
    • drewf.us/wcabq13 WHO I AM Drew Jaynes Web Engineer, 10up Core Contributor WordPress Docs Team Saturday, September 14, 13
    • drewf.us/wcabq13 WHAT IS A FILTER? A filter is a function that: 1.Takes a specific WordPress value 2. (maybe) modifies it 3.Then spits the resulting value back out Saturday, September 14, 13
    • drewf.us/wcabq13 OK ... ? Saturday, September 14, 13
    • drewf.us/wcabq13 apply_filters() Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • 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 ); Saturday, September 14, 13
    • drewf.us/wcabq13 CONTENT Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • drewf.us/wcabq13 ‘post_updated_messages’ Args:(array $messages) – Not handled by WordPress out of the box – Use with custom post types – Customize ‘Post ppdated’,‘Post deleted’, etc. Filter post updated|published|trashed|etc messages. Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • drewf.us/wcabq13 WORKFLOW Saturday, September 14, 13
    • 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) Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • drewf.us/wcabq13 ‘custom_menu_order’ // enable custom menu order add_filter( ‘custom_menu_order’, __return_true’ ); Saturday, September 14, 13
    • 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’ ); Saturday, September 14, 13
    • drewf.us/wcabq13 ‘default_hidden_meta_boxes’ Args:(array $hidden, WP_Screen $screen) – Standardize UX for all users – Doesn’t prevent future user changes Filter meta boxes hidden by default contextually Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • drewf.us/wcabq13 FRONT-END Saturday, September 14, 13
    • drewf.us/wcabq13 ‘the_content’ (string $content) – Used an abused often – Litmus test: is it content? Filter the post content Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • drewf.us/wcabq13 ‘excerpt_length’ Args:(int $number) – Commonly filtered by themes, defualt is 55 characters Filter the length (in characters) of the excerpt Saturday, September 14, 13
    • drewf.us/wcabq13 ‘show_admin_bar’ (bool true) // Disable Toolbar add_filter( ‘show_admin_bar’, ‘__return_false’ ); Show/hide theToolbar on the front-end Saturday, September 14, 13
    • drewf.us/wcabq13 ‘disable_captions’ (bool false) // Disable captions add_filter( ‘disable_captions’, ‘__return_true’ ); Disable/enable image captions Saturday, September 14, 13
    • drewf.us/wcabq13 DEVELOPMENT Saturday, September 14, 13
    • 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’ Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • 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 Saturday, September 14, 13
    • drewf.us/wcabq13 QUESTIONS? Saturday, September 14, 13