Adding a table creation and update method.

This commit is contained in:
Eric van der Vlist 2011-06-03 18:39:32 +02:00
parent 86d7e64af5
commit 68b215972f
2 changed files with 45 additions and 5 deletions

View File

@ -2,9 +2,7 @@
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../wordpress_vdv/wp-content/plugins/owark"> <content url="file://$MODULE_DIR$/../wordpress/plugins/owark" />
<sourceFolder url="file://$MODULE_DIR$/../wordpress_vdv/wp-content/plugins/owark" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>

View File

@ -18,7 +18,7 @@
/* /*
Plugin Name: owark Plugin Name: owark
Plugin URI: http://owark.org Plugin URI: http://owark.org
Description: Tired of broken links? Archive yours with the Open Web Archive! Description: Tired of broken links? Archive yours with owark, the Open Web Archive!
Version: 0.1 Version: 0.1
Author: Eric van der Vlist Author: Eric van der Vlist
Author URI: http://eric.van-der-vlist.com Author URI: http://eric.van-der-vlist.com
@ -32,6 +32,7 @@ if (!class_exists("Owark")) {
private $broken_links = array(); private $broken_links = array();
private $post_id = -1; private $post_id = -1;
private $post_type = ""; private $post_type = "";
private $version = '0.1';
/** /**
* Class constructor * Class constructor
@ -43,7 +44,11 @@ if (!class_exists("Owark")) {
*/ */
function Owark() { function Owark() {
add_action('admin_menu', array($this, 'owark_admin_menu'));
if (is_admin()) {
add_action('admin_menu', array($this, 'owark_admin_menu'));
add_action('plugins_loaded', array($this, 'sanity_checks'));
}
// See http://stackoverflow.com/questions/2210826/need-help-with-wp-rewrite-in-a-wordpress-plugin // See http://stackoverflow.com/questions/2210826/need-help-with-wp-rewrite-in-a-wordpress-plugin
// Using a filter instead of an action to create the rewrite rules. // Using a filter instead of an action to create the rewrite rules.
@ -63,6 +68,43 @@ if (!class_exists("Owark")) {
} }
/**
* Check we have everything we need...
*
* @package owark
* @since 0.1
*
*
*/
function sanity_checks(){
$installed_ver = get_option( "owark_db_version" );
if ($installed_ver != $this->version) {
global $wpdb;
$table = $wpdb->prefix."owark";
$sql = "CREATE TABLE $table (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
url text NOT NULL,
status varchar(20) NOT NULL DEFAULT 'to-archive',
arc_date datetime,
arc_location text,
PRIMARY KEY(`id`),
KEY `url` (`url`(150)) )";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
update_option( "owark_db_version", $this->version );
}
}
/**
* Admin menus
*
* @package owark
* @since 0.1
*
*
*/
function owark_admin_menu() { function owark_admin_menu() {
add_management_page(__('The Open Web Archive', 'owark'), __('Web Archive', 'owark'), 'edit_others_posts', 'owark', array($this, 'management_page')); add_management_page(__('The Open Web Archive', 'owark'), __('Web Archive', 'owark'), 'edit_others_posts', 'owark', array($this, 'management_page'));
} }