Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Custom form in Restrict content pro wordpress plugin
- // put this code on functions.php theme file
- // replace all variables (example: $telefono for your custom variable: $phone)
- // save and enjoy
- /**
- * Adds the custom fields to the registration form and profile editor
- *
- */
- function pw_rcp_add_user_fields() {
- $telefono = get_user_meta( get_current_user_id(), 'rcp_telefono', true );
- $actividad = get_user_meta( get_current_user_id(), 'rcp_actividad', true );
- $dependencia = get_user_meta( get_current_user_id(), 'rcp_dependencia', true );
- ?>
- <p>
- <label for="rcp_telefono"><?php _e( 'Teléfono', 'rcp' ); ?></label>
- <input name="rcp_telefono" id="rcp_telefono" type="tel" value="<?php echo esc_attr( $telefono ); ?>"/>
- </p>
- <p>
- <label for="rcp_actividad"><?php _e( 'Tu Actividad', 'rcp' ); ?></label>
- <input name="rcp_actividad" id="rcp_actividad" type="text" value="<?php echo esc_attr( $actividad ); ?>"/>
- </p>
- <p>
- <label for="rcp_dependendia"><?php _e( 'Dependencia', 'rcp' ); ?></label>
- <input name="rcp_Dependencia" id="rcp_dependencia" type="text" value="<?php echo esc_attr( $dependencia ); ?>"/>
- </p>
- <?php
- }
- add_action( 'rcp_after_password_registration_field', 'pw_rcp_add_user_fields' );
- add_action( 'rcp_profile_editor_after', 'pw_rcp_add_user_fields' );
- /**
- * Adds the custom fields to the member edit screen
- *
- */
- function pw_rcp_add_member_edit_fields( $user_id = 0 ) {
- $telefono = get_user_meta( $user_id, 'rcp_telefono', true );
- $actividad = get_user_meta( $user_id, 'rcp_actividad', true );
- $dependencia = get_user_meta( $user_id), 'rcp_dependencia', true);
- ?>
- <tr valign="top">
- <th scope="row" valign="top">
- <label for="rcp_telefono"><?php _e( 'Telefono ', 'rcp' ); ?></label>
- </th>
- <td>
- <input name="rcp_telefono" id="rcp_telefono" type="text" value="<?php echo esc_attr( $telefono ); ?>"/>
- <p class="description"><?php _e( 'Teléfono ', 'rcp' ); ?></p>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row" valign="top">
- <label for="rcp_actividad"><?php _e( 'Actividad', 'rcp' ); ?></label>
- </th>
- <td>
- <input name="rcp_actividad" id="rcp_actividad" type="text" value="<?php echo esc_attr( $actividad ); ?>"/>
- <p class="description"><?php _e( 'Actividad', 'rcp' ); ?></p>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row" valign="top">
- <label for="rcp_dependencia"><?php _e( 'Dependencia', 'rcp' ); ?></label>
- </th>
- <td>
- <input name="rcp_dependencia" id="rcp_dependencia" type="text" value="<?php echo esc_attr( $dependencia ); ?>"/>
- <p class="description"><?php _e( 'Dependencia', 'rcp' ); ?></p>
- </td>
- </tr>
- <?php
- }
- add_action( 'rcp_edit_member_after', 'pw_rcp_add_member_edit_fields' );
- /**
- * Determines if there are problems with the registration data submitted
- *
- */
- function pw_rcp_validate_user_fields_on_register( $posted ) {
- if ( is_user_logged_in() ) {
- return;
- }
- if( empty( $posted['rcp_telefono'] ) ) {
- rcp_errors()->add( 'invalid_telefono', __( 'Escriba su teléfono ', 'rcp' ), 'register' );
- }
- if( empty( $posted['rcp_actividad'] ) ) {
- rcp_errors()->add( 'invalid_actividad', __( 'Escriba su actividad', 'rcp' ), 'register' );
- }
- if( empty( $posted['rcp_dependencia'] ) ) {
- rcp_errors()->add( 'invalid_dependencia', __( 'Escriba su dependencia', 'rcp' ), 'register' );
- }
- }
- add_action( 'rcp_form_errors', 'pw_rcp_validate_user_fields_on_register', 10 );
- /**
- * Stores the information submitted during registration
- *
- */
- function pw_rcp_save_user_fields_on_register( $posted, $user_id ) {
- if( ! empty( $posted['rcp_telefono'] ) ) {
- update_user_meta( $user_id, 'rcp_telefono', sanitize_text_field( $posted['rcp_telefono'] ) );
- }
- if( ! empty( $posted['rcp_actividad'] ) ) {
- update_user_meta( $user_id, 'rcp_actividad', sanitize_text_field( $posted['rcp_actividad'] ) );
- }
- if( ! empty( $posted['rcp_dependencia'] ) ) {
- update_user_meta( $user_id, 'rcp_dependencia', sanitize_text_field( $posted['rcp_dependencia'] ) );
- }
- }
- add_action( 'rcp_form_processing', 'pw_rcp_save_user_fields_on_register', 10, 2 );
- /**
- * Stores the information submitted profile update
- *
- */
- function pw_rcp_save_user_fields_on_profile_save( $user_id ) {
- if( ! empty( $_POST['rcp_telefono'] ) ) {
- update_user_meta( $user_id, 'rcp_telefono', sanitize_text_field( $_POST['rcp_telefono'] ) );
- }
- if( ! empty( $_POST['rcp_actividad'] ) ) {
- update_user_meta( $user_id, 'rcp_actividad', sanitize_text_field( $_POST['rcp_actividad'] ) );
- }
- if( ! empty( $_POST['rcp_dependencia'] ) ) {
- update_user_meta( $user_id, 'rcp_dependencia', sanitize_text_field( $_POST['rcp_dependencia'] ) );
- }
- }
- add_action( 'rcp_user_profile_updated', 'pw_rcp_save_user_fields_on_profile_save', 10 );
- add_action( 'rcp_edit_member', 'pw_rcp_save_user_fields_on_profile_save', 10 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement