/**
 * register post, validate required custom fields
 *
 * @param string $sanitized_user_login 
 * @param string $user_email
 * @param object $errors
 * @param boolean $show_fields
 * @return object $errors
 */
function mgm_register_post($sanitized_user_login = '', $user_email = '', $errors = null, $show_fields = null)
{
    // get mgm_system
    $system_obj = mgm_get_class('system');
    // hide
    $hide_custom_fields = $system_obj->get_setting('hide_custom_fields');
    // error
    if (is_null($errors)) {
        $errors = new WP_Error();
    }
    // unset old errors
    unset($errors->errors);
    // errors
    $error_codes = $errors->get_error_codes();
    // user_login
    if (array_key_exists('user_login', $_POST)) {
        $sanitized_user_login = sanitize_user($_POST['user_login']);
        if ($sanitized_user_login == '') {
            if (!in_array('empty_username', $error_codes)) {
                $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.', 'mgm'));
            }
        } elseif (!validate_username($sanitized_user_login)) {
            if (!in_array('invalid_username', $error_codes)) {
                $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.', 'mgm'));
            }
            $sanitized_user_login = '';
        } elseif (!mgm_validate_username($sanitized_user_login)) {
            if (!in_array('invalid_username', $error_codes)) {
                $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters, spaces are not allowed. Please enter a valid username.', 'mgm'));
            }
            $sanitized_user_login = '';
        } elseif (username_exists($sanitized_user_login)) {
            if (!in_array('username_exists', $error_codes)) {
                $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.', 'mgm'));
            }
        }
    }
    // user_email
    if (array_key_exists('user_email', $_POST)) {
        $user_email = apply_filters('user_registration_email', $_POST['user_email']);
        // Check the e-mail address
        if ($user_email == '') {
            if (!in_array('empty_email', $error_codes)) {
                $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.', 'mgm'));
            }
        } elseif (!is_email($user_email)) {
            if (!in_array('invalid_email', $error_codes)) {
                $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.', 'mgm'));
            }
            $user_email = '';
        } elseif (email_exists($user_email)) {
            if (!in_array('email_exists', $error_codes)) {
                $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.', 'mgm'));
            }
        }
    }
    // check email only #1106
    if (in_array('email_exists', $errors->get_error_codes())) {
        $label = 'email';
        $url = mgm_get_complete_registration_url('email', $user_email);
        // check
        if ($url !== FALSE) {
            // unset old errors
            unset($errors->errors);
            // set
            $errors->add('unfinished_registration', sprintf(__('<strong>ERROR</strong>: This %s has an unfinished registration. Click here to <a href="%s">complete</a>.', 'mgm'), $label, $url));
            // return form here
            return $errors;
        }
    }
    // get custom fields
    $cf_register_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true)));
    //#739 modified starts
    if (empty($show_fields)) {
        $cf_alias_fields = mgm_get_class('member_custom_fields')->get_fields_where(array('attributes' => array('capture_only' => true)));
        if (!empty($cf_alias_fields)) {
            foreach ($cf_alias_fields as $key => $array) {
                unset($cf_register_page[$key]);
            }
        }
    }
    // #739 modified ends
    // #740 starts
    $args_fields = "";
    // Show fields in short code to filter the registration form #Issue 740
    if (isset($show_fields)) {
        $package = isset($args['package']) ? $args['package'] : NULL;
        $args_fields = $show_fields;
        if (!empty($args_fields)) {
            $cf_register_page = mgm_show_fields_result($args_fields, $cf_register_page, $package);
        }
    }
    // #740 ends
    $check = 0;
    if (isset($_POST['mgm_widget_active'])) {
        if (isset($_POST['mgm_custom_fields']) && $_POST['mgm_custom_fields'] == 1) {
            $check = $_POST['mgm_custom_fields'];
        }
    } else {
        $check = 1;
    }
    // wordpress register
    $wordpres_form = mgm_check_wordpress_login();
    // check
    if ($check) {
        // loop
        foreach ($cf_register_page as $field) {
            // skip custom fields by settings call
            if ($hide_custom_fields == 'Y' || $hide_custom_fields == 'W' && $wordpres_form || $hide_custom_fields == 'C' && !$wordpres_form) {
                // some are required
                if (!in_array($field['name'], array('subscription_options', 'payment_gateways'))) {
                    continue;
                }
            }
            // skip default fields, validated already
            if (in_array($field['name'], array('username', 'email'))) {
                continue;
            }
            // by name
            switch ($field['name']) {
                case 'terms_conditions':
                    // terms & conditions
                    if (!isset($_POST['mgm_tos']) || empty($_POST['mgm_tos'])) {
                        $errors->add('mgm_tos', __('<strong>ERROR</strong>: You must accept the Terms and Conditions.', 'mgm'));
                    }
                    break;
                case 'subscription_options':
                    // subscription options
                    if (!isset($_POST['mgm_subscription']) || empty($_POST['mgm_subscription'])) {
                        $errors->add('mgm_subscription', __('<strong>ERROR</strong>: You must select a Subscription Type.', 'mgm'));
                    }
                    break;
                case 'payment_gateways':
                    // payment gateways
                    if (isset($_POST['mgm_subscription'])) {
                        // pack
                        $sub_pack = mgm_decode_package($_POST['mgm_subscription']);
                        // check
                        if (isset($sub_pack['pack_id'])) {
                            $pack = mgm_get_class('subscription_packs')->get_pack($sub_pack['pack_id']);
                            $pack_modules = array_diff($pack['modules'], array('mgm_free', 'mgm_trial'));
                            // take paid module
                            // validate
                            if (!empty($pack_modules) && (!isset($_POST['mgm_payment_gateways']) || isset($_POST['mgm_payment_gateways']) && empty($_POST['mgm_payment_gateways']))) {
                                $errors->add('mgm_subscription', __('<strong>ERROR</strong>: You must select a Payment Gateway.', 'mgm'));
                            }
                        }
                    }
                    break;
                case 'coupon':
                    if (isset($_POST['mgm_register_field']['coupon']) && !empty($_POST['mgm_register_field']['coupon'])) {
                        // coupon
                        if ($coupon_code = trim($_POST['mgm_register_field']['coupon'])) {
                            // check if its a valid coupon
                            if (!($coupon = mgm_get_coupon_data($coupon_code))) {
                                $errors->add('mgm_coupon', sprintf(__('<strong>ERROR</strong>: Coupon Code "%s" is not valid, use a valid coupon only.', 'mgm'), $coupon_code));
                            } else {
                                // get subs
                                if ($subs_pack = mgm_decode_package(mgm_post_var('mgm_subscription'))) {
                                    // values
                                    $coupon_values = mgm_get_coupon_values(NULL, $coupon['value'], true);
                                    // check
                                    if (isset($coupon_values['new_membership_type']) && $coupon_values['new_membership_type'] != $subs_pack['membership_type']) {
                                        $new_membership_type = mgm_get_membership_type_name($coupon_values['new_membership_type']);
                                        $errors->add('mgm_coupon', sprintf(__('<strong>ERROR</strong>: Coupon Code "%s" is only available with Membership Type "%s".', 'mgm'), $coupon_code, $new_membership_type));
                                    }
                                }
                            }
                        }
                    } elseif ((bool) $field['attributes']['required'] === true) {
                        $errors->add('mgm_coupon', sprintf(__('<strong>ERROR</strong>: Please enter a valid coupon code.', 'mgm')));
                    }
                    break;
                case 'birthdate':
                    // validate age
                    if (isset($_POST['mgm_register_field'][$field['name']]) && !empty($_POST['mgm_register_field'][$field['name']])) {
                        // format
                        $short_format = mgm_get_date_format('date_format_short');
                        // date
                        $birthdate = mgm_format_inputdate_to_mysql($_POST['mgm_register_field'][$field['name']], $short_format);
                        // current date
                        $current_date = mgm_get_current_datetime('Y-m-d H:i:s');
                        // add
                        if (strtotime($birthdate) > $current_date['timestamp']) {
                            $errors->add($field['name'], __('<strong>ERROR</strong>: Birthdate should not be in future.', 'mgm'));
                        } else {
                            if (isset($field['attributes']['verify_age'])) {
                                // age
                                $unit = (int) $field['attributes']['verify_age_unit'];
                                $period = $field['attributes']['verify_age_period'];
                                // check
                                if ($field['attributes']['verify_age'] == 1 && (int) $field['attributes']['verify_age_unit'] > 0) {
                                    // verify_age_period
                                    $birthdate_should = strtotime(sprintf('-%d %s', $unit, $period), $current_date['timestamp']);
                                    if (strtotime($birthdate) > $birthdate_should) {
                                        $errors->add($field['name'], sprintf(__('<strong>ERROR</strong>: Birthdate should be on or before %s.', 'mgm'), date($short_format, $birthdate_should)));
                                    }
                                }
                            }
                        }
                    }
                    // left other process run
                // left other process run
                default:
                    // on type
                    switch ($field['type']) {
                        case 'captcha':
                            // captcha
                            if (!isset($_POST['recaptcha_response_field']) || empty($_POST['recaptcha_response_field'])) {
                                $errors->add('mgm_captcha', __('<strong>ERROR</strong>: You must enter the Captcha String.', 'mgm'));
                            } else {
                                $captcha = mgm_get_class('recaptcha')->recaptcha_check_answer($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
                                if (!isset($captcha->is_valid) || !$captcha->is_valid) {
                                    $errors->add('mgm_captcha', __('<strong>ERROR</strong>: ' . (!empty($captcha->error) ? $captcha->error : 'The Captcha String isn\'t correct.'), 'mgm'));
                                }
                            }
                            break;
                        default:
                            // check register and required
                            if ((bool) $field['attributes']['required'] === true) {
                                // error
                                $error_codes = $errors->get_error_codes();
                                // validate other
                                // confirm password
                                if ($field['name'] == 'password' || $field['name'] == 'password_conf') {
                                    if ($field['name'] == 'password' && (!isset($_POST['user_password']) || empty($_POST['user_password'])) || $field['name'] == 'password_conf' && (!isset($_POST['user_password_conf']) || empty($_POST['user_password_conf']))) {
                                        // issue #703
                                        $errors->add($field['name'], __('<strong>ERROR</strong>: You must provide a ', 'mgm') . mgm_stripslashes_deep($field['label']) . '.');
                                    } elseif ($field['name'] == 'password' && !empty($_POST['user_password']) && !empty($_POST['user_password_conf']) && (isset($field['attributes']['password_min_length']) && $field['attributes']['password_min_length'] == true || isset($field['attributes']['password_min_length']) && $field['attributes']['password_max_length'] == true)) {
                                        if (strlen($_POST['user_password']) < $field['attributes']['password_min_length_field_alias'] || strlen($_POST['user_password_conf']) < $field['attributes']['password_min_length_field_alias']) {
                                            $errors->add($field['name'], sprintf(__('<strong>ERROR</strong>:%s is too short, minimum %d characters.', 'mgm'), mgm_stripslashes_deep($field['label']), $field['attributes']['password_min_length_field_alias']));
                                        } elseif (strlen($_POST['user_password']) > $field['attributes']['password_max_length_field_alias'] || strlen($_POST['user_password_conf']) > $field['attributes']['password_max_length_field_alias']) {
                                            $errors->add($field['name'], sprintf(__('<strong>ERROR</strong>:%s is too long, maximum %d characters.', 'mgm'), mgm_stripslashes_deep($field['label']), $field['attributes']['password_max_length_field_alias']));
                                        } elseif ($field['name'] == 'password' && !empty($_POST['user_password']) && !empty($_POST['user_password_conf']) && $_POST['user_password'] != $_POST['user_password_conf']) {
                                            $errors->add($field['name'], __('<strong>ERROR</strong>: Password does not match. Please re-type.', 'mgm'));
                                        }
                                    } elseif ($field['name'] == 'password' && !empty($_POST['user_password']) && !empty($_POST['user_password_conf']) && $_POST['user_password'] != $_POST['user_password_conf']) {
                                        $errors->add($field['name'], __('<strong>ERROR</strong>: Password does not match. Please re-type.', 'mgm'));
                                    }
                                } else {
                                    //issue #1315
                                    if ($field['name'] == 'user_email' || $field['name'] == 'email_conf') {
                                        if ($field['name'] == 'email_conf' && (!isset($_POST['user_email_conf']) || empty($_POST['user_email_conf']))) {
                                            $errors->add($field['name'], __('<strong>ERROR</strong>: Please type your confirm e-mail address.', 'mgm'));
                                        } elseif (!is_email($_POST['user_email_conf'])) {
                                            $errors->add('invalid_email_conf', __('<strong>ERROR</strong>: The confirm email address isn&#8217;t correct.', 'mgm'));
                                        } elseif (email_exists($_POST['user_email_conf'])) {
                                            $errors->add('email_conf_exists', __('<strong>ERROR</strong>: This confirm email is already registered, please choose another one.', 'mgm'));
                                        } elseif (is_email($_POST['user_email']) && $_POST['user_email_conf'] != $_POST['user_email']) {
                                            $errors->add($field['name'], __('<strong>ERROR</strong>: E-mail does not match. Please re-type.', 'mgm'));
                                        }
                                    } elseif (!isset($_POST['mgm_register_field'][$field['name']]) || empty($_POST['mgm_register_field'][$field['name']])) {
                                        //issue #703
                                        $errors->add($field['name'], __('<strong>ERROR</strong>: You must provide a ', 'mgm') . mgm_stripslashes_deep($field['label']) . '.');
                                    }
                                }
                            }
                            break;
                    }
                    break;
            }
        }
    }
    // return
    return $errors;
}
/**
 * custom register form
 *
 * @param array $args
 * @param bool $use_default_links
 * @return string $form
 */
function mgm_user_register_form($args = array(), $use_default_links = false)
{
    // hide from logged in user
    if (is_user_logged_in()) {
        // redirect
        return __('You are already logged in!', 'mgm');
    }
    // registration disabled
    if (!get_option('users_can_register')) {
        // redirect
        return __('User registration is currently not allowed.', 'mgm');
    }
    // get system
    $system_obj = mgm_get_class('system');
    // hide flag
    $hide_custom_fields = $system_obj->get_setting('hide_custom_fields');
    // init
    $cf_show_fields = array();
    // default_register_fields
    $register_fields = mgm_get_config('default_register_fields', array());
    // get active custom fields on register
    $cf_register_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true)));
    //issue #1573
    $membership_args_fields = "";
    if (isset($args['membership']) && !empty($args['membership'])) {
        //init
        $show_fields_arr = array();
        // membership
        $membership = $args['membership'];
        // get active custom fields on register
        $cf_register_by_membership_types = mgm_get_class('member_custom_fields')->get_fields_where(array('attributes' => array('register_by_membership_types' => true)));
        //check
        if (!empty($cf_register_by_membership_types)) {
            //loop
            foreach ($cf_register_by_membership_types as $cf_register_by_membership_type) {
                //membership_type
                $membership_types_string = isset($cf_register_by_membership_type['attributes']['register_membership_types_field_alias']) ? $cf_register_by_membership_type['attributes']['register_membership_types_field_alias'] : null;
                //check
                if (preg_match('/\\b' . $membership . '\\b/', $membership_types_string) && $membership_types_string != null) {
                    $show_fields_arr[] = $cf_register_by_membership_type['name'];
                }
            }
        }
        //filter if any empty values found check
        $show_fields_arr = array_filter($show_fields_arr);
        //check
        if (!empty($show_fields_arr)) {
            $membership_args_fields = implode(',', $show_fields_arr);
        }
    }
    // # 740
    // Show fields in short code to filter the registration form #Issue 740
    $args_fields = '';
    if (isset($args['show_fields']) && !empty($args['show_fields']) || isset($membership_args_fields) && !empty($membership_args_fields)) {
        $package = isset($args['package']) ? $args['package'] : null;
        $args_fields = isset($args['show_fields']) ? $args['show_fields'] : $membership_args_fields;
        if (!empty($args_fields)) {
            $cf_register_page = mgm_show_fields_result($args_fields, $cf_register_page, $package);
        }
    }
    // error_html
    $error_html = '';
    // save-------------------------------------------------
    if (isset($_POST['method']) && $_POST['method'] == 'create_user') {
        // check security before processing form
        if (!wp_verify_nonce(mgm_post_var('_mgmnonce_user_register'), 'user_register')) {
            mgm_security_error('user_register');
        }
        // load wp lib for register
        if (mgm_compare_wp_version('3.1', '<')) {
            // only before 3.1
            require_once ABSPATH . WPINC . '/registration.php';
        }
        // process hooked registers i.e. facebook connect
        do_action('mgm_user_register_pre_process');
        // init
        $user_login = $user_email = '';
        // loop to check
        foreach ($register_fields as $cfield => $wfield) {
            // set custom
            if (isset($_POST['mgm_register_field'][$cfield])) {
                // set from custom
                ${$wfield['name']} = $_POST['mgm_register_field'][$cfield];
            } else {
                if (isset($_POST[$wfield['name']])) {
                    // default field
                    ${$wfield['name']} = $_POST[$wfield['name']];
                } else {
                    // else
                    ${$wfield['name']} = '';
                }
            }
        }
        // user login
        if (empty($user_login)) {
            $user_login = mgm_generate_user_login($user_email);
        }
        //issue #1573
        if (!isset($args['show_fields']) && isset($args['membership'])) {
            $args['show_fields'] = $_REQUEST['show_fields'];
        }
        // get error
        $errors = mgm_register_new_user($user_login, $user_email, isset($args['show_fields']) ? $args['show_fields'] : NULL);
        // no error
        if (!is_wp_error($errors)) {
            // get redirect
            $redirect = mgm_get_custom_url('login', $use_default_links, array('checkemail' => 'registered'));
            // check default
            $redirect_to = !empty($_POST['redirect_to']) ? $_POST['redirect_to'] : $redirect;
            // redirect
            wp_safe_redirect($redirect_to);
            // exit
            exit;
        }
        // errors
        $error_html = mgm_set_errors($errors, true);
    }
    // end save-----------------------------------------------
    // issue#: 532
    $form_action = isset($args['package']) || isset($args['membership']) ? get_permalink() : mgm_get_custom_url('register');
    // package code:
    if ($package = mgm_request_var('package', '', true)) {
        $form_action = add_query_arg(array('package' => $package), $form_action);
    }
    // membership code:
    if ($membership = mgm_request_var('membership', '', true)) {
        $form_action = add_query_arg(array('membership' => $membership), $form_action);
    }
    // wordpress register
    $wordpres_form = mgm_check_wordpress_login();
    // 	get row row template
    $form_row_template = $system_obj->get_template('register_form_row_template');
    // get template row filter, mgm_register_form_row_template for custom, mgm_register_form_row_template_wordpress for wordpress
    $form_row_template = apply_filters('mgm_register_form_row_template' . ($wordpres_form ? '_wordpress' : ''), $form_row_template);
    // form_fields_config
    $form_fields_config = array('wordpres_form' => (bool) $wordpres_form, 'form_row_template' => $form_row_template, 'cf_register_page' => $cf_register_page, 'args' => $args);
    // get mgm_form_fields generator
    $form_fields = new mgm_form_fields($form_fields_config);
    // default
    $form_html = '';
    // register & purchase, purchase options
    if (isset($_GET['show_purchase_options']) && isset($_GET['post_id'])) {
        // set
        $form_html .= apply_filters('mgm_guest_purchase_register_form_pre_register_html', mgm_get_post_purchase_options((int) strip_tags($_GET['post_id']), 'pre_register'));
    }
    // register & purchase, add post id
    if (isset($_GET['post_id']) && (int) $_GET['post_id'] > 0) {
        // set
        $form_html .= sprintf('<input type="hidden" name="post_id" value="%d">', (int) strip_tags($_GET['post_id']));
    }
    //register & purchase postpack
    if (isset($_GET['postpack_id']) && (int) $_GET['postpack_id'] > 0 && isset($_GET['postpack_post_id']) && (int) $_GET['postpack_post_id'] > 0) {
        // set
        // $form_html .= mgm_get_postpack_template($_GET['postpack_id'],false,$_GET['postpack_post_id'],'pre_register');
        $form_html .= sprintf('<input type="hidden" name="postpack_id" value="%d">', (int) strip_tags($_GET['postpack_id']));
        $form_html .= sprintf('<input type="hidden" name="postpack_post_id" value="%d">', (int) strip_tags($_GET['postpack_post_id']));
    }
    // mgm_pr($register_fields);
    // loop default register fields, create each if they are not defined in custom fields
    foreach ($register_fields as $cfield => $wfield) {
        // set not found
        $captured = false;
        // first check if in custom fields
        foreach ($cf_register_page as $rfield) {
            // if default register field  == custom register field, skip
            if ($rfield['name'] == $cfield) {
                // skip custom fields by settings call
                if ($hide_custom_fields == 'Y' || $hide_custom_fields == 'W' && $wordpres_form || $hide_custom_fields == 'C' && !$wordpres_form) {
                    // if($hide_custom_fields && $cfield['name'] != 'subscription_options') continue;
                    if (!in_array($field['name'], array('subscription_options', 'payment_gateways'))) {
                        continue;
                    }
                }
                // set found
                $captured = true;
                // do nothing
                break;
            }
            // skip username if setting enabled @todo
            if ($cfield == 'username' && bool_from_yn($system_obj->get_setting('enable_email_as_username'))) {
                // set found
                $captured = true;
                break;
            }
        }
        // not found
        if (!$captured) {
            // create element
            $form_html .= str_replace(array('[user_field_wrapper]', '[user_field_label]', '[user_field_element]'), array($wfield['name'], mgm_stripslashes_deep($wfield['label']), $form_fields->get_field_element($wfield, 'mgm_register_field')), $form_row_template);
        }
    }
    // register custom fields, this will be called via register_form hook
    // $form_html .= mgm_wp_register_form_additional($form_fields, $args, true);
    // register button text
    $register_button_text = apply_filters('mgm_register_button_text', $system_obj->get_setting('register_text', __('Register', 'mgm')));
    // buttons
    $buttons = array(sprintf('<input class="button mgm-register-button" type="submit" name="wp-submit" id="wp-submit" value="%s" tabindex="100" />', $register_button_text));
    // apply filters
    $buttons_s = implode(apply_filters('mgm_register_form_buttons_sep', ' &nbsp; '), apply_filters('mgm_register_form_buttons', $buttons));
    // append
    $buttons_html = sprintf('<div class="register-page-buttons">%s</div>', $buttons_s);
    // nonce
    $nonce = wp_nonce_field('user_register', '_mgmnonce_user_register', true, false);
    // this will not work in page shortcde as this does not return form html but directly outputs it
    // do_action('register_form');
    // set to globals to be used by "register_form" action hook
    $GLOBALS['form_fields'] = $form_fields;
    // attach custom fields via default hook
    $form_html .= apply_filters('mgm_register_form', $form_html);
    // output form
    $html = '<div class="mgm_register_form">
				' . $error_html . '
				<form class="mgm_form" name="registerform" id="registerform"  action="' . $form_action . '" method="post">	               
				   ' . $form_html . $buttons_html . $nonce . '					
					<input type="hidden" name="method" value="create_user">	
					<input type="hidden" name="show_fields" value="' . $args_fields . '">					
				</form>
			 </div>';
    // after links
    $links = array();
    // login link
    $links[] = sprintf('<a class="mgm-login-link" href="%s" title="%s">%s</a>', mgm_get_custom_url('login', $use_default_links), __('Log in', 'mgm'), __('Log in', 'mgm'));
    // lostpassword link
    if (get_option('users_can_register')) {
        $links[] = sprintf('<a class="mgm-lostpassword-link" href="%s" title="%s">%s</a>', mgm_get_custom_url('lostpassword', $use_default_links), __('Password Lost and Found', 'mgm'), __('Lost your password', 'mgm'));
    }
    // apply filters
    $links_s = implode(apply_filters('mgm_register_form_after_links_sep', ' | '), apply_filters('mgm_register_form_after_links', $links));
    // append
    $html .= sprintf('<div class="register-page-links">%s</div>', $links_s);
    // attach scripts,
    $html .= mgm_attach_scripts(true);
    // scripts & styles --------------------
    $script = "";
    //issue #1125
    $script .= "jQuery(document).ready(function() {\r\r\n\t\t\t\t\tvar c ='coupon';\r\r\n\t\t\t\t\tif(jQuery('.coupon_box input').attr('name') == 'mgm_register_field') {\t\r\r\n\t \t\t\t\t\tjQuery('.coupon_box input').attr('name', 'mgm_register_field['+c+']');\r\r\n\t\t\t\t\t}\r\r\n\t\t\t\t});";
    // script
    $script = sprintf('<script type="text/javascript">%s</script>', apply_filters('mgm_register_form_inline_script', $script));
    // scripts
    $html .= apply_filters('mgm_register_form_scripts', $script);
    // style
    $style = '.register-page-links, .register-page-buttons{margin-top:10px; clear:both}';
    // style
    $style = sprintf('<style type="text/css">%s</style>', apply_filters('mgm_register_form_inline_style', $style));
    // style
    $html .= apply_filters('mgm_register_form_styles', $style);
    // apply filter and return
    return apply_filters('mgm_register_form_html', $html);
}