我安装了一个Wordpress插件(Profile Builder),其中包含用于过滤功能的指令:
Filter 'wppb_signup_user_notification_filter' to bypass this function or
replace it with your own notification behavior.
实际上,我想用我自己的变量替换遵循此指令的函数,该变量会更改正在发送的电子邮件的文本。原始函数开头是这样的:
function wppb_signup_user_notification( $user, $user_email, $activation_key, $meta = '' ) {
if ( !apply_filters( 'wppb_signup_user_notification_filter', $user, $user_email, $activation_key, $meta ) )
return false;
...
}
我在我自己的插件中复制了该函数并重命名为:
function cvc_signup_user_notification( $user, $user_email, $activation_key, $meta = '' ) {
...(NOTE: I left out the if(!apply_filters conditional as it caused a server 500 error)
}
我现在对此过程的remove_filter和add_filter部分有困难。我试过了:
remove_filter( 'wppb_signup_user_notification_filter', 'wppd_signup_user_notification');
add_filter( 'wppb_signup_user_notification_filter', 'cvc_signup_user_notification');
结果如下:
Warning: Missing argument 2 for cvc_signup_user_notification() in /home/ccarlv5/public_html/homebaseinc/wp-content/plugins/cvc-profile-builder-homebase-emails/index.php on line 306
Warning: Missing argument 3 for cvc_signup_user_notification() in /home/ccarlv5/public_html/homebaseinc/wp-content/plugins/cvc-profile-builder-homebase-emails/index.php on line 306
这次尝试:
remove_filter( 'wppb_signup_user_notification_filter', 'wppd_signup_user_notification',$user, $user_email, $activation_key, $meta);
add_filter( 'wppb_signup_user_notification_filter', 'cvc_signup_user_notification',$user, $user_email, $activation_key, $meta);
产生这个结果:
Warning: Missing argument 1 for cvc_signup_user_notification() in /home/ccarlv5/public_html/homebaseinc/wp-content/plugins/cvc-profile-builder-homebase-emails/index.php on line 306
Warning: Missing argument 2 for cvc_signup_user_notification() in /home/ccarlv5/public_html/homebaseinc/wp-content/plugins/cvc-profile-builder-homebase-emails/index.php on line 306
Warning: Missing argument 3 for cvc_signup_user_notification() in /home/ccarlv5/public_html/homebaseinc/wp-content/plugins/cvc-profile-builder-homebase-emails/index.php on line 306
我尝试在不删除原件的情况下添加过滤器,导致相同的3个错误(原来的功能仍在使用中)
有人可以指出我正确的方向,以实现用修改后的电子邮件通知替换我自己的原始功能的目标。
任何指导都将不胜感激。 感谢。
答案 0 :(得分:1)
试试这个:我在参数中添加了add_filter()
函数。在插件文件中没有任何变化thx
function my_function_name($user, $user_email, $activation_key, $meta = '' ){
$wppb_general_settings = get_option( 'wppb_general_settings' );
$admin_email = get_site_option( 'admin_email' );
if ( $admin_email == '' )
$admin_email = 'support@' . $_SERVER['SERVER_NAME'];
$from_name = apply_filters ( 'wppb_signup_user_notification_email_from_field', get_bloginfo( 'name' ) );
$message_headers = apply_filters ( 'wppb_signup_user_notification_from', "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n" );
$registration_page_url = ( ( isset( $wppb_general_settings['activationLandingPage'] ) && ( trim( $wppb_general_settings['activationLandingPage'] ) != '' ) ) ? add_query_arg( array('activation_key' => $activation_key ), get_permalink( $wppb_general_settings['activationLandingPage'] ) ) : 'not_set' );
if ( $registration_page_url == 'not_set' ){
global $post;
if( !empty( $post->ID ) )
$permalink = get_permalink( $post->ID );
else
$permalink = get_bloginfo( 'url' );
if( !empty( $post->post_content ) )
$post_content = $post->post_content;
else
$post_content = '';
$registration_page_url = ( ( strpos( $post_content, '[wppb-register' ) !== false ) ? add_query_arg( array('activation_key' => $activation_key ), $permalink ) : add_query_arg( array('activation_key' => $activation_key ), get_bloginfo( 'url' ) ) );
}
$subject = sprintf( __( '[%1$s] Activate %2$s', 'profilebuilder'), $from_name, $user );
$subject = apply_filters( 'wppb_signup_user_notification_email_subject', $subject, $user_email, $user, $activation_key, $registration_page_url, $meta, $from_name, 'wppb_user_emailc_registr_w_email_confirm_email_subject' );
$message = sprintf( __( "To activate your user, please click the following link:\n\n%s%s%s\n\nAfter you activate it you will receive yet *another email* with your login.", "profilebuilder" ), '<a href="'.$registration_page_url.'">', $registration_page_url, '</a>.' );
$message = apply_filters( 'wppb_signup_user_notification_email_content', $message, $user_email, $user, $activation_key, $registration_page_url, $meta, $from_name, 'wppb_user_emailc_registr_w_email_confirm_email_content' );
wppb_mail( $user_email, $subject, $message, $from_name, '', $user, '', $user_email, 'register_w_email_confirmation', $registration_page_url, $meta );
return true;
}
add_filter('wppb_signup_user_notification_filter','my_function_name', 10);