Actions and Filters aka Hooks
Hooks are provided by WordPress to allow your plugin to 'hook into' the rest of WordPress; that is, to call functions in your plugin at specific times.
Put all your hook registrations at the top of your file. This way it is easier to see what you are hooking into and makes it easier to debug.
Actions
add_action ( 'hook_name', 'your_function_name', [priority], [accepted_args] );
Example:
function on_publish_post() {
//do something when the publish post action is triggered
}
add_action('publish_post', 'on_publish_post');
Avoiding function name collisions by making sure the function is not available on the global scope. You can prevent this by using a namespace in your file and/or enclose your plugin functions in a class and call the class methods statically.
Example:
<?php
namespace MW\Ripples\Classes\Posts
class Poster {
static function on_publish_post($post_ID) {
//do something when the publish post action is triggered
}
}
add_action('publish_post', array('Poster', 'on_publish_post', 10, 1));