Reputation: 654
I'm pretty new at this Wordpress thingy and I've now made my own theme and would like to create a plugin that handles my slideshow.
(I have to teach this for some pupils later on, so I cannot just use an existing plugin)
I have implemented the autoloader from http://www.php-fig.org/psr/psr-0 at the bottom and it works fine.
I can call all the methods in my class and everything, so thats fine. Here's the actual question:
When the
register_activation_hook(__FILE__, array('vendor\Keystroke\KeystrokeSlider', 'install'));
is called, then it runs the method
class KeystrokeSlider{
const VERSION = '1.0.0';
static public function install(){
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$tableName = $wpdb->prefix . 'ks_albums';
$sql = "CREATE TABLE IF NOT EXISTS $tableName (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,
PRIMARY KEY (id)
) $charset_collate;";
self::upgrade();
dbDelta($sql);
add_option('keystroke_slider_version', self::VERSION);
}
}
but the dbDelta() is an undefined function. I could see that it was trying to set the namespace in front of the function (I don't know why, since it's not at class method, but a function, right?). Anyway I've tried calling it like this
\dbDelta()
That seems to be working, but It still can't find the function. Can I manually require the dbDelta in the class or is there something else wrong?
Sorry for the very long question...
Ulrik McArdle
Upvotes: 0
Views: 764
Reputation: 10346
According to the WP manual in order to use the dbDelta
function you first need to include the upgrade
file which contains that function.
Therefore, adding the following line of code above dbDelta($sql)
should fix the problem:
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
Upvotes: 1