Sunday, January 8, 2023
HomeWordPress DevelopmentHow one can appropriately override a filter?

How one can appropriately override a filter?


perform _bp_enforce_bp_moderate_cap_for_admins( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
    // Bail if not checking the 'bp_moderate' cap.
    if ( 'bp_moderate' !== $cap ) {
        return $caps;
    }

    // Bail if BuddyPress isn't community activated.
    if ( bp_is_network_activated() ) {
        return $caps;
    }

    // By no means belief inactive customers.
    if ( bp_is_user_inactive( $user_id ) ) {
        return $caps;
    }

    // Solely customers that may 'manage_options' on this website can 'bp_moderate'.
    return array( 'manage_options' );
}
add_filter( 'map_meta_cap', '_bp_enforce_bp_moderate_cap_for_admins', 10, 4 );

Within the above code, the potential "bp_moderate" is mapped to "manage_options". This implies any motion that requires "bp_moderate" can be equal to requiring "manage_options". I’ve already given the consumer "bp_moderate" however that will not enable him to really average as a result of he would not have "manage_options". Now "manage_options" is just too highly effective, with it enabled, the consumer can do many issues on the backend. So I definitely cannot give "manage_options" to him. It will work for me if I may merely remark out the above code, however since that code resides within the plugin’s core file, so I am unable to try this. The one choice left for me is to put in writing my very own perform to nullify what the above perform has finished when the present consumer is the consumer I wish to grant the privilege to average:

perform allow_daniel_edit( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
    if ($user_id == 59) {
        return $caps;
    }
    // Bail if not checking the 'bp_moderate' cap.
    if ( 'bp_moderate' !== $cap ) {
        return $caps;
    }

    // Bail if BuddyPress isn't community activated.
    if ( bp_is_network_activated() ) {
        return $caps;
    }

    // By no means belief inactive customers.
    if ( bp_is_user_inactive( $user_id ) ) {
        return $caps;
    }

    // Solely customers that may 'manage_options' on this website can 'bp_moderate'.
    return array( 'manage_options' );
}
add_filter( 'map_meta_cap', 'allow_daniel_edit', 999, 4 );

However this did not work, as a result of by the point my perform executes, the $caps has been altered by the earlier code and turns into "manage_options". So what needs to be the appropriate means to do that?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments