1
I have a user registration form inside my shortcode.
Complete code
<?php
$user_login_RU = $_POST['username_RU'];
$user_email_RU= $_POST['email_RU'];
if(isset($user_login_RU, $user_email_RU)){
$teste = register_new_user($user_login, $user_email);
if ( !is_wp_error($teste) ) {
$redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
wp_safe_redirect( $redirect_to );
}
//register meta values
register_users_save_dados( $id_new_user, $_POST);
}
function register_users_shortcode(){
global $post;
?>
<div id="form1">
<form id="form1" name="form1"action="" method="POST" ectype="multipart/form-data">
<p>
<label for="nome_RU">Username:</label>
<br />
<input type="text" name="username_RU" id="username_RU" value="<?php echo get_post_meta( $post->ID, '_username_RU', true ); ?>" />
</p>
<p>
<label for="email_RU">E-mail:</label>
<br />
<input type="email" name="email_RU" id="email_RU"value="<?php echo get_post_meta( $post->ID, '_email_RU', true ); ?>" />
</p>
<p>
<h2>Tipo de cadastro</h2>
Empregador <input type="radio" name="type_user" onclick="document.getElementById('empregador').style.display = 'block'; document.getElementById('trabalhador').style.display = 'none'"value="<?php echo get_post_meta( $post->ID, '_empregador', true ); ?>">
Trabalhador <input type="radio" name="type_user" onclick="document.getElementById('empregador').style.display = 'none'; document.getElementById('trabalhador').style.display = 'block'"value="<?php echo get_post_meta( $post->ID, '_Empregador', true ); ?>">
</p>
<div id="empregador" style="display:none">
<h3>Identificação do empregador</h3>
<strong>*Tipo de indentificação:</strong><br />
<?php echo register_render("tipo_id_empregador", "radio","tipo_id_empregador" ,array("CNPJ","CPF","CEI")); ?><br />
<strong>*Número de indentificação:</strong>
<?php echo register_render('numeroIdEmpregador','text'); ?>
<h3>Dados referente ao empregador</a></h3>
<strong>*Razão social:</strong>
<?php echo register_render('razaoSocialEmpregador','text'); ?>
<strong>*Nome fantasia:</strong>
<?php echo register_render('nomeFantasiaEmpregador','text'); ?>
<h3>Localização da empresa</h3>
<strong>*Logradouro:</strong>
<?php echo register_render('logradouroEmpregador','text'); ?>
<br />
</div>
<div id="trabalhador" style="display:none">
<h3>Indentificação do Trabalhador</h3>
<strong>*Número de Indentificação (PIS/PASEP/NIS/NIT)</strong>
<?php echo register_render('numeroIdTralhador','text'); ?> <br />
<strong>*Nome da mãe do trabalhador</strong>
<?php echo register_render('maeTrabalhador','text'); ?>
</div>
<input type="submit" name="sub" value="cadastrar">
</form>
</div>
<?php }
add_shortcode('my-form','register_users_shortcode');
function to save dynamic inputs
function register_users_save_dados( $id_register_users,$value) {
foreach ($value as $key) {
if(isset($_POST[$key]))
add_post_meta( $id_register_users, '_$key', strip_tags( $_POST[$key] ) );
}
}
but I can’t register a new user, comes the following log error:
Call to Undefined Function
get_user_by()
Any, please organize your code logically. It makes it easier for you to find the problems for yourself, and whoever helps you will read the code quickly without wasting time deciphering the flow of things.
– brasofilo
Please edit the Question, the Answers field is for solutions. . . . . Didn’t you say where your codes are located, which file? Is it the same? . . . Tip: you are programming without having the
WP_DEBUG
turned on, it shows small program errors (type$var = $_POST['NOME']
, that drops a notice and should be avoided): http://codex.wordpress.org/Debugging_in_WordPress– brasofilo
I never used wp_debug, obg for this tip.
– Any Karolyne Galdino
You still haven’t told me where this code is. What a file?
– brasofilo
It is inside a folder called shortcodes, inside the folder of my plugin, the function is in another folder called functions, and both are called in my root folder where I define the name of my plugin.
– Any Karolyne Galdino
Yeah, without having one Minimum, Complete and Verifiable Example your code makes it hard to answer. I’m sorry.
– brasofilo