function install() { global $wpdb, $current_site; //check if multisite is installed if ( ! is_multisite() ) { $this->trigger_install_error( __( 'WordPress multisite is required to run this plugin. <a target="_blank" href="http://codex.wordpress.org/Create_A_Network">Create a network</a>.', 'psts' ), E_USER_ERROR ); } //rename tables if upgrading from old supporter if ( get_site_option( "supporter_installed" ) == "yes" ) { $wpdb->query( "RENAME TABLE `{$wpdb->base_prefix}supporters` TO `{$wpdb->base_prefix}pro_sites`" ); $wpdb->query( "RENAME TABLE `{$wpdb->base_prefix}supporter_signup_stats` TO `{$wpdb->base_prefix}pro_sites_signup_stats`" ); $wpdb->query( "RENAME TABLE `{$wpdb->base_prefix}supporter_daily_stats` TO `{$wpdb->base_prefix}pro_sites_daily_stats`" ); delete_site_option( "supporter_installed" ); } if( ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', false ); } $table1 = "CREATE TABLE {$wpdb->base_prefix}pro_sites ( blog_ID bigint(20) NOT NULL, level int(3) NOT NULL DEFAULT 1, expire bigint(20) NOT NULL, gateway varchar(25) NULL DEFAULT '', term varchar(25) NULL DEFAULT NULL, amount varchar(10) NULL DEFAULT NULL, is_recurring tinyint(1) NULL DEFAULT 1, meta longtext NOT NULL, identifier varchar(50) NULL, PRIMARY KEY (blog_ID), KEY (blog_ID,level,expire) );"; $table2 = "CREATE TABLE {$wpdb->base_prefix}pro_sites_signup_stats ( action_ID bigint(20) unsigned NOT NULL auto_increment, blog_ID bigint(20) NOT NULL, action varchar(20) NOT NULL, time_stamp DATE NOT NULL, PRIMARY KEY (action_ID) );"; $table3 = "CREATE TABLE {$wpdb->base_prefix}pro_sites_daily_stats ( id bigint(20) unsigned NOT NULL auto_increment, date DATE NOT NULL, supporter_count int(10) NOT NULL DEFAULT 0, expired_count int(10) NOT NULL DEFAULT 0, term_count_1 int(10) NOT NULL DEFAULT 0, term_count_3 int(10) NOT NULL DEFAULT 0, term_count_12 int(10) NOT NULL DEFAULT 0, term_count_manual int(10) NOT NULL DEFAULT 0, level_count_1 int(10) NOT NULL DEFAULT 0, level_count_2 int(10) NOT NULL DEFAULT 0, level_count_3 int(10) NOT NULL DEFAULT 0, level_count_4 int(10) NOT NULL DEFAULT 0, level_count_5 int(10) NOT NULL DEFAULT 0, level_count_6 int(10) NOT NULL DEFAULT 0, level_count_7 int(10) NOT NULL DEFAULT 0, level_count_8 int(10) NOT NULL DEFAULT 0, level_count_9 int(10) NOT NULL DEFAULT 0, level_count_10 int(10) NOT NULL DEFAULT 0, PRIMARY KEY (id) );"; $table4 = "CREATE TABLE {$wpdb->base_prefix}pro_sites_transactions ( id bigint(20) unsigned NOT NULL auto_increment, transaction_id varchar(255) NOT NULL, transaction_date DATE NOT NULL, items longtext NOT NULL, total decimal(13,4) NOT NULL DEFAULT 0, sub_total decimal(13,4) NOT NULL DEFAULT 0, tax_amount decimal(13,4) NOT NULL DEFAULT 0, tax_percentage decimal(4,2) NOT NULL DEFAULT 0, country varchar(3) NULL, currency varchar(3) NULL, meta longtext NULL, PRIMARY KEY (id), KEY (id, transaction_id) );"; if ( ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) || ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && ! DO_NOT_UPGRADE_GLOBAL_TABLES ) ) { require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $table1 ); dbDelta( $table2 ); dbDelta( $table3 ); dbDelta( $table4 ); } // add stats cron job action only to main site (or it may be running all the time!) switch_to_blog( $current_site->blog_id ); if ( ! wp_next_scheduled( 'psts_process_stats' ) ) { //get end of day $time = strtotime( date( "Y-m-d 23:50:00" ) ); wp_schedule_event( $time, 'daily', 'psts_process_stats' ); } restore_current_blog(); //our default settings $default_settings = ProSites::get_default_settings_array(); $settings = wp_parse_args( ( array ) get_site_option( 'psts_settings' ), $default_settings ); update_site_option( 'psts_settings', $settings ); //default level $default_levels = array( 1 => array( 'name' => __( 'Pro', 'psts' ), 'price_1' => get_site_option( "supporter_1_whole_cost" ) . '.' . get_site_option( "supporter_1_partial_cost" ), 'price_3' => get_site_option( "supporter_3_whole_cost" ) . '.' . get_site_option( "supporter_3_partial_cost" ), 'price_12' => get_site_option( "supporter_12_whole_cost" ) . '.' . get_site_option( "supporter_12_partial_cost" ) ) ); if ( ! get_site_option( 'psts_levels' ) ) { add_site_option( 'psts_levels', $default_levels ); } //create a checkout page if not existing add_action( 'init', array( &$this, 'create_checkout_page' ) ); //3.4.3.8 upgrade - fixes permanent upgrades that got truncated on 32 bit systems due to (int) casting if ( version_compare( $this->get_setting( 'version' ), '3.4.3.7', '<=' ) ) { $wpdb->query( "UPDATE {$wpdb->base_prefix}pro_sites SET expire = '9999999999' WHERE expire = '1410065407'" ); } //3.5 upgrade - modify pro_sites table if ( version_compare( $this->get_setting( 'version' ), '3.5', '<=' ) ) { // Using dbDelta above, but add other code here. //$wpdb->query( "ALTER TABLE {$wpdb->base_prefix}pro_sites ADD meta longtext NOT NULL" ); } $this->update_setting( 'version', $this->version ); }