覆盖我的插件中的函数

时间:2014-07-10 作者:Nomi

有谁能指导我如何重写插件中的以下函数吗。我知道如何使用add\\u action,但在buddypress插件中找不到该函数的add\\u action。它使用do\\u操作,我不知道如何使其工作

function groups_screen_group_request_membership() {
global $bp;

if ( !is_user_logged_in() )
    return false;

$bp = buddypress();

if ( \'private\' != $bp->groups->current_group->status )
    return false;

// If the user is already invited, accept invitation
if ( groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
    if ( groups_accept_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) )
        bp_core_add_message( __( \'Group invite accepted\', \'buddypress\' ) );
    else
        bp_core_add_message( __( \'There was an error accepting the group invitation, please try again.\', \'buddypress\' ), \'error\' );
    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
}

// If the user has submitted a request, send it.
if ( isset( $_POST[\'group-request-send\']) ) {

    // Check the nonce
    if ( !check_admin_referer( \'groups_request_membership\' ) )
        return false;

    if ( !groups_send_membership_request( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
        bp_core_add_message( __( \'There was an error sending your group membership request, please try again.\', \'buddypress\' ), \'error\' );
    } else {
        bp_core_add_message( __( \'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.\', \'buddypress\' ) );
    }
    bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
}

do_action( \'groups_screen_group_request_membership\', $bp->groups->current_group->id );

bp_core_load_template( apply_filters( \'groups_template_group_request_membership\', \'groups/single/home\' ) );
}

1 个回复
SO网友:Domain

在WordPress中,“do\\u action”用于在插件中添加一个动作挂钩,然后可以使用该挂钩将我们自己的函数与插件挂钩。

查看Codex了解更多详细信息:Hooks API WordPress

要添加自己的函数,必须执行以下操作:

add_action(\'groups_screen_group_request_membership\', \'your_function_callback\');

function your_function_callback($id){

    //here id can be used to get the id of current group
   //write your code here

}
如果您有任何疑问,请随时询问。

结束

相关推荐

强制将BuddyPress组设置为私有

我想让群创建者没有创建公共或隐藏群的选项。所有组都应该是私有的。这样人们仍然可以看到这些团体,但必须被邀请或要求加入。最简单的方法是隐藏单选按钮(见附图)。但我想使用插件或php来实现它。那么,我如何才能强制buddypress将每个组设置为私有?