Function Reference: geodir_payment_activation_script

Summary

This function has not been documented yet.

Actions

‘geodir_payment_package_table_created’ [Line: 608]

‘geodir_payment_invoice_table_created’ [Line: 671]

‘geodir_payment_coupon_table_created’ [Line: 692]

Filters

‘geodir_payment_package_table’ [Line: 604]

‘geodir_payment_invoice_table’ [Line: 667]

‘geodir_payment_coupon_table’ [Line: 688]

‘geodir_payment_.$key._payment_method’ [Line: 710]

Source Code

function geodir_payment_activation_script()
{
	global $wpdb,$plugin_prefix;
	
	$wpdb->hide_errors();
	
	/**
	 * Include any functions needed for upgrades.
	 *
	 * @since 1.0.0
	 */
	require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
	
	if($wpdb->query("SHOW TABLES LIKE 'geodir_price'")>0 && $wpdb->query("SHOW TABLES LIKE '".$wpdb->prefix."geodir_price'")==0){$wpdb->query("RENAME TABLE geodir_price TO ".$wpdb->prefix."geodir_price");}
	if($wpdb->query("SHOW TABLES LIKE 'geodir_invoice'")>0 && $wpdb->query("SHOW TABLES LIKE '".$wpdb->prefix."geodir_invoice'")==0){$wpdb->query("RENAME TABLE geodir_invoice TO ".$wpdb->prefix."geodir_invoice");}
	if($wpdb->query("SHOW TABLES LIKE 'geodir_coupons'")>0 && $wpdb->query("SHOW TABLES LIKE '".$wpdb->prefix."geodir_coupons'")==0){$wpdb->query("RENAME TABLE geodir_coupons TO ".$wpdb->prefix."geodir_coupons");}	
	
	$collate = '';
	if($wpdb->has_cap( 'collation' ) ) {
		if(!empty($wpdb->charset)) $collate = "DEFAULT CHARACTER SET $wpdb->charset";
		if(!empty($wpdb->collate)) $collate .= " COLLATE $wpdb->collate";
	}
		
// Table for storing place packages  - these are user defined

		$price_table = "CREATE TABLE ".GEODIR_PRICE_TABLE." (
					pid int(11) NOT NULL AUTO_INCREMENT,
					title varchar(255) NOT NULL,
					amount float(12,2) NOT NULL,
					cat text NOT NULL,
					status tinyint(2) NOT NULL DEFAULT '1',
					days int(10) NOT NULL,
					is_default tinyint(4) NOT NULL DEFAULT '0',
					is_featured tinyint(4) NOT NULL DEFAULT '0',
					title_desc text NOT NULL,
					image_limit varchar(255) NOT NULL,
					cat_limit varchar(255) NOT NULL,
					post_type varchar(255) NOT NULL,
					link_business_pkg varchar(255) NOT NULL,
					link_business_cpt varchar(255) NOT NULL,
					recurring_pkg varchar(255) NOT NULL,
					reg_desc_pkg varchar(255) NOT NULL,
					reg_fees_pkg varchar(255) NOT NULL,
					downgrade_pkg varchar(255) NOT NULL,
					sub_active varchar(255) NOT NULL,
					display_order INT( 11 ) NOT NULL DEFAULT '0',
					sub_units varchar(255) NOT NULL,
					sub_units_num varchar(255) NOT NULL,
					sub_num_trial_days varchar(255) NOT NULL,
					sub_num_trial_units varchar(1) NOT NULL DEFAULT 'D',
					sub_units_num_times varchar(255) NOT NULL,
					google_analytics TINYINT( 4 ) NOT NULL DEFAULT '0',
					sendtofriend TINYINT( 4 ) NOT NULL DEFAULT '0',
					use_desc_limit TINYINT( 1 ) NOT NULL DEFAULT '0',
					desc_limit INT( 11 ) NOT NULL DEFAULT '0',
					use_tag_limit TINYINT( 1 ) NOT NULL DEFAULT '0',
					tag_limit INT( 11 ) NOT NULL DEFAULT '0',
					hide_related_tab TINYINT( 1 ) NOT NULL DEFAULT '0',
					has_upgrades TINYINT( 1 ) NOT NULL DEFAULT '1',
					disable_coupon enum('0', '1') NOT NULL DEFAULT '0',
					PRIMARY KEY  (pid)) $collate";
					
		$price_table = apply_filters('geodir_payment_package_table' , $price_table);	
		
		dbDelta($price_table);
		
		do_action('geodir_payment_package_table_created' ,$price_table );
	
	/* ------- update post detail table start --- */
	$post_types = geodir_get_posttypes();
	
	if(!empty($post_types)){
	
		foreach($post_types as $post_type){
			
			$package_info = geodir_get_post_package_info_on_listing('', '', $post_type);
			
			$package_id = $package_info->pid;
			
			$table = $plugin_prefix.$post_type.'_detail';
			
			$wpdb->query($wpdb->prepare("UPDATE ".$table." SET package_id=%d WHERE package_id=0",array($package_id)));
			
			$wpdb->query(
				$wpdb->prepare(
					"UPDATE ".GEODIR_CUSTOM_FIELDS_TABLE." SET packages=%d WHERE post_type=%s AND (packages='0' || packages='')",
					array($package_id,$post_type)
				)
			);
			
			$meta_field_add = " ENUM( 'false', 'true' ) NOT NULL ";
			geodir_add_column_if_not_exist( $table, "expire_notification", $meta_field_add );
		}
	}	
		
	// Table for storing place packages  - these are user defined

		$invoice_table = "CREATE TABLE ".INVOICE_TABLE." (  
						 id int( 11  )  NOT  NULL  auto_increment ,
						 type varchar( 100  )  default NULL ,
						 post_id int( 11  )  NOT  NULL ,
						 post_title varchar( 255  )  default NULL ,
						 post_action varchar( 100  )  default NULL ,
						 invoice_type varchar(50) NOT NULL,
						 invoice_callback varchar(255) NOT NULL,
						 invoice_data text NOT NULL,
						 package_id int( 11  )  NOT  NULL ,
						 package_title varchar( 254  )  default NULL ,
						 amount float  default NULL ,
						 alive_days int( 11  )  default NULL ,
						 expire_date datetime  default NULL ,
						 user_id int( 11  )  default NULL ,
						 coupon_code varchar( 100  )  default NULL ,
						 coupon_usage enum('increase', 'decrease') DEFAULT NULL,
						 discount float  default NULL ,
						 tax_amount float(10,2) NOT NULL,
						 paied_amount float  default NULL ,
						 paymentmethod varchar( 100  )  default NULL ,
						 status varchar( 100  )  default NULL ,
						 subscription tinyint(1) NOT NULL DEFAULT '0',
						 HTML text,
						 is_current enum(  '1',  '0'  ) default  '0',
						 date datetime  default NULL ,
						 date_updated datetime NOT NULL,
						 PRIMARY KEY  (id)) $collate";
		$invoice_table = apply_filters('geodir_payment_invoice_table' , $invoice_table);
		
		dbDelta($invoice_table);
		
		do_action('geodir_payment_invoice_table_created' ,$invoice_table ) ;

	
	// Table for storing coupon  - these are user defined

		$coupon_table = "CREATE TABLE ".COUPON_TABLE." (
		cid int(11) NOT NULL AUTO_INCREMENT,
		coupon_code varchar(100) NOT NULL,
		post_types varchar(255) NOT NULL,
		recurring varchar(255) NOT NULL DEFAULT '0',
		discount_type varchar(5) NOT NULL,
		discount_amount float NOT NULL,
		status enum('0','1') NOT NULL DEFAULT '0',
		usage_limit varchar(11) DEFAULT NULL,
		usage_count int(11) NOT NULL DEFAULT '0',
		PRIMARY KEY  (cid)) $collate";
					
		$coupon_table = apply_filters('geodir_payment_coupon_table' , $coupon_table);
		
		dbDelta($coupon_table);
		
		do_action('geodir_payment_coupon_table_created' ,$coupon_table ) ;

	
	//////////paypal settings start////////
	$paymenthodinfo = geodir_get_additional_pay_options();
	
	if(!empty($paymenthodinfo)){
	
		for($i=0;$i $value)
		{
			
			$paymentsql = $wpdb->prepare("select * from $wpdb->options where option_name like %s order by option_id asc", array('payment_method_'.$key));
			
			$paymentinfo = $wpdb->get_results($paymentsql);
			
			if(empty($paymentinfo))
			{
				$value = apply_filters('geodir_payment_'.$key.'_payment_method' ,$value);
				$paymenthodArray = array("option_name"	=>	'payment_method_'.$key, "option_value"	=>	serialize($value),);
				
				$wpdb->insert( $wpdb->options, $paymenthodArray );
			}
		}
		
	}
		
}