2012-02-03 2 views
0

사용자 지정 양식이 있습니다. 등록한 후에 특정 페이지로 사용자를 리디렉션하려하지만 시도한 방법이 작동하지 않습니다. 여기에 코드가 있습니다. 사용자가 등록한 후 리디렉션을 받으려면 어떻게합니까?Wordpress - 사용자 지정 양식, 리디렉션 후

EDIT : 귀하의 pluggin는 일반적으로 사용하는 거라고 예상 액션 후크 형식을 존중하지 않는

<?php 
/* Load registration file. */ 
require_once(ABSPATH . WPINC . '/registration.php'); 

/* If user registered, input info. */ 
if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'adduser') { 
    $user_pass = wp_generate_password(); 
    $userdata = array(
     'user_pass' => esc_attr($_POST['user_pass']), 
     'user_login' => esc_attr($_POST['user_name']), 
     'user_email' => esc_attr($_POST['email']), 
    ); 

    if (!$userdata['user_login']) 
     $error = __('A username is required for registration.', 'frontendprofile'); 
    elseif (username_exists($userdata['user_login'])) 
     $error = __('Sorry, that username already exists!', 'frontendprofile'); 
    elseif (!is_email($userdata['user_email'], true)) 
     $error = __('You must enter a valid email address.', 'frontendprofile'); 
    elseif (email_exists($userdata['user_email'])) 
     $error = __('Sorry, that email address is already used!', 'frontendprofile'); 

    else{ 
     $new_user = wp_insert_user($userdata); 
     update_usermeta($new_user, 'fullname', esc_attr($_POST['fullname'] )); 
     update_usermeta($new_user, 'publication', esc_attr($_POST['publication'] )); 
     update_usermeta($new_user, 'usertype', esc_attr($_POST['usertype'] )); 
     wp_new_user_notification($new_user, $user_pass); 
     wp_redirect('http://www.google.com'); 
    } 
} 

?> 

<form method="post" id="adduser" class="user-forms" action="http://<?php echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>"> 
    <p class="form-usertype"> 
    <strong>TYPE</strong> 
    <?php $usertype = get_the_author_meta('usertype', $current_user->ID); ?> 
    <ul> 
    <li> 
     <input class="radio" value="Media" name="usertype" <?php if ($_POST['usertype'] == 'Media') { ?>checked="checked"<?php }?> type="radio" /> 
     <span><?php _e('Media', 'frontendprofile'); ?></span> 
    </li> 
    <li> 
     <input class="radio" value="Freelance" name="usertype" <?php if ($_POST['usertype'] == 'Freelance' ) { ?>checked="checked"<?php }?> type="radio" /> 
     <span><?php _e('Freelance', 'frontendprofile'); ?></span> 
    </li> 
    <li> 
     <input class="radio" value="Student" name="usertype" <?php if ($_POST['usertype'] == 'Student') { ?>checked="checked"<?php }?> type="radio" /> 
     <span><?php _e('Student', 'frontendprofile'); ?></span> 
    </li> 
    </ul> 
    </p> 
    <!-- .form-usertype --> 

    <p class="form-username"> 
    <strong>FULL NAME</strong> 
    <input class="text-input" name="user_name" type="text" id="user_name" value="<?php if ($error) echo wp_specialchars($_POST['user_name'], 1); ?>" /> 
    </p> 
    <!-- .form-username --> 

    <p class="form-email"> 
    <strong>E-MAIL</strong> 
    <input class="text-input" name="email" type="text" id="email" value="<?php if ($error) echo wp_specialchars($_POST['email'], 1); ?>" /> 
    </p> 
    <!-- .form-email --> 

    <p class="form-password"> 
    <strong>CONFIRM E-MAIL</strong> 
    <input type="text" name="user_pass" id="user_pass" class="input" value="" size="20" tabindex="10" /> 
    </p> 

    <p class="form-publication"> 
    <strong>MEDIA OUTLET</strong> 
    <input class="text-input" name="publication" type="text" id="publication" value="<?php if ($error) echo wp_specialchars($_POST['publication'], 1); ?>"/> 
    </p> 
    <!-- .form-publication --> 

    <p class="form-submit"> <?php echo $referer; ?> 
    <input name="adduser" type="submit" id="addusersub" class="submit button" value="<?php if (current_user_can('create_users')) _e('Add User', 'frontendprofile'); else _e('Register', 'frontendprofile'); ?>" /> 
    <?php wp_nonce_field('add-user') ?> 
    <input name="action" type="hidden" id="action" value="adduser" /> 
    </p> 
    <!-- .form-submit --> 

</form> 

<script type="text/javascript"> 
$(document).ready(function(){ 

    $("input[name$='usertype']").click(function(){ 

    var radio_value = $(this).val(); 

    if(radio_value=='Media') { 
    $("p.form-publication").show(); 
    } 
    else if(radio_value=='Student') { 
    $("p.form-publication").hide(); 
    } 
    else if(radio_value=='Freelance') { 
    $("p.form-publication").hide(); 
    } 
    }); 
}); 
</script> 
+0

... 나는 pluggin로했을 거라고하지만 잘 작동해야합니까 작동 안됨? Google로 리디렉션하면 리디렉션되지 않습니까? – Iznogood

+0

예, 리디렉션이 작동하지 않습니다. –

답변

1

(이것에 대한 jQuery를 또는 자바 스크립트 solutuion도 허용 될 수). 여기서해야 할 일은 플러그인을위한 두 가지 다른 기능을 연결하는 것입니다.

예를 들어 단축 코드를 사용하여 필요한 경우 플러그인을 그립니다.

다른 사람은 실제로 사용자 추가와 같이해야 할 일을하기 위해 wordpress의 초기 처리에 연결됩니다. 그런 다음 wp_redirect를 사용하면 모든 출력이 브라우저로 보내지기 전에 리디렉션 할 수 있습니다.

예를 들어, 내 pluggins에, 나는 후크 사용

add_action('init', 'my_function_to_process'); 
add_action('template_redirect', 'my_function_to_draw'); 

를 그리고 나는 그들이 내 pluggin의 파일에 무엇을해야 할 그 두 가지 기능을 만들 수 있습니다.

당신은 후크에 대한 자세한 내용은 후크의 데이터베이스 API를 확인 할 수 있습니다 :

편집

그냥 변경

http://codex.wordpress.org/Plugin_API/Action_Reference

행운을 빕니다 :

wp_redirect('http://www.google.com'); 

경우 : 승리로가는 것

?><script>window.href.location = "http://www.google.com";</script><?php exit(); 

그리고 ... 그것은 통합의 관점에서 추한,

+0

플러그인이 아닙니다. 프런트 엔드 등록 양식으로 wp-login.php 등록으로 리디렉션하지 않고 사이트 디자인 내에서 등록 할 수 있습니다. 이 변경 사항이 있으면 확실하지 않습니다 :) –

+0

여전히 모든 것을 변경하면 Wordpress 그리기가 시작되기 전에 코드를 포함하는 방법을 찾아야합니다. Wordpress가 그리기 시작한 후 코드를 처리하는 경우 헤더가 이미 전송 되었기 때문에 리디렉션 할 수 없습니다. 물론 플러그 인이 아니지만 이전에 해당 처리 코드를로드하는 방법을 찾아야합니다. 플러그인은 일찍로드되기 때문에 나쁜 생각이 아닙니다 ... –

+0

"submit", "mywebpage.com으로 사용자 보내기"라는 "submit"이 눌러 진 후에 jQuery 또는 뭔가를 추가 할 수 있습니까? –

관련 문제