' : '',
'row_after' => $args['row_after'],
);
}
/**
* Filter the array of form rows.
*
* This filter receives an array of the main rows in the form, each array element being
* an array of that particular row's pieces. This allows making changes to individual
* parts of a row without needing to parse through a string of HTML.
*
* @since 2.9.0
* @since 3.0.9 Added $rows['label_text'].
* @since 3.1.0 Added $rows['key'].
* @since 3.1.6 Deprecated $rows['order'].
*
* @param array $rows {
* An array containing the form rows.
*
* @type string order Field display order. (deprecated as of 3.1.6)
* @type string meta Field meta tag (not used for display).
* @type string type Input field type (not used for display).
* @type string value Input field value (not used for display).
* @type string values Possible field values (dropdown, multiple select/check, radio).
* @type string label_text Raw text for the label (not used for display).
* @type string row_before Opening wrapper tag around the row.
* @type string label Label tag.
* @type string field_before Opening wrapper tag before the input tag.
* @type string field The field input tag.
* @type string field_after Closing wrapper tag around the input tag.
* @type string row_after Closing wrapper tag around the row.
* }
* @param string $tag Toggle new registration or profile update. new|edit.
*/
$rows = apply_filters( 'wpmem_register_form_rows', $rows, $tag );
// Make sure all keys are set just in case someone didn't return a proper array through the filter.
// @todo Merge this with the next foreach loop so we only have to foreach one time.
$row_keys = array( 'meta', 'type', 'value', 'values', 'label_text', 'row_before', 'label', 'field_before', 'field', 'field_after', 'row_after' );
foreach ( $rows as $meta_key => $row ) {
foreach ( $row_keys as $check_key ) {
$rows[ $meta_key ][ $check_key ] = ( isset( $rows[ $meta_key ][ $check_key ] ) ) ? $rows[ $meta_key ][ $check_key ] : '';
}
}
// Put the rows from the array into $form.
$form = ''; $enctype = '';
foreach ( $rows as $row_item ) {
// Check form to see if we need multipart enctype.
$enctype = ( $row_item['type'] == 'file' || $row_item['type'] == 'image' ) ? "multipart/form-data" : $enctype;
// Assemble row pieces.
$row = ( $row_item['row_before'] != '' ) ? $row_item['row_before'] . $args['n'] . $row_item['label'] . $args['n'] : $row_item['label'] . $args['n'];
$row .= ( $row_item['field_before'] != '' ) ? $row_item['field_before'] . $args['n'] . $args['t'] . $row_item['field'] . $args['n'] . $row_item['field_after'] . $args['n'] : $row_item['field'] . $args['n'];
$row .= ( $row_item['row_after'] != '' ) ? $row_item['row_after'] . $args['n'] : '';
$form.= $row;
}
// Do recaptcha if enabled.
if ( ( $wpmem->captcha == 1 || $wpmem->captcha == 3 ) && $tag != 'edit' ) { // don't show on edit page!
// Get the captcha options.
$wpmem_captcha = get_option( 'wpmembers_captcha' );
// Start with a clean row.
$row = '';
$row = '';
$row.= '
';
// Add the captcha row to the form.
/**
* Filter the HTML for the CAPTCHA row.
*
* @since 2.9.0
*
* @param string The HTML for the entire row (includes HTML tags plus reCAPTCHA).
* @param string $tag Toggle new registration or profile update. new|edit.
*/
$form.= apply_filters( 'wpmem_register_captcha_row', $args['row_before'] . $row . $args['row_after'], $tag );
}
// Create hidden fields.
$var = ( $tag == 'edit' ) ? 'update' : 'register';
$redirect_to = ( isset( $_REQUEST['redirect_to'] ) ) ? $_REQUEST['redirect_to'] : ( ( $redirect_to ) ? $redirect_to : get_permalink() );
$hidden_rows['_wpmem_a'] = '';
$hidden_rows['_wpmem_reg_page'] = '';
if ( $redirect_to != get_permalink() ) {
$hidden_rows['_wpmem_redirect_to'] = '';
}
/**
* Filter the hidden form rows.
*
* @since 3.2.0
*
* @param array $hidden_rows
* @param string $tag
*/
$hidden_rows = apply_filters( 'wpmem_register_hidden_rows', $hidden_rows, $tag );
// Assemble hidden fields HTML.
$hidden = '';
foreach ( $hidden_rows as $hidden_row ) {
$hidden .= $hidden_row . $args['n'];
}
/**
* Filter the hidden field HTML.
*
* @since 2.9.0
*
* @param string $hidden The generated HTML of hidden fields.
* @param string $tag Toggle new registration or profile update. new|edit.
*/
$hidden = apply_filters( 'wpmem_register_hidden_fields', $hidden, $tag );
// Add the hidden fields to the form.
$form.= $hidden;
// Create buttons and wrapper.
$button_text = ( $tag == 'edit' ) ? $args['submit_update'] : $args['submit_register'];
$button_html = array(
'reset' => ( $args['show_clear_form'] ) ? ' ' : '',
'submit' => '',
);
$buttons = $button_html['reset'] . $args['n'] . $button_html['submit'] . $args['n'];
/**
* Filter the HTML for form buttons.
*
* The string passed through the filter includes the buttons, as well as the HTML wrapper elements.
*
* @since 2.9.0
* @since 3.2.6 Added $button_html parameter
*
* @param string $buttons The generated HTML of the form buttons.
* @param string $tag Toggle new registration or profile update. new|edit.
* @param array $button_html The individual button html.
*/
$buttons = apply_filters( 'wpmem_register_form_buttons', $buttons, $tag, $button_html );
// Add the buttons to the form.
$form.= $args['buttons_before'] . $args['n'] . $buttons . $args['buttons_after'] . $args['n'];
// Add the required field notation to the bottom of the form.
$form.= $args['req_label_before'] . $args['req_label'] . $args['req_label_after'];
// Apply the heading.
/**
* Filter the registration form heading.
*
* @since 2.8.2
*
* @param string $str
* @param string $tag Toggle new registration or profile update. new|edit.
*/
$heading = ( !$heading ) ? apply_filters( 'wpmem_register_heading', $wpmem->get_text( 'register_heading' ), $tag ) : $heading;
$form = $args['heading_before'] . $heading . $args['heading_after'] . $args['n'] . $form;
// Apply fieldset wrapper.
$form = $args['fieldset_before'] . $args['n'] . $form . $args['n'] . $args['fieldset_after'];
// Apply attribution if enabled.
$form = $form . wpmem_inc_attribution();
// Apply nonce. Nonce uses $tag value of the form processor, NOT the form builder.
$nonce = ( $tag == 'edit' ) ? 'update' : 'register';
$form = wp_nonce_field( 'wpmem_longform_nonce', '_wpmem_' . $nonce . '_nonce', true, false ) . $args['n'] . $form;
// Apply form wrapper.
$enctype = ( $enctype == 'multipart/form-data' ) ? ' enctype="multipart/form-data"' : '';
$form = '';
// Apply anchor.
$form = '' . $args['n'] . $form;
// Apply main div wrapper.
$form = $args['main_div_before'] . $args['n'] . $form . $args['n'] . $args['main_div_after'] . $args['n'];
// Apply wpmem_txt wrapper.
$form = $args['txt_before'] . $form . $args['txt_after'];
// Remove line breaks if enabled for easier filtering later.
$form = ( $args['strip_breaks'] ) ? $this->strip_breaks( $form, $rows ) : $form; //str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form ) : $form;
/**
* Filter the generated HTML of the entire form.
*
* @since 2.7.4
*
* @param string $form The HTML of the final generated form.
* @param string $tag Toggle new registration or profile update. new|edit.
* @param array $rows {
* An array containing the form rows.
*
* @type string order Field display order.
* @type string meta Field meta tag (not used for display).
* @type string type Input field type (not used for display).
* @type string value Input field value (not used for display).
* @type string values The possible values for the field (dropdown, multiple select/checkbox, radio group).
* @type string label_text Raw text for the label (not used for display).
* @type string row_before Opening wrapper tag around the row.
* @type string label Label tag.
* @type string field_before Opening wrapper tag before the input tag.
* @type string field The field input tag.
* @type string field_after Closing wrapper tag around the input tag.
* @type string row_after Closing wrapper tag around the row.
* }
* @param string $hidden The HTML string of hidden fields
*/
$form = apply_filters( 'wpmem_register_form', $form, $tag, $rows, $hidden );
/**
* Filter before the form.
*
* This rarely used filter allows you to stick any string onto the front of
* the generated form.
*
* @since 2.7.4
*
* @param string $str The HTML to add before the form. Default null.
* @param string $tag Toggle new registration or profile update. new|edit.
*/
$form = apply_filters( 'wpmem_register_form_before', '', $tag ) . $form;
// Return the generated form.
return $form;
} // End register_form().
/**
* Strip line breaks from form.
*
* Function removes line breaks and tabs. Checks for textarea fields
* before stripping line breaks.
*
* @since 3.1.8
*
* @param string $form
* @param array $rows
* @return string $form
*/
function strip_breaks( $form, $rows ) {
foreach( $rows as $key => $row ) {
if ( 'textarea' == $row['type'] ) {
$textareas[ $key ] = $row['field'];
}
}
$form = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $form );
if ( ! empty ( $textareas ) ) {
foreach ( $textareas as $textarea ) {
$stripped = str_replace( array( "\n", "\r", "\t" ), array( '','','' ), $textarea );
$form = str_replace( $stripped, $textarea, $form );
}
}
return $form;
}
/**
* Login Dialog.
*
* Loads the login form for user login.
*
* @since 1.8
* @since 3.1.4 Global $wpmem_regchk no longer needed.
* @since 3.2.0 Moved to forms class, renamed do_login_form().
*
* @global object $post The WordPress Post object.
* @global object $wpmem The WP_Members object.
* @param string $page If the form is being displayed in place of blocked content. Default: page.
* @param string $redirect_to Redirect URL. Default: null.
* @param string $show If the form is being displayed in place of blocked content. Default: show.
* @return string $str The generated html for the login form.
*/
function do_login_form( $page = "page", $redirect_to = null, $show = 'show' ) {
global $post, $wpmem;
$str = '';
if ( $page == "page" ) {
if ( $wpmem->regchk != "success" ) {
$dialogs = get_option( 'wpmembers_dialogs' );
// This shown above blocked content.
$msg = $wpmem->get_text( 'restricted_msg' );
$msg = ( $dialogs['restricted_msg'] == $msg ) ? $msg : __( stripslashes( $dialogs['restricted_msg'] ), 'wp-members' );
$str = '
' . $msg . '
';
/**
* Filter the post restricted message.
*
* @since 2.7.3
* @since 3.2.0 Added raw message string and HTML as separate params.
*
* @param string $str The post restricted message with HTML.
* @param string $msg The raw message string.
* @param string The 'before' HTML wrapper.
* @param string The 'after' HTML wrapper.
*/
$str = apply_filters( 'wpmem_restricted_msg', $str, $msg, '
', '
' );
}
}
// Create the default inputs.
$default_inputs = array(
array(
'name' => $wpmem->get_text( 'login_username' ),
'type' => 'text',
'tag' => 'log',
'class' => 'username',
'div' => 'div_text',
),
array(
'name' => $wpmem->get_text( 'login_password' ),
'type' => 'password',
'tag' => 'pwd',
'class' => 'password',
'div' => 'div_text',
),
);
/**
* Filter the array of login form fields.
*
* @since 2.9.0
*
* @param array $default_inputs An array matching the elements used by default.
*/
$default_inputs = apply_filters( 'wpmem_inc_login_inputs', $default_inputs );
$defaults = array(
'heading' => $wpmem->get_text( 'login_heading' ),
'action' => 'login',
'button_text' => $wpmem->get_text( 'login_button' ),
'inputs' => $default_inputs,
'redirect_to' => $redirect_to,
);
/**
* Filter the arguments to override login form defaults.
*
* @since 2.9.0
*
* @param array $args An array of arguments to use. Default null.
*/
$args = apply_filters( 'wpmem_inc_login_args', '' );
$arr = wp_parse_args( $args, $defaults );
$str = ( $show == 'show' ) ? $str . wpmem_login_form( $page, $arr ) : $str;
return $str;
}
/**
* Change Password Dialog.
*
* Loads the form for changing password.
*
* @since 2.0.0
* @since 3.2.0 Moved to forms class, renamed do_changepassword_form().
*
* @global object $wpmem The WP_Members object.
* @return string $str The generated html for the change password form.
*/
function do_changepassword_form() {
global $wpmem;
// create the default inputs
$default_inputs = array(
array(
'name' => $wpmem->get_text( 'pwdchg_password1' ),
'type' => 'password',
'tag' => 'pass1',
'class' => 'password',
'div' => 'div_text',
),
array(
'name' => $wpmem->get_text( 'pwdchg_password2' ),
'type' => 'password',
'tag' => 'pass2',
'class' => 'password',
'div' => 'div_text',
),
);
/**
* Filter the array of change password form fields.
*
* @since 2.9.0
*
* @param array $default_inputs An array matching the elements used by default.
*/
$default_inputs = apply_filters( 'wpmem_inc_changepassword_inputs', $default_inputs );
$defaults = array(
'heading' => $wpmem->get_text( 'pwdchg_heading' ),
'action' => 'pwdchange',
'button_text' => $wpmem->get_text( 'pwdchg_button' ),
'inputs' => $default_inputs,
);
/**
* Filter the arguments to override change password form defaults.
*
* @since 2.9.0
*
* @param array $args An array of arguments to use. Default null.
*/
$args = apply_filters( 'wpmem_inc_changepassword_args', '' );
$arr = wp_parse_args( $args, $defaults );
$str = wpmem_login_form( 'page', $arr );
return $str;
}
/**
* Reset Password Dialog.
*
* Loads the form for resetting password.
*
* @since 2.1.0
* @since 3.2.0 Moved to forms class, renamed do_resetpassword_form().
*
* @global object $wpmem The WP_Members object.
* @return string $str The generated html fo the reset password form.
*/
function do_resetpassword_form() {
global $wpmem;
// Create the default inputs.
$default_inputs = array(
array(
'name' => $wpmem->get_text( 'pwdreset_username' ),
'type' => 'text',
'tag' => 'user',
'class' => 'username',
'div' => 'div_text',
),
array(
'name' => $wpmem->get_text( 'pwdreset_email' ),
'type' => 'text',
'tag' => 'email',
'class' => 'text',
'div' => 'div_text',
),
);
/**
* Filter the array of reset password form fields.
*
* @since 2.9.0
*
* @param array $default_inputs An array matching the elements used by default.
*/
$default_inputs = apply_filters( 'wpmem_inc_resetpassword_inputs', $default_inputs );
$defaults = array(
'heading' => $wpmem->get_text( 'pwdreset_heading' ),
'action' => 'pwdreset',
'button_text' => $wpmem->get_text( 'pwdreset_button' ),
'inputs' => $default_inputs,
);
/**
* Filter the arguments to override reset password form defaults.
*
* @since 2.9.0
*
* @param array $args An array of arguments to use. Default null.
*/
$args = apply_filters( 'wpmem_inc_resetpassword_args', '' );
$arr = wp_parse_args( $args, $defaults );
$str = wpmem_login_form( 'page', $arr );
return $str;
}
/**
* Forgot Username Form.
*
* Loads the form for retrieving a username.
*
* @since 3.0.8
* @since 3.2.0 Moved to forms class, renamed do_forgotusername_form().
*
* @global object $wpmem The WP_Members object class.
* @return string $str The generated html for the forgot username form.
*/
function do_forgotusername_form() {
global $wpmem;
// create the default inputs
$default_inputs = array(
array(
'name' => $wpmem->get_text( 'username_email' ),
'type' => 'text',
'tag' => 'user_email',
'class' => 'username',
'div' => 'div_text',
),
);
/**
* Filter the array of forgot username form fields.
*
* @since 2.9.0
*
* @param array $default_inputs An array matching the elements used by default.
*/
$default_inputs = apply_filters( 'wpmem_inc_forgotusername_inputs', $default_inputs );
$defaults = array(
'heading' => $wpmem->get_text( 'username_heading' ),
'action' => 'getusername',
'button_text' => $wpmem->get_text( 'username_button' ),
'inputs' => $default_inputs,
);
/**
* Filter the arguments to override change password form defaults.
*
* @since
*
* @param array $args An array of arguments to use. Default null.
*/
$args = apply_filters( 'wpmem_inc_forgotusername_args', '' );
$arr = wp_parse_args( $args, $defaults );
$str = wpmem_login_form( 'page', $arr );
return $str;
}
} // End of WP_Members_Forms class.