title = __("plug_wookook","dagsopt"); $this->pluginname = $ns->pluginname; $this->file = $ns->file; $this->ns = $ns; } function start() { add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) ); add_action('wp_loaded',array(&$this,'header'),1); } function header(){ if(isset($_REQUEST['woohook'])){ $thecode = get_option($this->pluginname."_wookook_code",false); if($_REQUEST['woohook']!=="$thecode"){ die("code not right"); } $rr = file_get_contents('php://input'); //$itemnumbers = explode(",",); $itemroles = array( ); $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]); $role = $a[1]; foreach ($nums as $pp => $itemnum) { if(strlen($role)>0){ $itemroles[$itemnum] = $role; } } } } $found = false; try { $order = json_decode($rr,true); if(isset($order['date_paid_gmt'])){ foreach ($order['line_items'] as $num => $line) { if(isset($itemroles["".$line['product_id']])){ $found = true; $therole = $itemroles["".$line['product_id']]; } } } } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } $testmode = false; if($found){ $resu = array(); $user_email = $order['billing']['email']; $user_name = 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 ); wp_update_user( array( 'ID' => $user_id, 'role' => $therole) ); 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' ); } $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 Role:","dagsopt")) ?>

dagsopt['plug_wookook'] = $plug_wookook; }