|
@@ -24,27 +24,46 @@ if (!class_exists("plug_wookook")) {
|
|
|
|
|
|
}
|
|
}
|
|
function start() {
|
|
function start() {
|
|
-
|
|
|
|
- //add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
|
|
|
|
-
|
|
|
|
- add_action('wp_loaded',array(&$this,'header'),1);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
|
|
|
|
+ add_action('wp_loaded',array(&$this,'header'),1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function header(){
|
|
function header(){
|
|
|
|
|
|
if(isset($_REQUEST['woohook'])){
|
|
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');
|
|
$rr = file_get_contents('php://input');
|
|
- $itemnumbers = explode(",",get_option($this->pluginname."_wookook_items",false));
|
|
|
|
|
|
+ //$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;
|
|
$found = false;
|
|
try {
|
|
try {
|
|
$order = json_decode($rr,true);
|
|
$order = json_decode($rr,true);
|
|
if(isset($order['date_paid_gmt'])){
|
|
if(isset($order['date_paid_gmt'])){
|
|
foreach ($order['line_items'] as $num => $line) {
|
|
foreach ($order['line_items'] as $num => $line) {
|
|
- if(in_array($line['product_id'],$itemnumbers)){
|
|
|
|
|
|
+ if(isset($itemroles["".$line['product_id']])){
|
|
$found = true;
|
|
$found = true;
|
|
|
|
+ $therole = $itemroles["".$line['product_id']];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -64,7 +83,7 @@ if (!class_exists("plug_wookook")) {
|
|
$resu[] = "$user_id mock created : $user_name $user_email ";
|
|
$resu[] = "$user_id mock created : $user_name $user_email ";
|
|
}else{
|
|
}else{
|
|
$user_id = wp_create_user( $user_name, $random_password, $user_email );
|
|
$user_id = wp_create_user( $user_name, $random_password, $user_email );
|
|
- wp_update_user( array( 'ID' => $user_id, 'role' => 'betalende-abonnent' ) );
|
|
|
|
|
|
+ wp_update_user( array( 'ID' => $user_id, 'role' => $therole) );
|
|
wp_send_new_user_notifications($user_id,'both');
|
|
wp_send_new_user_notifications($user_id,'both');
|
|
$resu[] = "$user_id created : $user_name $user_email ";
|
|
$resu[] = "$user_id created : $user_name $user_email ";
|
|
}
|
|
}
|
|
@@ -95,9 +114,12 @@ if (!class_exists("plug_wookook")) {
|
|
|
|
|
|
function Option($pre){
|
|
function Option($pre){
|
|
|
|
|
|
- update_option ( $pre.'_items', $_POST [ $pre.'_items' ] );
|
|
|
|
|
|
+ //update_option ( $pre.'_items', $_POST [ $pre.'_items' ] );
|
|
|
|
|
|
|
|
+ update_option ( $pre.'_code', $_POST [ $pre.'_code' ] );
|
|
|
|
|
|
|
|
+
|
|
|
|
+ update_option ( $pre.'_item_roles', $_POST [ $pre.'_item_roles' ] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -105,31 +127,19 @@ if (!class_exists("plug_wookook")) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
function admin_line($pre){
|
|
function admin_line($pre){
|
|
|
|
|
|
|
|
|
|
?>
|
|
?>
|
|
-<table>
|
|
|
|
-
|
|
|
|
|
|
+<?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>
|
|
|
|
|
|
- <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 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
|
|
<?php
|