Created
May 17, 2022 09:24
-
-
Save wp-user-manager/4ac0e52e9a4e8e43696bd05c3006d3be to your computer and use it in GitHub Desktop.
WP User Manager - Remove nickname validation from the account form
This file contains hidden or 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 | |
/** | |
* 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save this file to your /wp-content/mu-plugins/ directory (you might need to create the mu-plugins directory).