WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm receiving this error: [27-Jun-2012 18:22:39 UTC] PHP Fatal error: Call to undefined function plugin_basename() in /XXXX/public_html/wp-content/plugins/price-update/price-update.php on line 68:

            //We set the plugin basename here, could manually set it, but this is for demonstration purposes
            $this->plugin_basename = plugin_basename(__FILE__);

in this block of code:

class PriceUpdate extends mtekk_admin
        protected $version = '0.0.1';
        protected $full_name = 'Price Update';
        protected $short_name = 'Price Update';
        protected $access_level = 'manage_options';
        protected $identifier = 'pr_upate';
        protected $unique_prefix = 'prud';
        protected $plugin_basename = 'price-update/price-update.php';
        protected $opt = array();
         * __construct()
         * Class default constructor
        function __construct()
                //We set the plugin basename here, could manually set it, but this is for demonstration purposes
                $this->plugin_basename = plugin_basename(__FILE__);
                register_deactivation_hook(__FILE__, array($this, 'deactivate'));
                add_action($this->unique_prefix . '_cron_hook', array($this,'cron_handle'));
                //Register some of our custom taxonomies
                add_action('init', array($this, 'wp_init'), 0);
                add_action('wp_footer', array($this, 'footer'));
                //We're going to make sure we load the parent's constructor

However, its defined above:

        protected $plugin_basename = 'price-update/price-update.php';

any ideas?

share|improve this question
The plugin_basename function does exist, and it is in wp-includes/plugin.php, and has been around since version 1.5 or so. If you're getting an undefined error, then you have a broken or incomplete copy of WordPress somehow, or you're calling your plugin incorrectly in some manner. Either way, the answer is not capable of being reached from the limited amount of code you've posted here. – Otto Jul 1 '12 at 11:49
pastebin.com/UmCkUrZp is the complete file – whatsthebigidea Jul 1 '12 at 20:24

plugin_basename is a WordPress function that gets your plugins file name by simply passing it the directory.

When you call $this->plugin_basename PHP is looking for a function plugin_basename defined within YOUR class. No function plugin_basename() in your class == PHP Fatal Error.

If you simply want to define a variable that contains the plugins file name do this:

var $plugin_filename = plugin_basename( __FILE__);

share|improve this answer
Not quite correct. When you reference $this->plugin_basename it is looking for a member variable that is $plugin_basename (which exists). If there was a call to $this->plugin_basename() then PHP would be looking for the member function plugin_basename() – mtekk Jul 4 '12 at 0:47

Perhaps you'd be better off using plugin_dir_path(__FILE__);?


define( 'MYPLUGINNAME_PATH', plugin_dir_path(__FILE__) );
require MYPLUGINNAME_PATH . 'includes/class-metabox.php';
require MYPLUGINNAME_PATH . 'includes/class-widget.php';

[EDIT - 06/29/2012]

I believe you have your PHP OOP logic incorrect, but I could be wrong. You're defining a property in a child class which extends a parent class. You then call the parent constructor inside the child constructor.

The code you provided shows that you assign the child class property $plugin_basename, but then you don't do anything with it after that.

I'm assuming you're trying to set a property $plugin_basename for the parent class to handle. However, if that's the case, then you need to either define the property within the parent class, OR you need to call the parent method which makes use the property $plugin_basename.

If that's NOT the case, then you need to be sure you make use of the property $plugin_basename, within the child class, AFTER it's been assigned like so: $this->child_class_method_name($this->plugin_basename);

You could access the parent class method which handles the property $plugin_basename, and pass the property assigned by the child class to the parent class method like so: $this->parent_class_method_name($this->plugin_basename);

I'm not really too certain how you have your plugin setup, given the minimal amount of code you provided.

If you could provide more of an idea of what you do with the property $plugin_basename, after it's been assigned, I could possibly be of more assistance.

share|improve this answer
I changed it to: $this->plugin_basename = plugin_dir_path(__FILE__); and still getting the same type error: [28-Jun-2012 15:01:43 UTC] PHP Fatal error: Call to undefined function plugin_dir_path() in /home/whatsthe/public_html/wp-content/plugins/price-update/price-update.php on line 68 – whatsthebigidea Jun 28 '12 at 15:07
@whatsthebigidea Please read my updated response, regarding your question. – Michael Ecklund Jun 29 '12 at 20:20
The mtekk_admin class, an older version of this: github.com/mtekk/Breadcrumb-NavXT/blob/master/includes/… does have the basename property, and the basename is used in the various areas that the WP API needs it (some hooks for example). – mtekk Jul 4 '12 at 0:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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