2015-02-12 164 views
0

我已经安装了一个WordPress的插件(资料创建),其中包括该指令用于过滤函数替换WordPress的插件功能:使用过滤器

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 

我试着加入过滤器没有删除原来的,哪个r在相同的3个错误esults(和原来的功能仍然能够被使用)

有人点我在正确的方向实现我自己的改良电子邮件通知替换原有功能的目标。

任何指导,将不胜感激。 谢谢。

+0

没有改变我找到了答案。我需要明确指定add_filter的参数优先级和数量:'add_filter('wppb_signup_user_notification_filter','cvc_signup_user_notification',10,4);' – cvc 2015-02-12 12:55:47

+0

我说得太快了。虽然我的新功能正在工作,没有缺少参数错误发生,而我得到我的自定义文本的电子邮件,我也从原来的功能接收重复的电子邮件。所以remove_filter行不起作用。建议? – cvc 2015-02-12 13:14:51

回答

1

试试这个:我添加add_filter()功能与arguments..i取得了插件文件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 = '[email protected]' . $_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); 
+0

感谢您的努力。看起来你所做的和我所做的之间的区别在于:a)你添加了',10'的优先级,并且将add_filter放在函数之后而不是之前。我尝试了你的方式,但结果仍然是第2条和第3条缺失的警告。此外,该功能确实发送了电子邮件,但它没有包含来自我的功能的任何文本更改。它仍在使用原始功能。 – cvc 2015-02-12 12:42:17

+0

其实,你帮助我指出正确的方向找到答案。在原始问题中看到我的评论。 – cvc 2015-02-12 12:55:31