Support » Plugins » Hacks » get_plugin_data() is undefined function?

  • I have the following code in my plugin’s main file:

    $_ENV['cc_author_plugindata'] = get_plugin_data( __FILE__, false );

    I get the following error:

    Fatal error: Call to undefined function get_plugin_data()

    I’m inside wp-admin, so I’m not sure why this function isn’t available. What’s going wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    Plugins are loaded fairly early and WP isn’t fully functional yet. You probably need to use the function from within an action callback that fires later in the process. If you can wait that long, ‘init’ should work.

    Oh, I’m following you. Yeah, I’m calling get_plugin_data() immediately in the script.

    I’ll try finding a place further down to place it that will still allow me to get it when I need it.

    It’s working now! I moved the call into my main admin file, and put it inside a function called by the ‘admin_init’ hook. Here’s the code:

    function cc_author_admin_init() {
    	/* Set plugin version data for use elsewhere in the plugin */
    	if ( function_exists( 'get_plugin_data' ) ) {
    		$_ENV['cc_author_plugindata'] = get_plugin_data( plugin_dir_path( dirname( __FILE__ ) ) . 'author-customization.php', false );
    	else { // If the function get_plugin_data does not exist, return empty array
    		$_ENV['cc_author_plugindata'] = array(
    			'Version'	=>	''
    add_action( 'admin_init', 'cc_author_admin_init' ); // Hook plugin admin initialization

    Thanks for the help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_plugin_data() is undefined function?’ is closed to new replies.