BuddyPress BP_CORE_ADD_MESSAGE()为什么不触发?

时间:2014-05-07 作者:vimes1984

好的,我有下面的php,它运行正常,直到IF,但无论我做什么,我都无法让bp\\U核心消息在屏幕上激发,它只会给我保存的更改消息。。。为什么我做错了什么!

    function valid_postcode ($self) {
    $getFieldID = $self->field_id;
    $PostCodeFieldID = 23;
    $postcodecheck = $_POST[\'field_23\'];
 if ( $getFieldID == $PostCodeFieldID || $postcodecheck == \'\'){

        $GetValuePost = $self->value;

        $regex = \'/[a-z][0-9][a-z][- ]?[0-9][a-z][0-9]$/i\';  

    if(!preg_match($regex, $GetValuePost)) {

       bp_core_add_message( __( \'That Postcode  is invalid. Check the formatting and try again.\', \'buddypress\' ), \'error\' );

    }elseif (!isset($getFieldID)) {

       bp_core_add_message( __( \'You need to fill out the post code.\', \'buddypress\' ), \'error\' );

    }
  }

}
add_action( \'xprofile_data_before_save\', \'valid_postcode\', 1, 1 );

1 个回复
最合适的回答,由SO网友:Boone Gorges 整理而成

使用发布的邮件bp_core_add_message() 存储在cookie中,然后在\'template_notices\' 钩子(在当前页面加载或下一个页面加载上,以先到者为准)。您使用的模板很可能无法启动\'template_notices\'.

结束