cvc
cvc

Reputation: 37

replace Wordpress plugin function using filter

I have installed a Wordpress plugin (Profile Builder) which includes this instruction for filtering a function:

Filter 'wppb_signup_user_notification_filter' to bypass this function or
replace it with your own notification behavior.  

Indeed, I want to replace the function which follows this instruction with my own variant which changes the text of the emails being sent. The original function starts out like this:

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;
...
}

I duplicated that function in my own plugin and renamed it:

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)
}

I am now having difficulty with the remove_filter and add_filter portion of this process. I've tried:

remove_filter(  'wppb_signup_user_notification_filter', 'wppd_signup_user_notification');
add_filter(  'wppb_signup_user_notification_filter', 'cvc_signup_user_notification');

With this result:

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

And this attempt:

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);

Produces this result:

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

I've tried adding the filter without removing the original, which results in the same 3 errors (and the original function is still apparently being used)

Can someone point me in the right direction for achieving the goal of replacing the original function with my own with modified email notifications.

Any guidance would be appreciated. Thanks.

Upvotes: 0

Views: 1249

Answers (1)

vrajesh
vrajesh

Reputation: 2942

Try this: I added add_filter() function with arguments..i made no changes in plugins file 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);

Upvotes: 1

Related Questions