add_action,add_filter,user_can ect in wordpress

I have developed wordpress for days,but I have found no way to these like:add_action,add_filter,user_can, I don’t know what are the functions they refere to.
worse still,I don’t know the parameter,today I want add a column to user list table admin panel,I fortunatelly found a tutorial, here is the code

add_filter( 'manage_users_columns', 'add_user_column');
function add_user_column( $columns){
     $columns['available_stickers'] = __('Stickers Available', 'available_stickers');
     return $columns;   
}
add_filter('manage_users_custom_column',  'add_user_column_value', 10, 3);
function add_user_column_value( $value, $column_name, $user_id ){
     if ( 'available_sticker' == $column_name)
          $value = get_user_meta($user_id,"available_stickers",true);
     return $value;
}

Even thought I made it, but I don’t know where the parameter manage_users_columns comes or why I should use manage_users_columns but not other code? Puzzled
and also they have matched code like apply_filter etc.
some one can help me out of the maze,oops!

Related posts

Leave a Reply

1 comment

  1. WordPress is beautifully designed because most of the actions it does are not executed directly, but through what are called actions and filters. This gives you, the developer, a possibility to hook onto any of these operations. Hooking means you can squeeze your own logic right in the middle of WP’s logic, in a very clean way, only by declaring that you want things to be done where the corresponding hooks are used. More precisely:

    Actions

    So, for example, when a post is saved, WordPress does not just save the post, it does it by executing this line:

    do_action( 'save_post', $post_ID, $post );
    

    This is a way to give a name to this action (save_post). That means two things :

    1) you can execute the exact same action by using the same line of code somewhere else.

    2) you can add your own logic to be executed during this action. How? just by “adding” your custom functions to the action, like this :

    add_action('save_post', 'name_of_the_function_you_want_to_execute_when_post_is_saved');
    

    So ‘save_post’ is the name of the hook, add_action gives you the possibility to add your own function to the action for this hook and do_action actually executes the action.

    Filters

    Filters are similar to actions, but instead of being used when executing a command, they are used to treat a value, an object, a string or some text (when “filtering” it). Again, instead of just manipulating objects and strings in such a way that you would have no other possibility than dive into the core code to access it, WordPress cleverly does many of its “filtering” operations with a special action called apply_filters(). This gives you the possibility, like for actions, to actually add your own filters to the filters already applied. So when showing the content of a post, WP would execute :

    apply_filters('the_content', $post->post_content);
    

    The name of the hook is the_content. If you use :

    add_filter('the_content', 'your_function_to_execute_to_further_filter_content');
    

    you can have a function named your_function_to_execute_to_further_filter_content()that can take the content as a parameter and return the filtered version of it after whatever treatment you wish to apply to it. Then this treatment will get applied anywhere in WP where the hook the_content is used to execute these filters (including WP default ones, plug-ins filters that were added to the same hook, and your own).

    So here, you are using these hooks so you can interfere with WP operations without messing WP core code. You declare the extra operations you wish to execute and you let WP aware of this. WP will then have the courtesy to execute your functions everytime the corresponding hook action or filter is being executed.