Add New screen. * * This file is part of the WP-Members plugin by Chad Butler * You can find out more about this plugin at https://rocketgeek.com * Copyright (c) 2006-2019 Chad Butler * WP-Members(tm) is a trademark of butlerblog.com * * @package WP-Members * @author Chad Butler * @copyright 2006-2019 * * Functions Included: * - wpmem_do_wp_register_form * - wpmem_do_wp_newuser_form */ // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit(); } /** * Appends WP-Members registration fields to wp-login.php registration form. * * @since 2.8.7 * @since 3.1.1 Updated to support new (3.1.0) field types. * @since 3.1.6 Updated to support new fields array. Added WC classes. * @since 3.1.8 Added $process parameter. */ function wpmem_do_wp_register_form( $process = 'wp' ) { global $wpmem; $wpmem_fields = wpmem_fields( $process ); // Check if this is WooCommerce account page. $is_woo = false; if ( 'woo' == $process ) { $is_woo = true; } else { if ( function_exists( 'is_account_page' ) ) { $is_woo = ( is_account_page() ) ? true : $is_woo; } } if ( isset( $wpmem_fields ) && is_array( $wpmem_fields ) ) { unset( $wpmem_fields['username'] ); foreach ( $wpmem_fields as $meta_key => $field ) { $req = ( $field['required'] ) ? ( ( $is_woo ) ? ' *' : ' ' . __( '(required)' ) . '' ) : ''; // File fields not yet supported for this form. if ( $field['register'] && $meta_key != 'user_email' && $field['type'] != 'file' && $field['type'] != 'image' ) { if ( 'checkbox' == $field['type'] ) { if ( 'tos' == $meta_key ) { $tos_content = stripslashes( get_option( 'wpmembers_tos' ) ); if ( has_shortcode( $tos_content, 'wpmem_tos' ) || has_shortcode( $tos_content, 'wp-members' ) ) { $link = do_shortcode( $tos_content ); $tos_pop = ''; } else { $tos_pop = ""; } /** This filter is documented in wp-members/inc/register.php */ $tos_link_text = apply_filters( 'wpmem_tos_link_txt', $wpmem->get_text( 'register_tos' ), 'new' ); // If filtered value is not the default label, use that, otherwise use label. // @note: if default changes, this check must change. if ( __( 'Please indicate that you agree to the %s Terms of Service %s', 'wp-members' ) == $tos_link_text ) { if ( __( 'TOS', 'wp-members' ) != $field['label'] && __( 'Terms of Service', 'wp-members' ) != $field['label'] ) { $tos_link_text = $field['label']; } } // If tos string does not contain link identifiers (%s), wrap the whole string. if ( ! strpos( $tos_link_text, '%s' ) ) { $tos_link_text = '%s' . $tos_link_text . '%s'; } $tos_link_text = ' ' . sprintf( $tos_link_text, $tos_pop, '' ); } $label = ( 'tos' == $meta_key ) ? $tos_link_text : __( $field['label'], 'wp-members' ); $val = ( isset( $_POST[ $meta_key ] ) ) ? esc_attr( $_POST[ $meta_key ] ) : ''; $val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val; $row_before = '
'; $label = '
'; } elseif ( 'hidden' == $field['type'] ) { // Handle hidden fields $row_before = ''; $label = ''; $input = wpmem_form_field( array( 'name' => $meta_key, 'type' => $field['type'], 'value' => $field['value'], 'compare' => $valtochk, 'required' => $field['required'], ) ); $row_after = ''; } else { $row_before = ( $is_woo ) ? '' : '
'; $label = '
'; } // if the row is set to display, add the row to the form array $rows[ $meta_key ] = array( 'type' => $field['type'], 'row_before' => $row_before, 'label' => $label, 'field' => $input, 'row_after' => $row_after, ); } } if ( isset( $rows ) && is_array( $rows ) ) { /** * Filter the native registration form rows. * * @since 2.9.3. * * @param array $rows The custom rows added to the form. */ $rows = apply_filters( 'wpmem_native_form_rows', $rows ); foreach ( $rows as $row_item ) { if ( $row_item['type'] == 'checkbox' ) { echo $row_item['row_before'] . $row_item['field'] . $row_item['label'] . $row_item['row_after']; } else { echo $row_item['row_before'] . $row_item['label'] . $row_item['field'] . $row_item['row_after']; } } } } } /** * Appends WP-Members registration fields to Users > Add New User screen. * * @since 2.9.0 * @since 3.1.1 Updated to support new (3.1.0) field types and user activation. * @since 3.1.6 Updated to support new fields array. */ function wpmem_do_wp_newuser_form() { global $wpmem; echo '| '; // determine the field type and generate accordingly. switch ( $field['type'] ) { case( 'select' ): $val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : ''; echo wpmem_create_formfield( $meta_key, $field['type'], $field['values'], $val ); break; case( 'textarea' ): echo ''; break; case( 'checkbox' ): $val = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : ''; $val = ( ! $_POST && $field['checked_default'] ) ? $field['checked_value'] : $val; echo wpmem_create_formfield( $meta_key, $field['type'], $field['checked_value'], $val ); break; case( 'multiselect' ): case( 'multicheckbox' ): case( 'radio' ): $valtochk = ( isset( $_POST[ $meta_key ] ) ) ? sanitize_text_field( $_POST[ $meta_key ] ) : ''; $formfield_args = array( 'name' => $meta_key, 'type' => $field['type'], 'value' => $field['values'], 'compare' => $valtochk, 'required' => $field['required'], ); if ( 'multicheckbox' == $field['type'] || 'multiselect' == $field['type'] ) { $formfield_args['delimiter'] = $field['delimiter']; } echo $wpmem->forms->create_form_field( $formfield_args ); break; case( 'file' ): case( 'image' ): break; default: echo ''; break; } echo ' | |
| ' . $wpmem->forms->create_form_field( array( 'name' => 'activate_user', 'type' => 'checkbox', 'value' => 1, 'compare' => '' ) ) . ' |