123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?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'])){
- $rr = file_get_contents('php://input');
- $itemnumbers = explode(",",get_option($this->pluginname."_wookook_items",false));
- $found = false;
- try {
- $order = json_decode($rr,true);
- if(isset($order['date_paid_gmt'])){
- foreach ($order['line_items'] as $num => $line) {
- if(in_array($line['product_id'],$itemnumbers)){
- $found = true;
- }
- }
- }
- } 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' => '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' );
- }
- $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' ] );
-
-
-
-
- }
-
-
- function admin_line($pre){
-
- ?>
- <table>
-
- <tr><td>
- </td><td>
- </td></tr>
- <tr><td>
-
- </td><td>
- </td></tr>
-
- <tr><td> <?php echo(__("Item numbers:","dagsopt")) ?><br><textarea name="<?php echo( $pre.'_items' ); ?>"><?php echo(stripcslashes(get_option($pre."_items"))); ?></textarea> <br></td></tr>
-
-
- </table>
-
- <?php
- }
- }
- global $plug_wookook;
- $plug_wookook = new plug_wookook($this);
- $this->dagsopt['plug_wookook'] = $plug_wookook;
-
- }
|