123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- 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;
- }
- }
- class plug_wookook {
- function __construct($ns) {
- $this->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
- <?php
- }
-
- function Option($pre){
-
- //update_option ( $pre.'_items', $_POST [ $pre.'_items' ] );
-
- update_option ( $pre.'_code', $_POST [ $pre.'_code' ] );
-
- update_option ( $pre.'_item_roles', $_POST [ $pre.'_item_roles' ] );
-
-
- }
-
-
- function admin_line($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>
- <?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
- }
- }
- global $plug_wookook;
- $plug_wookook = new plug_wookook($this);
- $this->dagsopt['plug_wookook'] = $plug_wookook;
-
- }
|