web/wp-content/themes/selecta/ocmx/ocmx-setup.php
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php
       
     2 /*
       
     3 	good to use this instead of the $wpdb->query(): require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
       
     4 	dbDelta($createClientsTable);
       
     5 */
       
     6 function install_ocmx()
       
     7 	{
       
     8 		global $wpdb;
       
     9 		
       
    10 		$comment_table = $wpdb->prefix . "ocmx_comment_meta";	
       
    11 		if(!check_table_existance($main_table)) :
       
    12 			
       
    13 			$comment_meta_table = "CREATE TABLE `".$comment_table."` (			
       
    14 			`commentId` MEDIUMINT(8) unsigned NOT NULL PRIMARY KEY,
       
    15 			`twitter` VARCHAR(255),
       
    16 			`block_user` TINYINT,
       
    17 			`email_subscribe` TINYINT);";
       
    18 			
       
    19 			mysql_query($comment_meta_table);
       
    20 			$comments_sql = "SELECT * FROM $wpdb->comments";
       
    21 			$comments_query = $wpdb->get_results($comments_sql);
       
    22 			
       
    23 			foreach($comments_query as $comment) :
       
    24 				if($comment->comment_subscribe == "Y") :
       
    25 					$comment_subs = "1";
       
    26 				else :
       
    27 					$comment_subs = "0";
       
    28 				endif;
       
    29 				$meta_update = $wpdb->query
       
    30 					($wpdb->prepare
       
    31 						("INSERT INTO $comment_table
       
    32 							(commentId, twitter, email_subscribe)
       
    33 						VALUES
       
    34 							(%d, %s, %s);", 
       
    35 						$comment->comment_ID, "", $comment_subs)
       
    36 					);
       
    37 			endforeach;
       
    38 		endif;
       
    39 	}
       
    40 	
       
    41 function check_table_existance($new_table) {
       
    42 	global $wpdb;
       
    43 	
       
    44 	foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
       
    45 		if ($table == $new_table) {
       
    46 			return true;
       
    47 		}
       
    48 	}
       
    49 	return false;
       
    50 }
       
    51 ?>