( Jump to Resources )
function fe_example( $str ) {
return $str;
}
function fe_phil( $str ) {
return "No, " . $str;
}
add_filter( 'the_title', 'fe_phil' );
function fe_phil( $str ) {
return "No, " . $str;
}
add_filter( 'login_message', 'fe_login_mg' );
function fe_login_mg( $orig ) {
return
'Use your words wisely
' . $orig;
}
add_filter( 'admin_footer_text', 'fe_aft' );
function fe_aft( $orig ) {
return ''
. 'This site created by Sal'
. 'with WordPress';
}
Before Filter
With Filter
functions.php
mu-plugins
directory/wp-content/mu-plugins/
/wp-content/mu-plugins/phil.php
add_filter( 'the_content', 'fe_disclaimer' );
function fe_disclaimer( $content ) {
return $content
. ''
. 'My personal opinion'
. '
';
}
add_filter(
'comments_open', '__return_false' );
add_filter( 'the_content_feed', 'fe_rss_ad');
function fe_rss_ad( $content ) {
$hire_blurb = "\nHire Sal
\n";
return $content . $hire_blurb;
}
add_filter(
'hook', // what to filter
'function_name', // a.k.a. callback
);
add_filter(
'hook', // what to filter
'function_name', // a.k.a. callback
10, // priority (order)
1 // # of args to pass in
);
Order in which the filters are applied.
add_filter( 'the_title', 'fe_colon', 10 );
add_filter( 'the_title', 'fe_paren', 10 );
"About Sal"
becomes "About Sal :)"
add_filter( 'the_title', 'fe_colon', 10 );
add_filter( 'the_title', 'fe_paren', 5 );
"About Sal"
becomes "About Sal ):"
Pass the function two values
add_filter(
'comments_open', 'fe_no_page_com', 10, 2);
function fe_no_page_com( $open, $post_id ) {
$post_type = get_post_type( $post_id );
if ( 'page' === $post_type ) {
return false;
}
return $open;
}
See comments_open documentation
Over 1,300 of them
Plugins often have filters too
Was not stopping BuddyPress notifications
add_filter(
'bp_email_use_wp_mail',
'__return_true'
);
See commit ad09c1d
"correct horse battery staple"
hash function outputs"zyxc4bbcb1fbec99d65bf59d85c"
What you typed in gets goes through the hash function and compared to the stored value "zyxc4bbcb1fbec99d65bf59d85c"
Magento and WordPress use two different hashing functions
to the rescue
add_filter(
'check_password', 'fe_mg_pwd', 10, 2 );
function fe_mg_pwd( $allowed, $plain_pwd ) {
$hashed_pwd = magento_hash( $plain_pwd );
if ( $hashed_pwd === $stored_mg_hash ) {
return true;
}
return $allowed;
}