2015-02-12 209 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