function expire_check()
 {
     global $ym_sys;
     if (!isset($this->ID)) {
         return;
     }
     $ID = $this->ID;
     // check for parent
     if ($this->parent_id != FALSE) {
         // has a parent account
         $parent_user = new YourMember_User($this->parent_id);
         $not_expired = $parent_user->expire_check();
         if ($not_expired) {
             // check special case expires
             if ($this->status == YM_STATUS_PARENT_CANCEL) {
                 return FALSE;
             }
             // check user is is in parents child account list ie is orphaned
             if (!in_array($ID, $parent_user->child_ids)) {
                 // orphaned transistion to a normal account
                 // which is pending a sub payment
                 $this->status = YM_STATUS_EXPIRED;
                 //explict active set to clear child account status
                 $this->parent_id = false;
                 $this->save();
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, __('Child Account Orphaned: Expired', 'ym'), $ID);
                 return FALSE;
             }
             // if the account type is blank
             // and parent only allows a single package type
             // set the child to that package type
             if (!$this->account_type) {
                 $allowed_types = count($parent_user->child_accounts_package_types);
                 $allowed_packs = count($parent_user->child_accounts_packages);
                 $error = FALSE;
                 if ($allowed_types >= 1 && $allowed_packs >= 1) {
                     // well f**k
                     $error = TRUE;
                 } else {
                     if ($allowed_types == 1) {
                         $this->account_type = $parent_user->child_accounts_package_types[0];
                         @ym_log_transaction(YM_ACCOUNT_TYPE_ASSIGNATION, $this->account_type, $ID);
                     } else {
                         if ($allowed_packs == 1) {
                             ym_group_apply_package($parent_user->child_accounts_packages[0]);
                             // go drop for status check.....
                         } else {
                             // if drop thru well deny. Account not configured
                             $error = TRUE;
                         }
                     }
                 }
                 if ($error) {
                     $this->status = YM_STATUS_PARENT_CONFIG;
                     $this->save();
                     return FALSE;
                 }
             }
             if ($this->status != $parent_user->status) {
                 $this->status = $parent_user->status;
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, $this->status, $ID);
             }
             // if expose expire date to child
             // update expiry
             $this->save();
             return TRUE;
         }
         // check for status update at this point the child account should be expired
         // but the parent account can be of any status (such as pending)
         if ($this->account_type != YM_STATUS_PARENT_EXPIRED) {
             $this->status = YM_STATUS_PARENT_EXPIRED;
             @ym_log_transaction(YM_USER_STATUS_UPDATE, $this->status, $ID);
             $this->save();
         }
         return FALSE;
     }
     if (ym_superuser($ID)) {
         return TRUE;
     }
     $current_status = $this->status;
     if ($current_status === false) {
         return TRUE;
     }
     if ($current_status == YM_STATUS_EXPIRED || $current_status == YM_STATUS_TRIAL_EXPIRED) {
         return FALSE;
     }
     $grace_limit_user = $ym_sys->grace_limit;
     $grace_limit_user = apply_filters('ym_user_grace_limit_adjust', $grace_limit_user, $this);
     $new = FALSE;
     $reg_date = get_userdata($ID);
     $reg_date = strtotime($reg_date->user_registered);
     if ($reg_date > time() - 86400 * $grace_limit_user) {
         $new = TRUE;
     }
     if ($current_status == YM_STATUS_ACTIVE || $current_status == YM_STATUS_GRACE) {
         // time
         $expire = $this->expire_date;
         if ($expire > time()) {
             // expire is in the future
             // safe/not expired
             return TRUE;
         }
         // expired
         if ($this->ym_expiry_sub_dropdown_check()) {
             return;
         }
         if ($this->trial_on) {
             $user_status = YM_STATUS_TRIAL_EXPIRED;
         } else {
             $user_status = YM_STATUS_EXPIRED;
         }
         @ym_log_transaction(YM_ACCESS_EXPIRY, time(), $ID);
         @ym_log_transaction(YM_USER_STATUS_UPDATE, $user_status, $ID);
         $data = array('status' => $user_status, 'status_str' => __('User has expired', 'ym'));
         $data = apply_filters('ym_user_expire_check_into_expire', $data, $this);
         $this->update($data);
         $this->save();
         do_action('ym_user_is_expired', $ID, $data);
         return FALSE;
     } else {
         if ($current_status == YM_STATUS_PENDING && $ym_sys->grace_enable && !$new) {
             // grace is only applied to pending users
             // eligable
             $last_pay_date = $this->last_pay_date;
             $limit = time() - 86400 * $grace_limit_user;
             if ($last_pay_date > $limit) {
                 // lets put them into grace
                 $data = array('status' => YM_STATUS_GRACE, 'status_str' => __('User is entering Grace', 'ym'), 'expire_date' => time() + 86400 * $grace_limit_user);
                 @ym_log_transaction(YM_ACCESS_EXPIRY, $data['expire_date'], $ID);
                 @ym_log_transaction(YM_USER_STATUS_UPDATE, $data['status'], $ID);
                 $data = apply_filters('ym_user_expire_check_into_grace', $data, $this);
                 $this->update($data);
                 $this->save();
                 do_action('ym_user_is_in_grace', $ID, $data);
                 // recheck
                 return $this->expire_check();
             } else {
                 // not eligable
                 return FALSE;
             }
         }
     }
     return FALSE;
 }
function ym_child_package_pack_apply()
{
    global $current_user;
    get_currentuserinfo();
    $parent_id = $current_user->ID;
    $child_id = $_POST['child_id'];
    $user = new YourMember_User($child_id);
    // check parent can access child
    if (!ym_superuser($parent_id)) {
        // && $user->parent_id != $parent_id) {
        echo '0';
        die;
    }
    if ($_POST['package_id'] == '-') {
        echo '0';
        die;
    }
    ym_group_apply_package($_POST['package_id'], $child_id);
    echo '1';
    die;
}