Last active
July 23, 2016 20:00
Referring to this post on github:https://github.com/danahutchins/wp-members-bootstrap-forms/blob/master/wp-members-pluggable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This gist is set up to diplay the correct way to customize forms in WP-Members. | |
* | |
* It is in reference to this script file: | |
* https://github.com/danahutchins/wp-members-bootstrap-forms/blob/master/wp-members-pluggable.php | |
* | |
* The author of that script indicates in this post: | |
* http://www.inforest.com/updating-wp-members-wordpress-plugin-for-twitter-bootstrap/ | |
* that "Rather than going to the trouble of writing hooks, I decided to simply | |
* write new functions to generate the forms for Bootstrap, because it was easier | |
* and I assumed any changes to these functions would probably require rewriting | |
* hooks anyway." | |
* | |
* While I applaud Dana's efforts as well as his sharing this in general, | |
* that's actually not a good approach. That is why I am posting this as I would | |
* like to discourage that approach while explaining why and giving what is the | |
* preferred approach. | |
* | |
* First, you would not go to the trouble of "writing hooks" - the hooks | |
* are already there. What you would go through the trouble of would be hooking | |
* filter functions to those hooks. If you're going to bother to rewrite the | |
* function, it would in fact be much easier to use thefilters AND you would | |
* end up with a result that would not require you to rewrite your work when | |
* you update, as Dana assumed. | |
* | |
* Pluggable functions should only be used as a last resort when there is no | |
* current way to implement a necessary feature or customization. The trade-off | |
* with pluggable functions is that they may not be compatible with future | |
* releases, as will be the case with the above mentioned implementation when | |
* version 3.1 is released. If done correctly using the appropriate filter | |
* hooks, the result would be fully compatible when updating. | |
* | |
* These filters currently cover everything in the above mentioned post except | |
* the registration form function. | |
*/ | |
add_filter( 'wpmem_restricted_msg', 'my_restricted_msg' ); | |
function my_restricted_msg( $str ) { | |
return '<h4>Sell Sheets | Art Files | Order Forms</h4>'; | |
} | |
/** | |
* Since the login and password change/reset forms need | |
* the same custom classes, the same function can be used | |
* for all three of these filters. | |
*/ | |
add_filter( 'wpmem_inc_login_inputs', 'my_custom_inputs' ); | |
add_filter( 'wpmem_inc_changepassword_inputs', 'my_custom_inputs' ); | |
add_filter( 'wpmem_inc_resetpassword_inputs', 'my_custom_inputs' ); | |
function my_custom_inputs( $default_inputs ) { | |
$default_inputs[0]['class'] = 'form-control'; | |
$default_inputs[0]['div'] = 'col-sm-8'; | |
$default_inputs[1]['class'] = 'form-control'; | |
$default_inputs[1]['div'] = 'col-sm-8'; | |
return $default_inputs; | |
} | |
add_filter( 'wpmem_inc_login_args', 'my_inc_login_args' ); | |
function my_inc_login_args( $args ) { | |
$args['heading'] = 'Established Users'; | |
return $args; | |
} | |
/** | |
* This filter actually handles the login form, the password reset form, | |
* the change password form, and the new forgot username form. | |
*/ | |
add_filter( 'wpmem_login_form', 'my_login_form', 10, 2 ); | |
function my_login_form( $form, $toggle ) { | |
global $wpmem; | |
// Put the custom opening div wrappers before original form HTML | |
$form = "<div class=\"row grey\"><div class=\"col-sm-6 grey\">" . $form; | |
// Continue with custom HTML that comes after the form HTML. | |
$form .= "</div>\n"; | |
$form .= "<div class=\"col-sm-6\">"; | |
$form .= "<h3>New Users</h3>\n"; | |
$form .= "<p>If you are a Dutch Cheese Maker broker or customer and would like to apply for access, click \"Create Account\" and enter the information requested on the next page.</p>\n"; | |
$form .= '<div style="text-align:center;"><a class="btn btn-primary contact-btn" href="' . $wpmem->user_pages['register'] . '">Create Account</a></div>'; | |
$form .= "</div>\n"; | |
$form .= "</div>\n"; | |
return $form; | |
} | |
/** | |
* This filter actually handles the login form, the password reset form, | |
* the change password form, and the new forgot username form. | |
*/ | |
add_filter( 'wpmem_login_form_args', 'my_login_form_args', 10, 2 ); | |
function my_login_form_args( $args, $action ) { | |
$args = array( | |
'heading_before' => '<h3>', | |
'heading_after' => '</h3>', | |
'fieldset_before' => '<div class="form-group">', | |
'fieldset_after' => '</div>', | |
'buttons_before' => '<div class="form-group"><div class="col-sm-offset-4 col-sm-8">', | |
'buttons_after' => '</div></div>', | |
'link_before' => '<div class="row"><div class="col-sm-offset-2 col-sm-10">', | |
'link_after' => '</div></div>', | |
'form_class' => 'form-horizontal', | |
'button_class' => 'btn btn-primary contact-btn', | |
); | |
return $args; | |
} | |
/** | |
* This filter actually handles the login form, the password reset form, | |
* the change password form, and the new forgot username form. | |
*/ | |
add_filter( 'wpmem_login_form_rows', 'my_login_form_rows', 10, 2 ); | |
function my_login_form_rows( $rows, $action ) { | |
// Set up replacement variables. | |
$old = '<label'; | |
$new = '<label class="col-sm-4 control-label" '; | |
// str_replace on the label tag to slip in custom class. | |
$rows[0]['label'] = str_replace( $old, $new, $rows[0]['label'] ); | |
$rows[1]['label'] = str_replace( $old, $new, $rows[1]['label'] ); | |
return $rows; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ignore this line | |
/** | |
* This filters the heading instead of changing it in the | |
* pluggable version at line 78. | |
*/ | |
add_filter( 'wpmem_inc_login_args', 'my_inc_login_args' ); | |
function my_inc_login_args( $args ) { | |
$args['heading'] = 'Established Users'; | |
return $args; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ignore this line | |
/** | |
* Since the login and password change/reset forms need | |
* the same custom classes, the same function can be used | |
* for all three of these filters. | |
* | |
* Note: these are classes that in the pluggable version were set | |
* by changing the class and div values at lines 56 & 57. | |
*/ | |
add_filter( 'wpmem_inc_login_inputs', 'my_custom_inputs' ); | |
add_filter( 'wpmem_inc_changepassword_inputs', 'my_custom_inputs' ); | |
add_filter( 'wpmem_inc_resetpassword_inputs', 'my_custom_inputs' ); | |
function my_custom_inputs( $default_inputs ) { | |
$default_inputs[0]['class'] = 'form-control'; | |
$default_inputs[0]['div'] = 'col-sm-8'; | |
$default_inputs[1]['class'] = 'form-control'; | |
$default_inputs[1]['div'] = 'col-sm-8'; | |
return $default_inputs; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ignore this line | |
/** | |
* This filter actually handles the login form, the password reset form, | |
* the change password form, and the new forgot username form. | |
* | |
* This makes the changes that are done in the pluggable version | |
* at lines 96-107 | |
*/ | |
add_filter( 'wpmem_login_form', 'my_login_form', 10, 2 ); | |
function my_login_form( $form, $toggle ) { | |
global $wpmem; | |
// Put the custom opening div wrappers before original form HTML | |
$form = "<div class=\"row grey\"><div class=\"col-sm-6 grey\">" . $form; | |
// Continue with custom HTML that comes after the form HTML. | |
$form .= "</div>\n"; | |
$form .= "<div class=\"col-sm-6\">"; | |
$form .= "<h3>New Users</h3>\n"; | |
$form .= "<p>If you are a Dutch Cheese Maker broker or customer and would like to apply for access, click \"Create Account\" and enter the information requested on the next page.</p>\n"; | |
$form .= '<div style="text-align:center;"><a class="btn btn-primary contact-btn" href="' . $wpmem->user_pages['register'] . '">Create Account</a></div>'; | |
$form .= "</div>\n"; | |
$form .= "</div>\n"; | |
return $form; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ignore this line | |
/** | |
* This filter actually handles the login form, the password reset form, | |
* the change password form, and the new forgot username form. | |
* | |
* This changes the general HTML that the pluggable version changes by | |
* editing the default in line 129-157 | |
*/ | |
add_filter( 'wpmem_login_form_args', 'my_login_form_args', 10, 2 ); | |
function my_login_form_args( $args, $action ) { | |
$args = array( | |
'heading_before' => '<h3>', | |
'heading_after' => '</h3>', | |
'fieldset_before' => '<div class="form-group">', | |
'fieldset_after' => '</div>', | |
'buttons_before' => '<div class="form-group"><div class="col-sm-offset-4 col-sm-8">', | |
'buttons_after' => '</div></div>', | |
'link_before' => '<div class="row"><div class="col-sm-offset-2 col-sm-10">', | |
'link_after' => '</div></div>', | |
'form_class' => 'form-horizontal', | |
'button_class' => 'btn btn-primary contact-btn', | |
); | |
return $args; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ignore this line | |
/** | |
* This filter actually handles the login form, the password reset form, | |
* the change password form, and the new forgot username form. | |
* | |
* This makes the change to the label tag that the pluggable version | |
* changes at line 179. | |
* | |
* This is the one tricky piece of the process because there isn't | |
* currently a direct process of adding/changing a class in the | |
* label tag itself (at least in the login form), so you must use | |
* the php str_replace function to do a find/replace (that's the | |
* $old/$new part). | |
*/ | |
add_filter( 'wpmem_login_form_rows', 'my_login_form_rows', 10, 2 ); | |
function my_login_form_rows( $rows, $action ) { | |
// Set up replacement variables. | |
$old = '<label'; | |
$new = '<label class="col-sm-4 control-label" '; | |
// str_replace on the label tag to slip in custom class. | |
$rows[0]['label'] = str_replace( $old, $new, $rows[0]['label'] ); | |
$rows[1]['label'] = str_replace( $old, $new, $rows[1]['label'] ); | |
return $rows; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ignore this line | |
/** | |
* This handles the change at line 35 in wp-members-pluggable.php | |
* | |
* Note that the original script then comments out the filter application | |
* at line 45, nullifying the wpmem_restricted_msg filter. | |
*/ | |
add_filter( 'wpmem_restricted_msg', 'my_restricted_msg' ); | |
function my_restricted_msg( $str ) { | |
return '<h4>Sell Sheets | Art Files | Order Forms</h4>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment