user2679476
user2679476

Reputation: 419

add_action() in wordpress uses php file name as first parameter. What does it mean?

Recently I am trying to understand the codebase of a custom wordpress plugin. Some syntax of add_action() looks confusing to me.

add_action( 'after_plugin_row_wc-smart-cod/wc-smart-cod.php', array( $this, 'add_warning' ) );

I know the first parameter of add_action() is the name of the action to which the function 'add_warning' of $this object is hooked. But in the above example the first parameter is the name of a php file, instead of an action name. What does it mean ?

Thanks.

Upvotes: 0

Views: 416

Answers (1)

Chris Haas
Chris Haas

Reputation: 55447

The first parameter to an action is a string. Generally it is something like wp_footer or before_send_email but there really isn't any restrictions on it. For instance, in my company's code, we often use slashes to give the action a (fake) namespace such as company/plugin-name/class/action but this is 100% arbitrary from WordPress's perspective.

Back to your example, however, there actually is a specific pattern from WordPress for that specific hook which you can see here. Every plugin in WordPress has an "entrance" or "plugin" file that boots up the entire plugin. Because most plugins live in a sub-folder, it is often plugin-name/plugin-name.php or plugin-name/index.php but it is ultimately up to the plugin author.

Most people use that specific action to add special messages to their own plugin's row in the general listing of plugins. The plugin you mentioned is using it to give a warning to users with a very specific version of the plugin installed.

Upvotes: 1

Related Questions