function module_file_upload()
 {
     // name of module
     $module = mgm_request_var('module', '', true);
     // file
     $file_element = 'logo_' . $module;
     // init
     $logo = array();
     // init messages
     $status = 'error';
     $message = __('Logo upload failed.', 'mgm');
     // upload check
     if (is_uploaded_file($_FILES[$file_element]['tmp_name'])) {
         // random filename
         $uniquename = substr(microtime(), 2, 8);
         // paths
         $oldname = strtolower($_FILES[$file_element]['name']);
         $newname = preg_replace('/(.*)\\.(png|jpg|jpeg|gif)$/i', $uniquename . '.$2', $oldname);
         $filepath = MGM_FILES_MODULE_DIR . $newname;
         // upload
         if (move_uploaded_file($_FILES[$file_element]['tmp_name'], $filepath)) {
             // get thumb
             $thumb = image_make_intermediate_size(MGM_FILES_MODULE_DIR . $newname, 100, 100);
             // set logo
             if ($thumb) {
                 $logo = array('image_name' => $thumb['file'], 'image_url' => MGM_FILES_MODULE_URL . $thumb['file']);
                 // remove main file, we dont need it
                 mgm_delete_file($filepath);
             } else {
                 $logo = array('image_name' => $newname, 'image_url' => MGM_FILES_MODULE_URL . $newname);
             }
             // status
             $status = 'success';
             $message = __('logo uploaded successfully, it will be attached when you update the settings.', 'mgm');
         }
     }
     // send ouput
     @ob_end_clean();
     // PRINT
     echo json_encode(array('status' => $status, 'message' => $message, 'logo' => $logo));
     // end out put
     @ob_flush();
     exit;
 }
/**
 * get transaction page html
 *
 * @param bool $return
 * @return string
 * @since 1.5
 */
function mgm_get_transaction_page_html($return = false, $method = NULL)
{
    // get method
    if (!$method) {
        $method = mgm_request_var('method', '', true);
    }
    // switch $method
    switch ($method) {
        case 'payment_return':
            // after payment return with get/post values and process
        // after payment return with get/post values and process
        case 'payment_notify':
            // silent post back, IPN, just after first payment
        // silent post back, IPN, just after first payment
        case 'payment_status_notify':
            // INS, post back, at each payment cycle,i.e, 2CO INS, PayPal IPN
        // INS, post back, at each payment cycle,i.e, 2CO INS, PayPal IPN
        case 'payment_cancel':
            // cancelled
        // cancelled
        case 'payment_unsubscribe':
            // unsubscribe tracking
        // unsubscribe tracking
        case 'payment_html_redirect':
            // proxy for html redirect
        // proxy for html redirect
        case 'payment_credit_card':
            // proxy for credit_card processing
            // get module
            $module = mgm_request_var('module', '', true);
            // validate module
            if ($module_obj = mgm_is_valid_module($module, 'payment', 'object')) {
                // process, invoke process_return,process_notify,process_cancel,process_unsubscribe
                $output = $module_obj->invoke(str_replace(array('payment_'), 'process_', $method));
                // html redirect
                if ($method == 'payment_html_redirect') {
                    // set in globals
                    $GLOBALS['mgm_html_outout'] = $output;
                    // if template exists
                    if ($return) {
                        $template_file = MGM_CORE_DIR . 'html/payment_processing_return.php';
                    } else {
                        if (file_exists(TEMPLATEPATH . '/payment_processing.php')) {
                            $template_file = TEMPLATEPATH . '/payment_processing.php';
                        } else {
                            $template_file = MGM_CORE_DIR . 'html/payment_processing.php';
                        }
                    }
                    // apply template filter
                    $template_file = apply_filters('mgm_page_template', $template_file, $method);
                    // return template
                    if ($return) {
                        return mgm_get_include($template_file);
                    }
                    // @todo check payment
                    // include template
                    @(include $template_file);
                }
            } else {
                // not a valiud module, call default for unsubscribe
                if ($method == 'payment_unsubscribe') {
                    // default unsubscribe
                    return mgm_member_unsubscribe();
                } else {
                    // error
                    return __('Invalid module supplied', 'mgm');
                }
            }
            break;
        case 'payment_processed':
            // processed
            // get module
            $module = mgm_request_var('module', '', true);
            // validate module
            if ($module_obj = mgm_is_valid_module($module, 'payment', 'object')) {
                // redirect logic moved, in all cases same page is loaded
                // if template exists
                if ($return) {
                    $template_file = MGM_CORE_DIR . 'html/payment_processed_return.php';
                } else {
                    if (file_exists(TEMPLATEPATH . '/payment_processed.php')) {
                        $template_file = TEMPLATEPATH . '/payment_processed.php';
                    } else {
                        $template_file = MGM_CORE_DIR . 'html/payment_processed.php';
                    }
                }
                // apply template filter
                $template_file = apply_filters('mgm_page_template', $template_file, $method);
                // return template
                if ($return) {
                    return mgm_get_include($template_file);
                }
                // include template
                @(include $template_file);
            } else {
                return __('Invalid module supplied', 'mgm');
            }
            break;
        case 'payment_purchase':
            // post purchase
            // if template exists
            if ($return) {
                $template_file = MGM_CORE_DIR . 'html/payment_post_purchase_return.php';
            } else {
                if (file_exists(TEMPLATEPATH . '/payment_post_purchase.php')) {
                    $template_file = TEMPLATEPATH . '/payment_post_purchase.php';
                } else {
                    $template_file = MGM_CORE_DIR . 'html/payment_post_purchase.php';
                }
            }
            // apply template filter
            $template_file = apply_filters('mgm_page_template', $template_file, $method);
            // return template
            if ($return) {
                return mgm_get_include($template_file);
            }
            // include template
            @(include $template_file);
            break;
        case 'guest_purchase':
            // form
            // if template exists
            if ($return) {
                $template_file = MGM_CORE_DIR . 'html/guest_purchase_return.php';
            } else {
                if (file_exists(TEMPLATEPATH . '/guest_purchase.php')) {
                    $template_file = TEMPLATEPATH . '/guest_purchase.php';
                } else {
                    $template_file = MGM_CORE_DIR . 'html/guest_purchase.php';
                }
            }
            // apply template filter
            $template_file = apply_filters('mgm_page_template', $template_file, $method);
            // return template
            if ($return) {
                return mgm_get_include($template_file);
            }
            // include template
            @(include $template_file);
            break;
        case 'register':
            // if template exists
            $template = mgm_get_page_template($method, $return);
            // return template
            if ($return) {
                return mgm_get_include($template);
            }
            // include template
            @(include $template);
            break;
        case 'profile':
            //user profile page
            // if template exists
            $template = mgm_get_page_template($method, $return);
            // return template
            if ($return) {
                return mgm_get_include($template);
            }
            // include template
            @(include $template);
            break;
        case 'lost_password':
            // if template exists
            $template = mgm_get_page_template($method, $return);
            // return template
            if ($return) {
                return mgm_get_include($template);
            }
            // include template
            @(include $template);
            break;
        case 'user_login':
        case 'login':
            // if template exists
            $template = mgm_get_page_template('login', $return);
            // return template
            if ($return) {
                return mgm_get_include($template);
            }
            // include template
            @(include $template);
            break;
        case 'payment_subscribe':
            // form
        // form
        case 'payment':
            // form
        // form
        default:
            // if template exists
            if ($return) {
                $template_file = MGM_CORE_DIR . 'html/payment_subscribe_return.php';
            } elseif (file_exists(TEMPLATEPATH . '/payment_subscribe.php')) {
                $template_file = TEMPLATEPATH . '/payment_subscribe.php';
            } else {
                $template_file = MGM_CORE_DIR . 'html/payment_subscribe.php';
            }
            // apply template filter
            $template_file = apply_filters('mgm_page_template', $template_file, $method);
            // return template
            if ($return) {
                return mgm_get_include($template_file);
            }
            // include template
            @(include $template_file);
            break;
    }
}
function mgm_parse_query()
{
    global $wpdb;
    // pre process hook for parse query
    do_action('mgm_parse_query_pre_process');
    //check file uploads:
    if ($file_upload = mgm_request_var('file_upload', '', true)) {
        // option
        switch ($file_upload) {
            case 'image':
                mgm_photo_file_upload();
                break;
        }
        // no process further
        exit;
    }
    // payment process --------------------
    // default
    $process_payments = false;
    // check
    foreach (mgm_get_payment_page_query_vars() as $query_var) {
        // set if
        if ($isset_query_var = mgm_get_query_var($query_var)) {
            // process
            $process_payments = true;
            break;
        }
    }
    // If buddy press registration page is used. issue #1085
    if (!$process_payments) {
        $process_payments = mgm_is_bp_registration();
    }
    // check
    if ($process_payments) {
        // payment html
        mgm_get_transaction_page_html(false);
        // exit
        exit;
    }
    // download flag // wp-ecommerce also uses download as slug, check
    if (!($download_slug = mgm_get_class('system')->get_setting('download_slug'))) {
        $download_slug = 'download';
    }
    // download call
    if ($isset_download_slug = mgm_get_query_var($download_slug)) {
        // get method
        $code = mgm_request_var('code', '', true);
        // check
        mgm_download_file($code);
        // exit
        exit;
    }
}
function mgm_replace_payment_message_tags($content)
{
    // system
    $system_obj = mgm_get_class('system');
    // current module
    $module = mgm_request_var('module', '', true);
    // object
    $module_object = NULL;
    // check
    if ($module) {
        // module object
        $module_object = mgm_get_module($module, 'payment');
    }
    // double check
    if (is_object($module_object)) {
        // status and message
        if (!isset($_GET['status']) || $_GET['status'] == 'success') {
            $payment_status_title = $module_object->setting['success_title'] ? $module_object->setting['success_title'] : $system_obj->get_template('payment_success_title', array(), true);
            $payment_status_message = $module_object->setting['success_message'] ? $module_object->setting['success_message'] : $system_obj->get_template('payment_success_message', array(), true);
        } else {
            if (!isset($_GET['status']) || $_GET['status'] == 'cancel') {
                $payment_status_title = __('Transaction cancelled', 'mgm');
                $payment_status_message = __('You have cancelled the transaction.', 'mgm');
            } else {
                $payment_status_title = $module_object->setting['failed_title'] ? $module_object->setting['failed_title'] : $system_obj->get_template('payment_failed_title', array(), true);
                $payment_status_message = $module_object->setting['failed_message'] ? $module_object->setting['failed_message'] : $system_obj->get_template('payment_failed_message', array(), true);
            }
        }
        // set errors
        if (isset($_GET['errors'])) {
            $errors = explode('|', strip_tags($_GET['errors']));
            $payment_status_message .= '<p><h3>' . __('Messages', 'mgm') . '</h3>';
            $payment_status_message .= '<div><ul>';
            foreach ($errors as $error) {
                $payment_status_message .= '<li>' . $error . '</li>';
            }
            $payment_status_message .= '</ul>
			</div></p>';
        }
        // redirect_to post
        if (isset($_GET['post_redirect'])) {
            $payment_status_message .= __('<b>You will be redirected to the Post Purchased, please click <a href="' . strip_tags($_GET['post_redirect']) . '"> here </a> if you are not redirected.</b>', 'mgm');
            $payment_status_message .= "<script language=\"Javascript\">var t = setTimeout ( \"window.location='" . strip_tags($_GET['post_redirect']) . "'\", 5000 ); </script>";
        }
        // loop tags
        foreach (array('payment_status_title', 'payment_status_message') as $tag) {
            // set
            $content = str_replace('[[' . $tag . ']]', mgm_stripslashes_deep(${$tag}), $content);
        }
    } else {
        // loop tags and clean tags
        foreach (array('payment_status_title', 'payment_status_message') as $tag) {
            // set
            $content = str_replace('[[' . $tag . ']]', '', $content);
        }
    }
    // return
    return $content;
}
/**
 * after login redirect
 * 
 * @param string user login
 * @param object user
 * @return object user
 */
function mgm_login_redirect($user_login, $user = NULL)
{
    // get user
    if (!$user) {
        $user = get_user_by('login', $user_login);
    }
    // if super admin
    if (is_super_admin($user->ID)) {
        // redirect
        mgm_redirect(admin_url());
        exit;
    }
    // check doing auto login from register and skip if true
    if (defined('MGM_DOING_REGISTER_AUTO_LOGIN') && MGM_DOING_REGISTER_AUTO_LOGIN == TRUE) {
        // return
        return $user;
    }
    // custom hook
    do_action('mgm_before_login_redirect', $user);
    // get setting
    $system_obj = mgm_get_class('system');
    // issue #503,allow redirecting back to post url: @depends on  "enable_post_url_redirection" in misc setting
    $enable_post_url_redirection = bool_from_yn($system_obj->get_setting('enable_post_url_redirection'));
    // check
    if ($enable_post_url_redirection) {
        // redirect_to
        if ($redirect_to = mgm_request_var('redirect_to', '', true)) {
            // flag
            $do_redirect = true;
            // loop custom pages
            foreach ($system_obj->get_custom_pages_url() as $page_url) {
                // if not same
                if (!empty($page_url) && trailingslashit($redirect_to) == trailingslashit($page_url)) {
                    // check, matched both full url or part /%postname%/ url
                    if (trailingslashit($redirect_to) == trailingslashit($page_url) || site_url($redirect_to) == trailingslashit($page_url)) {
                        // reset
                        $do_redirect = false;
                        break;
                    }
                }
            }
            // OK
            if (!empty($redirect_to) && $do_redirect) {
                mgm_redirect($redirect_to);
            }
            exit;
        }
    }
    // apply filter
    $login_redirect_url = apply_filters('mgm_login_redirect', mgm_login_redirect_url($user));
    // check
    if (!empty($login_redirect_url)) {
        mgm_redirect($login_redirect_url);
        exit;
    }
    // return
    return $user;
}
/**
 * get errors
 */
function mgm_subscription_purchase_errors()
{
    // error
    $error_field = mgm_request_var('error_field', '', true);
    //issue #1250
    $error_field_value = mgm_request_var('error_field_value', '', true);
    // check
    if (!empty($error_field)) {
        // obj
        $errors = new WP_Error();
        // type
        switch (mgm_request_var('error_type', '', true)) {
            case 'empty':
                $error_string = 'You must provide a ';
                //issue #1250
                if ($error_field == 'Coupon') {
                    $errors->add($error_field, __('<strong>ERROR</strong>: ' . $error_string, 'mgm') . $error_field);
                }
                break;
            case 'invalid':
                $error_string = 'Invalid ';
                //issue #1250
                if ($error_field == 'Coupon' && !mgm_request_var('membership_type', '', true)) {
                    $errors->add($error_field, sprintf(__('<strong>ERROR</strong>: Coupon Code "%s" is not valid, use a valid coupon only.', 'mgm'), $error_field_value));
                }
                if ($error_field == 'Coupon' && ($membership_type = mgm_request_var('membership_type', '', true))) {
                    $errors->add($error_field, sprintf(__('<strong>ERROR</strong>: Coupon Code "%s" is only available with Membership Type "%s".', 'mgm'), $error_field_value, $membership_type));
                }
                break;
        }
        // add - issue #1250
        if ($error_field != 'Coupon') {
            //issue #703
            $errors->add($error_field, __('<strong>ERROR</strong>: ' . $error_string, 'mgm') . $error_field);
        }
        // return
        return mgm_set_errors($errors, true);
    }
    // nothing
    return '';
}
/**
 * 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);
}