Expanding User Meta to work with other post types

Support MB User Meta Expanding User Meta to work with other post types

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #14471
    pluginovenpluginoven
    Participant

    I am using a plugin to create multiple tabs in the user profiles. Since these tabs are not on the 'profile' or 'user-edit' pages, any meta_box that has type => 'user' will not render.

    Here are the changes so that User Meta will work with other plugins and on any post_type:

    File: inc/class-mb-user-meta-box.php

    appended add_meta_boxes to the object_hooks function:

    protected function object_hooks() {
        ...
        // Allow user meta fields to be used by other plugins and post types.
        add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
        ...
    }

    add a filter to expand valid edit_screens

    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', array( 'profile', 'user-edit', 'profile-network', 'user-edit-network' ) );
        return in_array( $screen->id, $edit_screens, true );
    }

    do not limit get_current_user_id to user-edit and profile pages:

    public static function get_current_user_id() {
        if ( ! is_admin() ) {
            return false;
        }
    
        if( !empty( $_REQUEST['user_id'] )){
            return absint( $_REQUEST['user_id'] );
        }
        else if( get_current_user_id() ){
            return get_current_user_id();
        }
    
        return false;
    }

    I'll submit a pull request on bitbucket if you like to include these useful changes in a future release.

    #29369
    pluginovenpluginoven
    Participant

    It's been two years, and every time this plugin is updated, I have to go in and manually re-add this filter. @Tran - would you please consider granting me access to the github repo for this plugin so I can fork and submit a proper pull request for this change? Thank you.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.