get_var("show tables like'" . table_name_with_prefix($table_name) . "'") != table_name_with_prefix($table_name)) { require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $sql_create_func = "sql_create_$table_name"; $sql = $sql_create_func(); add_option("hoges_version", '1.0'); dbDelta($sql); } } function table_name_with_prefix($table_name) { global $wpdb; return $wpdb->prefix . $table_name; } function sql_create_alert_post_options() { return "CREATE TABLE " . table_name_with_prefix('alert_post_options') . "( id int not null auto_increment, name varchar(255) not null, validity boolean default 0, primary key(id) );"; } function plugin_menu() { add_options_page('My Plugin Options', 'Alert Before Post',8, __FILE__, 'my_plugin_options'); } function my_plugin_options() { global $wpdb; global $current_user; get_currentuserinfo(); if (isset($_POST['name'])){ $wpdb->update( $wpdb->prefix.'alert_post_options', array( 'validity'=> $_POST['val']), array( 'name'=> $_POST['name']) ); } if(count($wpdb->get_results("SELECT * FROM ".$wpdb->prefix."alert_post_options WHERE name =".$current_user->ID)) <= 0) { $wpdb->insert( $wpdb->prefix.'alert_post_options', array( 'name' => $current_user->ID, 'validity' => 0) ); } echo "
"; } function mypluginAddHeaderFirst() { global $wpdb; global $current_user; get_currentuserinfo(); echo ""; if(count($wpdb->get_results("SELECT * FROM ".$wpdb->prefix."alert_post_options WHERE name =".$current_user->ID)) <= 0) { return false; } $result = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."alert_post_options WHERE name =".$current_user->ID); if($result->validity == 0) { return false; } echo <<