Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wp-user-manager/4ac0e52e9a4e8e43696bd05c3006d3be to your computer and use it in GitHub Desktop.
Save wp-user-manager/4ac0e52e9a4e8e43696bd05c3006d3be to your computer and use it in GitHub Desktop.
WP User Manager - Remove nickname validation from the account form
<?php
/**
* Remove an object filter.
*
* @param string $tag Hook name.
* @param string $class Class name. Use 'Closure' for anonymous functions.
* @param string|void $method Method name. Leave empty for anonymous functions.
* @param string|int|void $priority Priority
* @return void
*/
function wpum_remove_object_filter( $tag, $class, $method = NULL, $priority = NULL ) {
global $wp_version;
$new_wp_filter_struct = false;
$filters = $GLOBALS['wp_filter'][ $tag ];
if ( empty ( $filters ) ) {
return;
}
if (version_compare( $wp_version, '4.7', '>=' ) && isset($filters->callbacks)) { // new 'wp_filter' structure (WP >= 4.7)
$filters = $filters->callbacks;
$new_wp_filter_struct = true;
}
foreach ( $filters as $p => $filter ) {
if ( ! is_null($priority) && ( (int) $priority !== (int) $p ) ) continue;
$remove = FALSE;
foreach ( $filter as $identifier => $function ) {
$function = $function['function'];
if (
is_array( $function )
&& (
is_a( $function[0], $class )
|| ( is_array( $function ) && $function[0] === $class )
)
) {
$remove = ( $method && ( $method === $function[1] ) );
} elseif ( $function instanceof Closure && $class === 'Closure' ) {
$remove = TRUE;
}
if ( $remove ) {
if ($new_wp_filter_struct) {
unset( $GLOBALS['wp_filter'][$tag]->callbacks[$p][$identifier] );
if (count($GLOBALS['wp_filter'][$tag]->callbacks[$p]) == 0) {
unset($GLOBALS['wp_filter'][$tag]->callbacks[$p]);
}
}
else {
unset( $GLOBALS['wp_filter'][$tag][$p][$identifier] );
}
}
}
}
}
add_action( 'init', function() {
if ( ! is_user_logged_in() ) {
return;
}
wpum_remove_object_filter( 'submit_wpum_form_validate_fields', 'WPUM_Form_Profile', 'validate_nickname', 10 );
}, 20 );
@wp-user-manager
Copy link
Author

Save this file to your /wp-content/mu-plugins/ directory (you might need to create the mu-plugins directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment