PHP Fatal error: Call to undefined function plugin_basename

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:

Read More
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
                parent::__construct();
        }

However, its defined above:

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

any ideas?

Related posts

Leave a Reply

2 comments

  1. 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__);

  2. Perhaps you’d be better off using plugin_dir_path(__FILE__);?

    Example:

    <?php
    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.