# ACTIONS -- side effects, no return value needed
function send_welcome_email($user_id) {
$user = get_userdata($user_id);
wp_mail($user->user_email, 'Welcome!', 'Thanks for joining.');
}
add_action('user_register', 'send_welcome_email');
# FILTERS -- transform a value, MUST return it
function add_copyright($content) {
if (is_single()) {
$content .= '© ' . date('Y') . ' My Company
';
}
return $content; // MUST return!
}
add_filter('the_content', 'add_copyright');
# Priority (lower = runs first, default = 10)
add_action('init', 'my_function', 5);
# Remove hooks
remove_action('wp_head', 'wp_generator');
remove_filter('the_content', 'wpautop');
# Key difference:
# add_action -- do something at a point
# add_filter -- modify something and return it