I'm developing a plugin and I've organized its code in separate files. The admin functions file is inside an /admin subfolder. In this file I enqueue scripts and styles, add meta boxes and so on.

I'd like to add some action links to the installed plugins screen using the plugin_action_links_{$plugin_file} hook, but I cannot get it to work.

As this hook is added outside the main plugin file this doesn't work:

add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ),  array( $this, 'add_action_links' ) );

My question is, how can I get the plugin_basename() of the main plugin file from a different file in a subfolder? Is it possible?

Thanks in advance

1 Answer 1


You can simply store the basename in a variable in the main file and reference that variable in the admin file.

If you are using classes, which I determine from your example code, you can simply create a static property in you main class and reference that in the admin class:

class My_Plugin {
    static $basename = null;

    public function __construct {
        $this->basename = plugin_basename(__FILE__);

class My_Plugin_Admin {
    public function change_action_links() {
        add_filter( 'plugin_action_links_' . My_Plugin::$basename,  array( $this, 'add_action_links' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.