我试图创建一个小插件,但当我激活插件时,它并没有在数据库中创建表。请看下面给出的代码有功能function jal_install ()
它没有被调用。
<?php
/*
Plugin Name: My-Ads
Plugin URI: http://wordpress.org/#
Description: This is the most basic wordpress plugin, gets input from the user and displays it on every page.
Author: shalu
*/
/*when plugin is activated*/
register_activation_hook(_FILE_,\'my_first_install\');
/*when plugin is deactivated*/
register_deactivation_hook( __FILE__, \'my_first_remove\' );
function my_first_install()
{
add_option("my_first_data", \'Testing !! My Plugin is Working Fine.\', \'This is my first plugin panel data.\', \'yes\');
}
function my_first_remove()
{
/* Deletes the database field */
delete_option(\'my_first_data\');
}
/*Code-Add Admin Panel Menu Item*/
if(is_admin())
{
add_action(\'admin_menu\',\'my_first_admin_menu\');
function my_first_admin_menu()
{
add_options_page(\'My First\', \'Ads\', \'administrator\',\'my-first\', \'my_first_plugin_page\');
}
}
function my_first_plugin_page() {
?>
<div>
<h2>Add your ads from here</h2>
<form method="post" action="options.php" enctype="multipart/form-data">
<?php wp_nonce_field(\'update-options\'); ?>
<table width="510">
<tr valign="top">
<th width="92" scope="row">Name:</th>
<td width="406">
<input name="my_first_data" type="text" id="my_first_data" value="<?php echo get_option(\'my_first_data\'); ?>" /></td>
</tr>
<tr>
<th width="92" scope="row">Target Url:</th>
<td width="406">
<input name="Target_Url" type="text" id="Target_Url" value="<?php echo get_option(\'Target_Url\'); ?>" />
</td>
<tr>
<tr>
<th width="92" scope="row">Ad image:</th>
<td width="406">
<input name="file" type="file" id="file"/></td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="my_first_data" />
<p>
<input type="submit" value="<?php _e(\'Save Changes\') ?>" />
</p>
</form>
</div>
<?php
}
/* This calls my_first() function when wordpress initializes.*/
function my_first()
{
echo get_option(\'my_first_data\');
}
function jal_install () {
global $wpdb;
global $jal_db_version;
$table_name = $wpdb->prefix . "liveshoutbox";
echo $table_name;
if($wpdb->get_var("show tables like \'$table_name\'") != $table_name) {
$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time bigint(11) DEFAULT \'0\' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url VARCHAR(55) NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . \'wp-admin/includes/upgrade.php\');
dbDelta($sql);
$rows_affected = $wpdb->insert( $table_name, array( \'time\' => current_time(\'mysql\'), \'name\' => $welcome_name, \'text\' => $welcome_text ) );
add_option("jal_db_version", $jal_db_version);
}
}
//calling the function
register_activation_hook(__FILE__,\'jal_install\');
?>
请帮助我问题出在哪里。我将非常感谢你