Beispiel #1
17
/**
 * Get theme update information from the PMPro server.
 *
 * @since  2.0
 */
function memberlite_getUpdateInfo()
{
    //check if forcing a pull from the server
    $update_info = get_option("memberlite_update_info", false);
    $update_info_timestamp = get_option("memberlite_update_info_timestamp", 0);
    //if no update_infos locally, we need to hit the server
    if (empty($update_info) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $update_info_timestamp + 86400) {
        /**
         * Filter to change the timeout for this wp_remote_get() request.
         *
         * @since 2.0.1
         *
         * @param int $timeout The number of seconds before the request times out
         */
        $timeout = apply_filters("memberlite_get_update_info_timeout", 5);
        //get em
        $remote_info = wp_remote_get(PMPRO_LICENSE_SERVER . "/themes/memberlite", $timeout);
        //test response
        if (is_wp_error($remote_info) || empty($remote_info['response']) || $remote_info['response']['code'] != '200') {
            //error
            pmpro_setMessage("Could not connect to the PMPro License Server to get update information. Try again later.", "error");
        } else {
            //update update_infos in cache
            $update_info = json_decode(wp_remote_retrieve_body($remote_info), true);
            delete_option('memberlite_update_info');
            add_option("memberlite_update_info", $update_info, NULL, 'no');
        }
        //save timestamp of last update
        delete_option('memberlite_update_info_timestamp');
        add_option("memberlite_update_info_timestamp", current_time('timestamp'), NULL, 'no');
    }
    return $update_info;
}
Beispiel #2
0
/**
 * Get addon information from PMPro server.
 *
 * @since  1.8.5
 */
function pmpro_getAddons()
{
    //check if forcing a pull from the server
    $addons = get_option("pmpro_addons", array());
    $addons_timestamp = get_option("pmpro_addons_timestamp", 0);
    //if no addons locally, we need to hit the server
    if (empty($addons) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $addons_timestamp + 86400) {
        //get em
        $remote_addons = wp_remote_get(PMPRO_LICENSE_SERVER . "/addons/");
        if (get_class($remote_addons) === "WP_Error") {
            return array();
        }
        //test response
        if (empty($remote_addons['response']) || $remote_addons['response']['code'] != '200') {
            //error
            pmpro_setMessage("Could not connect to the PMPro License Server to update addon information. Try again later.", "error");
            //make sure we have at least an array to pass back
            if (empty($addons)) {
                $addons = array();
            }
        } else {
            //update addons in cache
            $addons = json_decode(wp_remote_retrieve_body($remote_addons), true);
            delete_option('pmpro_addons');
            add_option("pmpro_addons", $addons, NULL, 'no');
        }
        //save timestamp of last update
        delete_option('pmpro_addons_timestamp');
        add_option("pmpro_addons_timestamp", current_time('timestamp'), NULL, 'no');
    }
    return $addons;
}
function mailpoet_pmpro_registration_checks($okay)
{
    //only check if we're okay so far
    if (!empty($_REQUEST['pmpro_user_subscribe_to_mailpoet'])) {
        global $pmpro_msg, $pmpro_msgt, $pmpro_error_fields;
        $required_fields = array('bemail');
        //Check for username field while registration
        if (!is_user_logged_in()) {
            $required_fields[] = 'username';
        }
        foreach ($required_fields as $field) {
            if (empty($_REQUEST[$field])) {
                $okay = false;
                pmpro_setMessage(__('Please complete all required fields.', 'mailpoet_paid_memberships_pro_addon'), "pmpro_error");
                $pmpro_error_fields[] = $field;
            }
        }
    }
    return $okay;
}
/**
 * Get addon information from PMPro server.
 *
 * @since  1.8.5
 */
function pmpro_getAddons()
{
    //check if forcing a pull from the server
    $addons = get_option("pmpro_addons", array());
    $addons_timestamp = get_option("pmpro_addons_timestamp", 0);
    //if no addons locally, we need to hit the server
    if (empty($addons) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $addons_timestamp + 86400) {
        /**
         * Filter to change the timeout for this wp_remote_get() request.
         *
         * @since 1.8.5.1
         *
         * @param int $timeout The number of seconds before the request times out
         */
        $timeout = apply_filters("pmpro_get_addons_timeout", 5);
        //get em
        $remote_addons = wp_remote_get(PMPRO_LICENSE_SERVER . "/addons/", $timeout);
        //make sure we have at least an array to pass back
        if (empty($addons)) {
            $addons = array();
        }
        //test response
        if (is_wp_error($remote_addons)) {
            //error
            pmpro_setMessage("Could not connect to the PMPro License Server to update addon information. Try again later.", "error");
        } elseif (!empty($remote_addons) && $remote_addons['response']['code'] == 200) {
            //update addons in cache
            $addons = json_decode(wp_remote_retrieve_body($remote_addons), true);
            delete_option('pmpro_addons');
            add_option("pmpro_addons", $addons, NULL, 'no');
        }
        //save timestamp of last update
        delete_option('pmpro_addons_timestamp');
        add_option("pmpro_addons_timestamp", current_time('timestamp'), NULL, 'no');
    }
    return $addons;
}
function pmprorh_rf_pmpro_registration_checks($okay)
{
    global $current_user;
    //arrays to store fields that were required and missed
    $required = array();
    $required_labels = array();
    //any fields?
    global $pmprorh_registration_fields;
    if (!empty($pmprorh_registration_fields)) {
        //cycle through groups
        foreach ($pmprorh_registration_fields as $where => $fields) {
            //cycle through fields
            foreach ($fields as $field) {
                //handle arrays
                $field->name = preg_replace('/\\[\\]$/', '', $field->name);
                //if the field is not for this level, skip it
                if (!pmprorh_checkFieldForLevel($field)) {
                    continue;
                }
                if (isset($_REQUEST[$field->name])) {
                    $value = $_REQUEST[$field->name];
                } elseif (isset($_FILES[$field->name])) {
                    $value = $_FILES[$field->name]['name'];
                    //handle empty file but the user already has a file
                    if (empty($value) && !empty($_REQUEST[$field->name . "_old"])) {
                        $value = $_REQUEST[$field->name . "_old"];
                    } elseif (!empty($value)) {
                        //check extension against allowed extensions
                        $filetype = wp_check_filetype_and_ext($_FILES[$field->name]['tmp_name'], $_FILES[$field->name]['name']);
                        if ((!$filetype['type'] || !$filetype['ext']) && !current_user_can('unfiltered_upload')) {
                            if ($okay) {
                                //only want to update message if there is no previous error
                                pmpro_setMessage(sprintf(__("Sorry, the file type for %s is not permitted for security reasons.", "pmpro"), $_FILES[$field->name]['name']), "pmpro_error");
                            }
                            return false;
                        } else {
                            //check for specific extensions anyway
                            if (!empty($field->ext) && !in_array($filetype['ext'], $field->ext)) {
                                if ($okay) {
                                    //only want to update message if there is no previous error
                                    pmpro_setMessage(sprintf(__("Sorry, the file type for %s is not permitted for security reasons.", "pmpro"), $_FILES[$field->name]['name']), "pmpro_error");
                                }
                                return false;
                            }
                        }
                    }
                } else {
                    $value = false;
                }
                if (!empty($field->required) && empty($value)) {
                    $required[] = $field->name;
                    $required_labels[] = $field->label;
                }
            }
        }
    }
    if (!empty($required)) {
        $required = array_unique($required);
        //add them to error fields
        global $pmpro_error_fields;
        $pmpro_error_fields = array_merge((array) $pmpro_error_fields, $required);
        if (count($required) == 1) {
            $pmpro_msg = "The " . implode(", ", $required_labels) . " field is required.";
        } else {
            $pmpro_msg = "The " . implode(", ", $required_labels) . " fields are required.";
        }
        $pmpro_msgt = "pmpro_error";
        if ($okay) {
            pmpro_setMessage($pmpro_msg, $pmpro_msgt);
        }
        return false;
    }
    //return whatever status was before
    return $okay;
}
function pmprosm_pmpro_registration_checks_sponsored_accounts($okay)
{
    global $pmpro_msg, $pmpro_msgt;
    //only if we're adding accounts at checkout
    $pmprosm_values = pmprosm_getValuesByMainLevel($_REQUEST['level']);
    if (empty($pmprosm_values['sponsored_accounts_at_checkout'])) {
        return $okay;
    }
    //get number of old accounts to test later
    if (!empty($_REQUEST['old_sub_accounts_active'])) {
        $num_old_accounts = count($_REQUEST['old_sub_accounts_active']);
    } else {
        $num_old_accounts = 0;
    }
    //get seats
    if (!empty($_REQUEST['seats'])) {
        $seats = intval($_REQUEST['seats']);
    } else {
        $seats = 0;
    }
    //how many new accounts?
    $num_new_accounts = $seats - $num_old_accounts;
    //get account values
    if (!empty($_REQUEST['add_sub_accounts_username'])) {
        $child_usernames = $_REQUEST['add_sub_accounts_username'];
    } else {
        $child_usernames = array();
    }
    if (!empty($_REQUEST['add_sub_accounts_first_name'])) {
        $child_first_names = $_REQUEST['add_sub_accounts_first_name'];
    } else {
        $child_first_names = array();
    }
    if (!empty($_REQUEST['add_sub_accounts_last_name'])) {
        $child_last_names = $_REQUEST['add_sub_accounts_last_name'];
    } else {
        $child_last_names = array();
    }
    if (!empty($_REQUEST['add_sub_accounts_email'])) {
        $child_emails = $_REQUEST['add_sub_accounts_email'];
    } else {
        $child_emails = array();
    }
    if (!empty($_REQUEST['add_sub_accounts_password'])) {
        $child_passwords = $_REQUEST['add_sub_accounts_password'];
    } else {
        $child_passwords = array();
    }
    //check that these emails and usernames are unique
    $unique_usernames = array_unique(array_filter($child_usernames));
    $unique_emails = array_unique(array_filter($child_emails));
    $passwords = array_filter($child_passwords);
    if ($num_new_accounts > 0 && (count($unique_usernames) < $num_new_accounts || count($unique_emails) < $num_new_accounts || count($passwords) < $num_new_accounts)) {
        pmpro_setMessage(__("Please enter details for each new sponsored account."), "pmpro_error");
        $okay = false;
    } elseif (count($unique_usernames) != count($child_usernames) || count($unique_emails) != count($child_emails)) {
        pmpro_setMessage(__("Each sponsored account must have a unique username and email address."), "pmpro_error");
        $okay = false;
    } elseif (count($child_emails) + $num_old_accounts > $seats) {
        pmpro_setMessage(__("You have more accounts checked than you are purchasing seats. Increase the number of seats or deactivate some accounts."), "pmpro_error");
        $okay = false;
    } else {
        foreach ($child_usernames as $child_username) {
            //if registering child username or email already exisits the create an error.
            if (username_exists($child_username)) {
                $pmpro_msg = "The username <b>" . $child_username . "</b> already exists. Please select a different username";
                $pmpro_msgt = "pmpro_error";
                pmpro_setMessage($pmpro_msg, "pmpro_error");
                $okay = false;
            }
        }
        foreach ($child_emails as $child_email) {
            if (email_exists($child_email)) {
                $pmpro_msg = "That email <b>" . $child_email . "</b> already exists. Please select a different email";
                $pmpro_msgt = "pmpro_error";
                pmpro_setMessage($pmpro_msg, "pmpro_error");
                $okay = false;
            } elseif (!is_email($child_email)) {
                $pmpro_msg = "<b>" . $child_email . "</b> is not a valid email address. Please select a different email";
                $pmpro_msgt = "pmpro_error";
                pmpro_setMessage($pmpro_msg, "pmpro_error");
                $okay = false;
            }
        }
    }
    return $okay;
}
Beispiel #7
0
 function saveFile($user_id, $name, $value)
 {
     //setup some vars
     $file = $_FILES[$name];
     $user = get_userdata($user_id);
     //no file?
     if (empty($file['name'])) {
         return;
     }
     //check extension against allowed extensions
     $filetype = wp_check_filetype_and_ext($file['tmp_name'], $file['name']);
     if ((!$filetype['type'] || !$filetype['ext']) && !current_user_can('unfiltered_upload')) {
         //we throw an error earlier, but this just bails on the upload just in case
         return false;
     } else {
         //need to check this in case we are in class context or not
         if (!empty($this)) {
             if (!empty($this->ext)) {
                 $ext = $this->ext;
             } else {
                 $ext = false;
             }
         } else {
             global $pmprorh_registration_fields;
             foreach ($pmprorh_registration_fields as $checkout_box) {
                 foreach ($checkout_box as $field) {
                     if ($field->name == $name) {
                         if (!empty($field->ext)) {
                             $ext = $field->ext;
                         } else {
                             $ext = false;
                         }
                         break 2;
                     }
                 }
             }
         }
         //check for specific extensions anyway
         if (!empty($ext) && !in_array($filetype['ext'], $ext)) {
             pmpro_setMessage(sprintf(__("Sorry, the file type for %s is not permitted for security reasons.", "pmpro"), $file['name']), "pmpro_error");
             return false;
         }
     }
     /*
     	save file in uploads
     */
     //check for a register helper directory in wp-content
     $upload_dir = wp_upload_dir();
     $pmprorh_dir = $upload_dir['basedir'] . "/pmpro-register-helper/" . $user->user_login . "/";
     //create the dir and subdir if needed
     if (!is_dir($pmprorh_dir)) {
         wp_mkdir_p($pmprorh_dir);
     }
     //if we already have a file for this field, delete it
     $old_file = get_user_meta($user->ID, $name, true);
     if (!empty($old_file) && !empty($old_file['fullpath']) && file_exists($old_file['fullpath'])) {
         unlink($old_file['fullpath']);
     }
     //figure out new filename
     $filename = $file['name'];
     $count = 0;
     while (file_exists($pmprorh_dir . $filename)) {
         if ($count) {
             $filename = str_lreplace("-" . $count . "." . $filetype['ext'], "-" . strval($count + 1) . "." . $filetype['ext'], $filename);
         } else {
             $filename = str_lreplace("." . $filetype['ext'], "-1." . $filetype['ext'], $filename);
         }
         $count++;
         //let's not expect more than 50 files with the same name
         if ($count > 50) {
             die("Error uploading file. Too many files with the same name.");
         }
     }
     //save file
     if (strpos($file['tmp_name'], $upload_dir['basedir']) !== false) {
         //was uploaded and saved to $_SESSION
         rename($file['tmp_name'], $pmprorh_dir . $filename);
     } else {
         //it was just uploaded
         move_uploaded_file($file['tmp_name'], $pmprorh_dir . $filename);
     }
     //save filename in usermeta
     update_user_meta($user_id, $name, array("original_filename" => $file['name'], "filename" => $filename, "fullpath" => $pmprorh_dir . $filename, "fullurl" => content_url("/uploads/pmpro-register-helper/" . $user->user_login . "/" . $filename), "size" => $file['size']));
 }
 }
 $pmpro_continue_registration = apply_filters("pmpro_registration_checks", $pmpro_continue_registration);
 if ($pmpro_continue_registration) {
     //if creating a new user, check that the email and username are available
     if (empty($current_user->ID)) {
         $oldusername = $wpdb->get_var("SELECT user_login FROM {$wpdb->users} WHERE user_login = '******' LIMIT 1");
         $oldemail = $wpdb->get_var("SELECT user_email FROM {$wpdb->users} WHERE user_email = '" . esc_sql($bemail) . "' LIMIT 1");
         //this hook can be used to allow multiple accounts with the same email address
         $oldemail = apply_filters("pmpro_checkout_oldemail", $oldemail);
     }
     if (!empty($oldusername)) {
         pmpro_setMessage(__("That username is already taken. Please try another.", "pmpro"), "pmpro_error");
         $pmpro_error_fields[] = "username";
     }
     if (!empty($oldemail)) {
         pmpro_setMessage(__("That email address is already taken. Please try another.", "pmpro"), "pmpro_error");
         $pmpro_error_fields[] = "bemail";
         $pmpro_error_fields[] = "bconfirmemail";
     }
     //only continue if there are no other errors yet
     if ($pmpro_msgt != "pmpro_error") {
         //check recaptcha first
         global $recaptcha;
         if (!$skip_account_fields && ($recaptcha == 2 || $recaptcha == 1 && pmpro_isLevelFree($pmpro_level))) {
             global $recaptcha_privatekey;
             if (isset($_POST["recaptcha_challenge_field"])) {
                 //using older recaptcha lib
                 $resp = recaptcha_check_answer($recaptcha_privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
                 $recaptcha_valid = $resp->is_valid;
                 $recaptcha_errors = $resp->error;
             } else {
function pmpro_license_check_key($key = NULL)
{
    //get key
    if (empty($key)) {
        $key = get_option('pmpro_license_key');
    }
    //key? check with server
    if (!empty($key)) {
        //check license server
        $url = add_query_arg(array('license' => $key, 'domain' => site_url()), PMPRO_LICENSE_SERVER);
        /**
         * Filter to change the timeout for this wp_remote_get() request.
         *
         * @since 1.8.5.1
         *
         * @param int $timeout The number of seconds before the request times out
         */
        $timeout = apply_filters("pmpro_license_check_key_timeout", 5);
        $r = wp_remote_get($url, array("timeout" => $timeout));
        //test response
        if (is_wp_error($r)) {
            //error
            pmpro_setMessage("Could not connect to the PMPro License Server to check key Try again later.", "error");
        } elseif (!empty($r) && $r['response']['code'] == 200) {
            $r = json_decode($r['body']);
            if ($r->active == 1) {
                //valid key save enddate
                if (!empty($r->enddate)) {
                    $enddate = strtotime($r->enddate, current_time('timestamp'));
                } else {
                    $enddate = strtotime("+1 Year", current_time("timestamp"));
                }
                delete_option('pmpro_license_check');
                add_option('pmpro_license_check', array('license' => $r->license, 'enddate' => $enddate), NULL, 'no');
                return true;
            } elseif (!empty($r->error)) {
                //invalid key
                global $pmpro_license_error;
                $pmpro_license_error = $r->error;
                delete_option('pmpro_license_check');
                add_option('pmpro_license_check', array('license' => false, 'enddate' => 0), NULL, 'no');
            }
        }
    }
    //no key or there was an error
    return false;
}
         pmpro_setMessage(__("That email address is already taken. Please try another.", "pmpro"), "pmpro_error");
         $pmpro_error_fields[] = "bemail";
         $pmpro_error_fields[] = "bconfirmemail";
     }
     //okay so far?
     if ($pmpro_msgt != "pmpro_error") {
         //random password if needed
         if (empty($user_pass)) {
             $user_pass = wp_generate_password();
         }
         //add user
         $user_id = wp_insert_user(array("user_login" => $user_login, "user_pass" => $user_pass, "user_email" => $user_email, "first_name" => $first_name, "last_name" => $last_name));
     }
 }
 if (!$user_id) {
     pmpro_setMessage("Error creating user.", "pmpro_error");
 } else {
     //other user meta
     update_user_meta($user_id, "user_notes", $user_notes);
     //figure out start date
     $now = current_time('timestamp');
     $startdate = date("Y-m-d", $now);
     //figure out end date
     if (!empty($_REQUEST['expires'])) {
         //update the expiration date
         $enddate = intval($_REQUEST['expires_year']) . "-" . str_pad(intval($_REQUEST['expires_month']), 2, "0", STR_PAD_LEFT) . "-" . str_pad(intval($_REQUEST['expires_day']), 2, "0", STR_PAD_LEFT);
     } else {
         $enddate = '';
     }
     //add membership level
     $custom_level = array('user_id' => $user_id, 'membership_id' => $membership_level, 'code_id' => '', 'initial_payment' => $total, 'billing_amount' => '', 'cycle_number' => '', 'cycle_period' => '', 'billing_limit' => '', 'trial_amount' => '', 'trial_limit' => '', 'startdate' => $startdate, 'enddate' => $enddate);
function pmproio_pmpro_registration_checks($okay)
{
    global $pmpro_level, $pmproio_invite_required_levels;
    if (pmproio_isInviteLevel($pmpro_level->id)) {
        global $pmpro_msg, $pmpro_msgt, $pmpro_error_fields, $wpdb;
        //get invite code
        $invite_code = $_REQUEST['invite_code'];
        $real = pmproio_checkInviteCode($invite_code);
        if (empty($invite_code) || empty($real)) {
            pmpro_setMessage(__("An invite code is required for this level. Please enter a valid invite code.", "pmpro"), "pmpro_error");
            $pmpro_error_fields[] = "invite_code";
        }
    }
    return $okay;
}
function my_pmpro_registration_checks_require_code_to_register($pmpro_continue_registration)
{
    //only bother if things are okay so far
    if (!$pmpro_continue_registration) {
        return $pmpro_continue_registration;
    }
    //level = 1 and there is no discount code, then show an error message
    global $pmpro_level, $discount_code;
    //if($pmpro_level->id == 1 && (empty($discount_code) || $discount_code != "REQUIRED_CODE")) //use this conditional to check for a specific code.
    if ($pmpro_level->id == 12 && empty($discount_code)) {
        pmpro_setMessage("You must use a valid discount code to register for this level.", "pmpro_error");
        return false;
    }
    return $pmpro_continue_registration;
}