Support Forum
Support › MB User Profile › Missing filter to allow devs to extend which screens to show on
As this plugin includes the functionality of MB Meta User, this is the exact same issue as this one:
https://support.metabox.io/topic/expanding-user-meta-to-work-with-other-post-types/
from 2019. Since there was no result from that I posted the solution in the thread as well as this public repo on Github: https://github.com/baden03/mb-user-meta
This issue for the MB User Profile plugin stems from the following function in src/UserFields.php:
public function hide_in_admin( $html, $field ) {
if ( ! is_admin() ) {
return $html;
}
$screen = get_current_screen();
if ( ! is_object( $screen ) || ! in_array( $screen->id, [ 'profile', 'user-edit', 'profile-network', 'user-edit-network' ], true ) ) {
return $html;
}
return in_array( $field['id'], $this->fields, true ) ? '' : $html;
}
As you can see the array of accepted screens only contains:
'profile', 'user-edit', 'profile-network', 'user-edit-network'
This makes it not possible to expand to more advanced user profiles. Therefor a filter would be appreciated.
$screen = get_current_screen();
$edit_screens = apply_filters( 'rwmb_user_edit_screens', array( 'profile', 'user-edit', 'profile-network', 'user-edit-network' ) );
if ( ! is_object( $screen ) || ! in_array( $screen->id, $edit_screens, true ) ) {
return $html;
}
return in_array( $field['id'], $this->fields, true ) ? '' : $html;
I would (as always) be happy to submit a pull request.
Update. Since this plugin actually does include 'mb-user-meta', this is actually exactly the same issue as posted back in 2019. In this case, the file is found under:
vendor > meta-box > mb-user-meta > src > MetaBox.php
The function:
public function is_edit_screen( $screen = null ) {
if ( ! is_admin() ) {
return false;
}
$screen = get_current_screen();
return in_array( $screen->id, ['profile', 'user-edit', 'profile-network', 'user-edit-network'], true );
}
should be updated to:
public function is_edit_screen( $screen = null ) {
if ( ! is_admin() ) {
return false;
}
$screen = get_current_screen();
// Allow edit screens to be expanded
$edit_screens = apply_filters( 'rwmb_user_edit_screens', [ 'profile', 'user-edit', 'profile-network', 'user-edit-network' ] );
return in_array( $screen->id, $edit_screens, true );
}
I see that the array was changed from array()
to []
... yet the filter was not added.