Parcourir la source

Bumped version to 0.0.52

Jannick Knudsen il y a 4 ans
Parent
commit
dac2c2e3a7
6 fichiers modifiés avec 276 ajouts et 331 suppressions
  1. 1 1
      VERSION
  2. 1 0
      VERSIONLOG
  3. 1 1
      package.json
  4. 154 191
      plug_usermanager.php
  5. 117 136
      plug_woohook.php
  6. 2 2
      plugin.php

+ 1 - 1
VERSION

@@ -1 +1 @@
-v0.0.51
+v0.0.52

+ 1 - 0
VERSIONLOG

@@ -50,3 +50,4 @@ v0.0.48
 v0.0.49
 v0.0.50
 v0.0.51
+v0.0.52

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "dagsplug",
-  "version": "0.0.51",
+  "version": "0.0.52",
   "description": "",
   "main": "script_backend.js",
   "scripts": {

+ 154 - 191
plug_usermanager.php

@@ -2,36 +2,38 @@
 
 if (!class_exists("plug_usermanager")) {
 
-	function arrayFromCSV($file, $hasFieldNames = false, $delimiter = ',', $enclosure='') {
-	    $result = Array();
-	    $size = filesize($file) +1;
-	    $file = fopen($file, 'r');
-	    #TO DO: There must be a better way of finding out the size of the longest row... until then
-	    if ($hasFieldNames) $keys = fgetcsv($file, $size, $delimiter, $enclosure);
-	    while ($row = fgetcsv($file, $size, $delimiter, $enclosure)) {
-	        $n = count($row); $res=array();
-	        for($i = 0; $i < $n; $i++) {
-	            $idx = ($hasFieldNames) ? $keys[$i] : $i;
-	            $res[$idx] = $row[$i];
-	        }
-	        $result[] = $res;
-	    }
-	    fclose($file);
-	    return $result;
-	  }
+	function arrayFromCSV($file, $hasFieldNames = false, $delimiter = ',', $enclosure = '') {
+		$result = Array();
+		$size = filesize($file) + 1;
+		$file = fopen($file, 'r');
+		#TO DO: There must be a better way of finding out the size of the longest row... until then
+		if ($hasFieldNames) {
+			$keys = fgetcsv($file, $size, $delimiter, $enclosure);
+		}
+
+		while ($row = fgetcsv($file, $size, $delimiter, $enclosure)) {
+			$n = count($row);
+			$res = array();
+			for ($i = 0; $i < $n; $i++) {
+				$idx = ($hasFieldNames) ? $keys[$i] : $i;
+				$res[$idx] = $row[$i];
+			}
+			$result[] = $res;
+		}
+		fclose($file);
+		return $result;
+	}
 	function sanitize_username($username) {
-	  $parts = explode("@", $username);
-	  if (count($parts) == 2) {
-	     $username = $parts[0];
-	  }
-	  return $username;
+		$parts = explode("@", $username);
+		if (count($parts) == 2) {
+			$username = $parts[0];
+		}
+		return $username;
 	}
 
-
-
-	class plug_usermanager {	
+	class plug_usermanager {
 		function __construct($ns) {
-			$this->title = __("plug_usermanager","dagsopt");
+			$this->title = __("plug_usermanager", "dagsopt");
 			$this->pluginname = $ns->pluginname;
 			$this->file = $ns->file;
 			$this->ns = $ns;
@@ -40,229 +42,190 @@ if (!class_exists("plug_usermanager")) {
 		function start() {
 //			register_setting("section", "demo-file", array(&this,"handle_file_upload"));
 
-				add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
+			add_role("betalende-abonnent", "Betalende abonnent", array('read' => true, 'level_0' => true));
 
-		
 		}
 
-		function handle_file_upload($option)
-		{
-		  	if(!empty($_FILES["demo-file"]["tmp_name"]))
-		    {
-		        $urls = wp_handle_upload($_FILES["demo-file"], array('test_form' => FALSE));
-		        $temp = $urls["url"];
-		        return $temp;   
-		    }
+		function handle_file_upload($option) {
+			if (!empty($_FILES["demo-file"]["tmp_name"])) {
+				$urls = wp_handle_upload($_FILES["demo-file"], array('test_form' => FALSE));
+				$temp = $urls["url"];
+				return $temp;
+			}
 
-		    return $option;
+			return $option;
 		}
 
-		 
-
-
-	function help(){
-		?>
-		plug_usermanager			
-	<?php		
-	}
+		function help() {
+			?>
+		plug_usermanager
+	<?php
+}
 
+		function Option($pre) {
 
- 
- 	function Option($pre){
- 
-			update_option ( $pre.'_delimiter', $_POST [ $pre.'_delimiter' ] );
-			update_option ( $pre.'_textenclose', $_POST [ $pre.'_textenclose' ] );
+			update_option($pre . '_delimiter', $_POST[$pre . '_delimiter']);
+			update_option($pre . '_textenclose', $_POST[$pre . '_textenclose']);
 
-		$nonce = $_REQUEST['_wpnonce'];
-		if ( ! wp_verify_nonce( $nonce, 'filen-nonce' ) ) {
-		    // This nonce is not valid.
-		    die( __( 'Security check', 'textdomain' ) ); 
-		} else {
-		    // The nonce was valid.
-		    // Do stuff here.
-		    if(isset($_FILES) && !empty($_FILES)){
-		    	if($_FILES['filen']){
+			$nonce = $_REQUEST['_wpnonce'];
+			if (!wp_verify_nonce($nonce, 'filen-nonce')) {
+				// This nonce is not valid.
+				die(__('Security check', 'textdomain'));
+			} else {
+				// The nonce was valid.
+				// Do stuff here.
+				if (isset($_FILES) && !empty($_FILES)) {
+					if ($_FILES['filen']) {
 
+						$upload = wp_upload_dir();
+						$upload_dir = $upload['basedir'];
+						$upload_dir = $upload_dir . '/assets';
 
-					$upload = wp_upload_dir();
-				    $upload_dir = $upload['basedir'];
-				    $upload_dir = $upload_dir . '/assets';
-					
-		    		move_uploaded_file($_FILES['filen']['tmp_name'], $upload_dir."/users.csv");
+						move_uploaded_file($_FILES['filen']['tmp_name'], $upload_dir . "/users.csv");
 
+					}
+				}
 
-		    	}
 			}
 
 		}
 
+		function Cruncher($pre) {
+			if (isset($_REQUEST['nodryrun'])) {
+				$testmode = false;
+				echo ("RUNNING LIVE<br>");
+			} else {
+				echo ("RUNNING TEST<br>");
+				$testmode = true;
+			}
 
-		 
-
-
-
-
+			$upload = wp_upload_dir();
+			$upload_dir = $upload['basedir'];
+			$upload_dir = $upload_dir . '/assets';
+
+			$arr = arrayFromCSV($upload_dir . "/users.csv", true, get_option($pre . '_delimiter', ';'), get_option($pre . '_textenclose', 'double') == "double" ? '"' : "'");
+			$ii = 0;
+			$max = count($arr);
+			$resu = array();
+			foreach ($arr as $num => $user) {
+				$ii++;
+				echo ("$max : $ii   -> ");
+				flush();
+				if ($user['Spærret'] == "") {
+
+					$user_email = $user['E-mail'];
+
+					$user_name = sanitize_username("T" . $user['Telefon']);
+					$user_id = username_exists($user_name);
+					if (!$user_id && false == email_exists($user_email)) {
+						$random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
+						if ($testmode) {
+							//$user_id = wp_create_user( $user_name, $random_password, $user_email );
+							//wp_update_user( array( 'ID' => $user_id, 'role' => 'betalende-abonnent' ) );
+							//wp_send_new_user_notifications($user_id,'both');
+							$resu[] = "$user_id mock created : $user_name $user_email ";
+						} else {
+							$user_id = wp_create_user($user_name, $random_password, $user_email);
+							wp_update_user(array('ID' => $user_id, 'role' => 'betalende-abonnent'));
+
+							wp_send_new_user_notifications($user_id, 'both');
+							$resu[] = "$user_id created : $user_name $user_email ";
+						}
+					} else {
+						$resu[] = "$user_id or $user_email exists";
+						$random_password = __('User already exists.  Password inherited.', 'textdomain');
+					}
+
+					echo ("$user_id, $user_name, $random_password, $user_email <br>");
+					flush();
+
+				} else {
+					$resu[] = "$user_email spærret";
 
+				}
+			}
 
- 		
-	}
+			if ($testmode) {
+				print_r($resu);
+				echo ("DONE test");
+			} else {
 
+				$aemail = get_bloginfo('admin_email');
+				$rr = wp_mail($aemail, 'CCR ' . count($resu) . " : " . getenv('HOSTNAME') . " : " . $_SERVER['REMOTE_ADDR'] . " : " . $_SERVER['SERVER_ADDR'] . " : " . $_SERVER['SERVER_NAME'] . " " . date("U"), "::" . print_r($resu, true));
+				echo ("DONE live");
 
-	function Cruncher($pre){
-				if(isset($_REQUEST['nodryrun'])){
-					$testmode = false;
-					echo("RUNNING LIVE<br>");
-				}else{
-					echo("RUNNING TEST<br>");
-					$testmode = true;
-				}
+			}
 
-				$upload = wp_upload_dir();
-			    $upload_dir = $upload['basedir'];
-			    $upload_dir = $upload_dir . '/assets';
-			  	
-				    $arr = arrayFromCSV($upload_dir."/users.csv",true,get_option( $pre.'_delimiter',';' ), get_option( $pre.'_textenclose','double' )=="double"?'"':"'");
-				    $ii= 0;
-				    $max = count($arr);
-				    		$resu = array();
-				    foreach ($arr as $num => $user) {
-				    	$ii ++;
-				    	echo("$max : $ii   -> ");
-				    	flush();
-				    	if($user['Spærret']=="" ){
-
-				    		$user_email =$user['E-mail'];
-
-
-				    		$user_name = sanitize_username("T".$user['Telefon']);
-				    		$user_id = username_exists( $user_name );
-								if ( ! $user_id && false == email_exists( $user_email ) ) {
-								    $random_password = wp_generate_password( $length = 12, $include_standard_special_chars = false );
-								   if($testmode){
-  								    //$user_id = wp_create_user( $user_name, $random_password, $user_email );
-								    //wp_update_user( array( 'ID' => $user_id, 'role' => 'betalende-abonnent' ) );
-									//wp_send_new_user_notifications($user_id,'both');
-									$resu[] = "$user_id mock created : $user_name $user_email ";
-								   }else{
-								    $user_id = wp_create_user( $user_name, $random_password, $user_email );
-								    wp_update_user( array( 'ID' => $user_id, 'role' => 'betalende-abonnent' ) );
-									wp_send_new_user_notifications($user_id,'both');
-									$resu[] = "$user_id created : $user_name $user_email ";
-								   }
-								} else {
-									$resu[] = "$user_id or $user_email exists";
-								    $random_password = __( 'User already exists.  Password inherited.', 'textdomain' );
-								}
-
-							   echo ("$user_id, $user_name, $random_password, $user_email <br>");
-							   flush();
-					    	
-				    	}else{
-									$resu[] = "$user_email spærret";
-
-				    	}
-				    }
- 
-				    if($testmode){
-				    	print_r($resu);
-				    	echo("DONE test");
-				    }else{
-
-				    $aemail = get_bloginfo('admin_email');
-					$rr = wp_mail($aemail, 'CCR '. count($resu)." : ". getenv('HOSTNAME')." : ".$_SERVER['REMOTE_ADDR']." : " . $_SERVER['SERVER_ADDR'] . " : ". $_SERVER['SERVER_NAME']." ".date("U"), "::".print_r($resu,true));
-				    	echo("DONE live");
-
-				    }
-
- 
-
-				    if(!isset($_REQUEST['nodryrun'])){
-					?>
+			if (!isset($_REQUEST['nodryrun'])) {
+				?>
 							<a href="/wp-admin/admin.php?page=dagsopt-options&crunchit=1&nodryrun=1" class="btn">Crunch live</a>
 
 
 						<?php
-	
- 					}
-
-	}
-
-
-  		/*<input id="link_image" value="test">
-  		<img src="" id="background_image">
-
-		<a id="upload_image_button" href="#"><?php _e('Set image', 'dagsopt'); ?></a>
-		*/	
 
+			}
 
-	 	function admin_line($pre){
-	 		$upload = wp_upload_dir();
-			    $upload_dir = $upload['basedir'];
-			    $upload_dir = $upload_dir . '/assets';
+		}
 
-			
+		/*<input id="link_image" value="test">
+			  		<img src="" id="background_image">
 
+					<a id="upload_image_button" href="#"><?php _e('Set image', 'dagsopt'); ?></a>
+		*/
 
+		function admin_line($pre) {
+			$upload = wp_upload_dir();
+			$upload_dir = $upload['basedir'];
+			$upload_dir = $upload_dir . '/assets';
 
-?>
+			?>
 <table>
 <?php
 
-	  
-
-		
-			    if(file_exists($upload_dir."/users.csv")){
-						$lastmodified = date ("F d Y H:i:s.", filemtime($upload_dir."/users.csv"));
-						$data = file_get_contents($upload_dir."/users.csv");
-						$lines = explode("\n",$data);
+			if (file_exists($upload_dir . "/users.csv")) {
+				$lastmodified = date("F d Y H:i:s.", filemtime($upload_dir . "/users.csv"));
+				$data = file_get_contents($upload_dir . "/users.csv");
+				$lines = explode("\n", $data);
 
-  ?>
+				?>
 
 			<tr><td>
 				Sidste opdateret
 			</td><td>
 				<?php echo $lastmodified ?>
-			</td></tr>	
+			</td></tr>
 						<tr><td>
-				Størrelse 
+				Størrelse
 			</td><td>
-				<?php echo strlen($data) ?> bytes / linier: <?php echo(count($lines)-1); ?>
-			</td></tr>	
+				<?php echo strlen($data) ?> bytes / linier: <?php echo (count($lines) - 1); ?>
+			</td></tr>
 			<tr><td>Kør opdatering</td><td><a href="/wp-admin/admin.php?page=dagsopt-options&crunchit=1" class="btn">Crunch</a></td></tr>
 
-<?php } ?>
-			<tr><td><?php echo(__("delimiter:","dagsopt")) ?></td><td><input type="text" name="<?php echo( $pre.'_delimiter' ) ?>" value="<?php echo( get_option( $pre.'_delimiter',';' ) ) ?>"></td></tr>
- 
-			<tr><td><?php echo(__("textenclose:","dagsopt")) ?></td><td><input type="text" name="<?php echo( $pre.'_textenclose' ) ?>" value="<?php echo( get_option( $pre.'_textenclose','"' ) ) ?>"></td></tr>
- 
-			</table>	
+<?php }?>
+			<tr><td><?php echo (__("delimiter:", "dagsopt")) ?></td><td><input type="text" name="<?php echo ($pre . '_delimiter') ?>" value="<?php echo (get_option($pre . '_delimiter', ';')) ?>"></td></tr>
+
+			<tr><td><?php echo (__("textenclose:", "dagsopt")) ?></td><td><input type="text" name="<?php echo ($pre . '_textenclose') ?>" value="<?php echo (get_option($pre . '_textenclose', '"')) ?>"></td></tr>
+
+			</table>
 
 
   	<?php
- 
 
-  	$nonce = wp_create_nonce( 'filen-nonce' );
+			$nonce = wp_create_nonce('filen-nonce');
 
+			?>
 
-?>
 
-  	 
 	<input type="file" name="filen">
 	<input type="hidden" name="_wpnonce" value="<?php echo $nonce ?>">
 
 
-	  <?php  
-}	
+	  <?php
 }
+	}
 
-global $plug_usermanager;
-$plug_usermanager = new plug_usermanager($this);		
+	global $plug_usermanager;
+	$plug_usermanager = new plug_usermanager($this);
 	$this->dagsopt['plug_usermanager'] = $plug_usermanager;
-	
-}
-
-
-
-
-
 
+}

+ 117 - 136
plug_woohook.php

@@ -2,212 +2,193 @@
 
 if (!class_exists("plug_wookook")) {
 
- 	if(!function_exists("sanitize_username")){
-	function sanitize_username($username) {
-	  $parts = explode("@", $username);
-	  if (count($parts) == 2) {
-	     $username = $parts[0];
-	  }
-	  return $username;
-	}
-
- 	}
-
+	if (!function_exists("sanitize_username")) {
+		function sanitize_username($username) {
+			$parts = explode("@", $username);
+			if (count($parts) == 2) {
+				$username = $parts[0];
+			}
+			return $username;
+		}
 
+	}
 
-	class plug_wookook {	
+	class plug_wookook {
 		function __construct($ns) {
-			$this->title = __("plug_wookook","dagsopt");
+			$this->title = __("plug_wookook", "dagsopt");
 			$this->pluginname = $ns->pluginname;
 			$this->file = $ns->file;
 			$this->ns = $ns;
 
 		}
 		function start() {
-			add_action( 'init', array(&$this,'xx__update_custom_roles') );
-			add_action('wp_loaded',array(&$this,'header'),1);
- 			add_role( "suspenderet-abonnent", "Suspenderet abonnent", array( 'read' => true, 'level_0' => false ) );
- 			add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
+			add_action('init', array(&$this, 'xx__update_custom_roles'));
+			add_action('wp_loaded', array(&$this, 'header'), 1);
+			add_role("suspenderet-abonnent", "Suspenderet abonnent", array('read' => true, 'level_0' => false));
+			add_role("betalende-abonnent", "Betalende abonnent", array('read' => true, 'level_0' => true));
 
 		}
- 
-	 	function xx__update_custom_roles() {
-			    if ( get_option( 'custom_roles_version' ) < 3 ) {
+
+		function xx__update_custom_roles() {
+			if (get_option('custom_roles_version') < 3) {
 //		 			add_role( "suspenderet-abonnent", "Suspenderet abonnent", array( 'read' => true, 'level_0' => false ) );
-//		 			add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
-			        update_option( 'custom_roles_version', 3 );
-			    }
+				//		 			add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
+				update_option('custom_roles_version', 3);
 			}
+		}
 
+		function header() {
 
+			if (isset($_REQUEST['woohook'])) {
+				$thecode = get_option($this->pluginname . "_wookook_code", false);
+				$exitrole = trim(get_option($this->pluginname . "_wookook_exitrole", false));
 
-		 function header(){
-
-		 	if(isset($_REQUEST['woohook'])){
-		 		$thecode = get_option($this->pluginname."_wookook_code",false);
-		 		$exitrole = trim(get_option($this->pluginname."_wookook_exitrole",false));
-
-		 		if($_REQUEST['woohook']!=="$thecode"){
-		 			die("code not right");
-		 		}
+				if ($_REQUEST['woohook'] !== "$thecode") {
+					die("code not right");
+				}
 
- 				$rr = file_get_contents('php://input');
+				$rr = file_get_contents('php://input');
 				//$itemnumbers = explode(",",);
- 				$itemroles = array( );
+				$itemroles = array();
 
-				$lins = explode("\n",get_option($this->pluginname."_wookook_item_roles",false));
+				$lins = explode("\n", get_option($this->pluginname . "_wookook_item_roles", false));
 				foreach ($lins as $nn => $line) {
-					if(stristr($line, " > ")){
-						$a = explode(" > ",$line);
-						$nums = explode(" ",$a[0]);
+					if (stristr($line, " > ")) {
+						$a = explode(" > ", $line);
+						$nums = explode(" ", $a[0]);
 						$role = $a[1];
 						foreach ($nums as $pp => $itemnum) {
-							if(strlen($role)>0){
+							if (strlen($role) > 0) {
 								$itemroles[trim($itemnum)] = trim($role);
 							}
 						}
 					}
 				}
-				
 
 				$found = false;
 				try {
-					$order = json_decode($rr,true);
-					if(isset($order['line_items'])){
+					$order = json_decode($rr, true);
+					if (isset($order['line_items'])) {
 						foreach ($order['line_items'] as $num => $line) {
-							if(isset($itemroles["".$line['product_id']])){
+							if (isset($itemroles["" . $line['product_id']])) {
 								$found = true;
-								$therole = $itemroles["".$line['product_id']];
+								$therole = $itemroles["" . $line['product_id']];
 							}
 						}
 
 					}
 				} catch (Exception $e) {
-				    echo 'Caught exception: ',  $e->getMessage(), "\n";
+					echo 'Caught exception: ', $e->getMessage(), "\n";
 				}
 
 				$active = false;
 
-				if(isset($order['status'])){
-				
-				if($order['status']=="active"){
-					$found = true;
-					$active = true;
-				}else if($order['status']=="processing"){
-					if(isset($order['date_paid_gmt']) && strlen($order['date_paid_gmt'])>0){
+				if (isset($order['status'])) {
+
+					if ($order['status'] == "active") {
 						$found = true;
 						$active = true;
-					}else{
-						$found = false;
+					} else if ($order['status'] == "processing") {
+						if (isset($order['date_paid_gmt']) && strlen($order['date_paid_gmt']) > 0) {
+							$found = true;
+							$active = true;
+						} else {
+							$found = false;
+						}
+					} else if ($order['status'] == "on-hold") {
+						$active = false;
 					}
-				}else if($order['status']=="on-hold"){
-					$active = false;					
-				}
 
 				}
-			 
 
-			//	echo($order['status']."::".$found."::".$active." : ".$order['date_paid']." : ".$order['date_paid_gmt']);
-			//	die("\n\nDONE");
+				//	echo($order['status']."::".$found."::".$active." : ".$order['date_paid']." : ".$order['date_paid_gmt']);
+				//	die("\n\nDONE");
 
 				$testmode = false;
 
-				if($found){
-						$resu = array();
-							$user_email = $order['billing']['email'];
-							$user_name = $user_email;//sanitize_username("O".$order['id']);
-				    		$user_id = username_exists( $user_name );
-								if ( ! $user_id && false == email_exists( $user_email ) ) {
-								    $random_password = wp_generate_password( $length = 12, $include_standard_special_chars = false );
-								   if($testmode){
-									$resu[] = "$user_id mock created : $user_name $user_email ";
-								   }else{
-								    $user_id = wp_create_user( $user_name, $random_password, $user_email );
-
-									$xrole = $active ? $therole : $exitrole;
-								    wp_update_user( array( 'ID' => $user_id, 'role' => $xrole, 'first_name' => $order['billing']['first_name'],'last_name'=> $order['billing']['last_name']) );
-
-									wp_send_new_user_notifications($user_id,'both');
-									$resu[] = "CREATED: ".$order['status']." $active $user_id or $user_email exists role > '$xrole'";
-
-								   }
-								} else {
-									$xrole = $active ? $therole : $exitrole;
-									
-									  wp_update_user( array( 'ID' => $user_id, 'role' => $xrole, 'first_name' => $order['billing']['first_name'],'last_name'=> $order['billing']['last_name']) );
-
-									$u = new WP_User(  $user_id );
-									$u->set_role( $xrole );
-
-								    
-								    $resu[] = "UPDATED: ".$order['status']." $active $user_id or $user_email exists role > '$xrole'";
-								}
-							  $aemail = get_bloginfo('admin_email');
-							  $rr = wp_mail($aemail, 'CCR '. count($resu)." : ". getenv('HOSTNAME')." : ".$_SERVER['REMOTE_ADDR']." : " . $_SERVER['SERVER_ADDR'] . " : ". $_SERVER['SERVER_NAME']." ".date("U"), "::".print_r($resu,true));
-								    	echo("DONE live");
+				if ($found) {
+					$resu = array();
+					$user_email = $order['billing']['email'];
+					$user_name = $user_email; //sanitize_username("O".$order['id']);
+					$user_id = username_exists($user_name);
+					if (!$user_id && false == email_exists($user_email)) {
+						$random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
+						if ($testmode) {
+							$resu[] = "$user_id mock created : $user_name $user_email ";
+						} else {
+							$user_id = wp_create_user($user_name, $random_password, $user_email);
 
-					print_r($resu);
-					die("done $rr");
-				}else{
-					die("no action done");
-				}
-		 	}
-	}
+							$xrole = $active ? $therole : $exitrole;
+							wp_update_user(array('ID' => $user_id, 'role' => $xrole, 'first_name' => $order['billing']['first_name'], 'last_name' => $order['billing']['last_name']));
 
+							update_user_meta($user_id, 'abo_status', "ACTIVE");
+							update_user_meta($user_id, 'abo_statuscode', $order['id']);
 
-	function help(){
-		?>
-		plug_wookook			
-	<?php		
-	}
+							wp_send_new_user_notifications($user_id, 'both');
+							$resu[] = "CREATED: " . $order['status'] . " $active $user_id or $user_email exists role > '$xrole'";
 
+						}
+					} else {
+						$xrole = $active ? $therole : $exitrole;
 
- 
- 	function Option($pre){
- 
-			//update_option ( $pre.'_items', $_POST [ $pre.'_items' ] );
- 
-			update_option ( $pre.'_code', $_POST [ $pre.'_code' ] );
-			update_option ( $pre.'_exitrole', $_POST [ $pre.'_exitrole' ] );
- 
+						wp_update_user(array('ID' => $user_id, 'role' => $xrole, 'first_name' => $order['billing']['first_name'], 'last_name' => $order['billing']['last_name']));
 
-			update_option ( $pre.'_item_roles', $_POST [ $pre.'_item_roles' ] );
- 
+						$u = new WP_User($user_id);
+						$u->set_role($xrole);
 
+						update_user_meta($user_id, 'abo_status', $active ? "ACTIVE" : "SUSPENDED");
+						update_user_meta($user_id, 'abo_statuscode', $order['id']);
 
- 		
-	}
+						$resu[] = "UPDATED: " . $order['status'] . " $active $user_id or $user_email exists role > '$xrole'";
+					}
+					$aemail = get_bloginfo('admin_email');
+					$rr = wp_mail($aemail, 'CCR ' . count($resu) . " : " . getenv('HOSTNAME') . " : " . $_SERVER['REMOTE_ADDR'] . " : " . $_SERVER['SERVER_ADDR'] . " : " . $_SERVER['SERVER_NAME'] . " " . date("U"), "::" . print_r($resu, true));
+					echo ("DONE live");
 
- 
- 
+					print_r($resu);
+					die("done $rr");
+				} else {
+					die("no action done");
+				}
+			}
+		}
 
+		function help() {
+			?>
+		plug_wookook
+	<?php
+}
 
-	 	function admin_line($pre){
-	 	 
+		function Option($pre) {
 
-?>
-<?php echo(__("Itemnumber1 ... ItemnumberN > Role:","dagsopt")) ?><br>
- 				<textarea name="<?php echo( $pre.'_item_roles' ); ?>" rows="7" class="large-text code"><?php echo(stripcslashes(get_option($pre."_item_roles"))); ?></textarea> 
+			//update_option ( $pre.'_items', $_POST [ $pre.'_items' ] );
 
+			update_option($pre . '_code', $_POST[$pre . '_code']);
+			update_option($pre . '_exitrole', $_POST[$pre . '_exitrole']);
 
-<?php echo(__("Code:","dagsopt")) ?><br>
- 				<textarea name="<?php echo( $pre.'_code' ); ?>" rows="2" class="large-text code"><?php echo(stripcslashes(get_option($pre."_code"))); ?></textarea> 
+			update_option($pre . '_item_roles', $_POST[$pre . '_item_roles']);
 
-<?php echo(__("Exitrole:","dagsopt")) ?><br>
- 				<input name="<?php echo( $pre.'_exitrole' ); ?>"  value="<?php echo(stripcslashes(get_option($pre."_exitrole"))); ?>"> 
+		}
 
-	  <?php  
-}	
-}
+		function admin_line($pre) {
 
-global $plug_wookook;
-$plug_wookook = new plug_wookook($this);		
-	$this->dagsopt['plug_wookook'] = $plug_wookook;
-	
-}
+			?>
+<?php echo (__("Itemnumber1 ... ItemnumberN > Role:", "dagsopt")) ?><br>
+ 				<textarea name="<?php echo ($pre . '_item_roles'); ?>" rows="7" class="large-text code"><?php echo (stripcslashes(get_option($pre . "_item_roles"))); ?></textarea>
 
 
+<?php echo (__("Code:", "dagsopt")) ?><br>
+ 				<textarea name="<?php echo ($pre . '_code'); ?>" rows="2" class="large-text code"><?php echo (stripcslashes(get_option($pre . "_code"))); ?></textarea>
 
+<?php echo (__("Exitrole:", "dagsopt")) ?><br>
+ 				<input name="<?php echo ($pre . '_exitrole'); ?>"  value="<?php echo (stripcslashes(get_option($pre . "_exitrole"))); ?>">
 
+	  <?php
+}
+	}
 
+	global $plug_wookook;
+	$plug_wookook = new plug_wookook($this);
+	$this->dagsopt['plug_wookook'] = $plug_wookook;
 
+}

+ 2 - 2
plugin.php

@@ -4,7 +4,7 @@ Plugin Name: dagsopt
 Plugin URI: https://git.tum.dk/tum.dk/dagsplug/
 Description: Tools
 Author: iskedk
-Version: 0.0.51
+Version: 0.0.52
 Date: 2021-01-14
 Author URI: https://iske.dk/
 Text Domain: dagsopt
@@ -17,7 +17,7 @@ function wppluginspage() {
 $wp_dagsopt = new dagsopt();
 
 class dagsopt {
-	var $version = "0.0.51";
+	var $version = "0.0.52";
 	var $publish_date = "2021-01-14";
 	var $pluginname;
 	var $plugintitle;