• Resolved Lab41

    (@lab41)


    When I use this snippet

    remove_filter( 'mandrill_payload', array($wp_better_emails, 'wpmandrill_compatibility') );
    
    // do your own email processing
    add_filter( 'mandrill_payload', 'wpbe_wpmandrill_compatibility' );
    function wpbe_wpmandrill_compatibility( $message ) {
    
        global $wp_better_emails;
    
        // make sure you have the %content% tag in the template
        if ( $wp_better_emails->check_template() ) {
            // clean < and > around text links in WP 3.1
            $message['html'] = $wp_better_emails->esc_textlinks( $message['html'] );
            // make links out of URLs
            $message['html'] = make_clickable( $message['html'] );
            // set template
            $message['html'] = $wp_better_emails->set_email_template( $message['html'] );
            // replace variables
            $message['html'] = apply_filters( 'wpbe_html_body', $wp_better_emails->template_vars_replacement( $message['html'] ) );
        }
    
        return $message;
    }

    In my functions it works. But when I use it in your plugin it doesn’t work.

    What am I missing?

    https://wordpress.org/plugins/code-snippets/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Quite possibly because snippets run at an earlier point in the WordPress load order then functions.php code. Try wrapping your remove_filter call in a function:

    add_action( 'init', 'wpbe_wpmandrill_compatibility_init' );
    
    function wpbe_wpmandrill_compatibility_init() {
    	remove_filter( 'mandrill_payload', array($wp_better_emails, 'wpmandrill_compatibility') );
    
    	// do your own email processing
    	add_filter( 'mandrill_payload', 'wpbe_wpmandrill_compatibility' );
    }
    
    function wpbe_wpmandrill_compatibility( $message ) {
    
        global $wp_better_emails;
    
        // make sure you have the %content% tag in the template
        if ( $wp_better_emails->check_template() ) {
            // clean < and > around text links in WP 3.1
            $message['html'] = $wp_better_emails->esc_textlinks( $message['html'] );
            // make links out of URLs
            $message['html'] = make_clickable( $message['html'] );
            // set template
            $message['html'] = $wp_better_emails->set_email_template( $message['html'] );
            // replace variables
            $message['html'] = apply_filters( 'wpbe_html_body', $wp_better_emails->template_vars_replacement( $message['html'] ) );
        }
    
        return $message;
    }
    Thread Starter Lab41

    (@lab41)

    Hi

    I’ve tried that but it breaks the function.
    http://screencast.com/t/8NbHMtsnF2iZ

    It now adds a duplicate header area to my emails.

    Alex

    Plugin Author Shea Bunge

    (@bungeshea)

    I forgot to add global $wp_better_emails; to the first function. Try this code instead:

    add_action( 'init', 'wpbe_wpmandrill_compatibility_init' );
    
    function wpbe_wpmandrill_compatibility_init() {
    	global $wp_better_emails;
    
    	remove_filter( 'mandrill_payload', array($wp_better_emails, 'wpmandrill_compatibility') );
    
    	// do your own email processing
    	add_filter( 'mandrill_payload', 'wpbe_wpmandrill_compatibility' );
    }
    
    function wpbe_wpmandrill_compatibility( $message ) {
    
        global $wp_better_emails;
    
        // make sure you have the %content% tag in the template
        if ( $wp_better_emails->check_template() ) {
            // clean < and > around text links in WP 3.1
            $message['html'] = $wp_better_emails->esc_textlinks( $message['html'] );
            // make links out of URLs
            $message['html'] = make_clickable( $message['html'] );
            // set template
            $message['html'] = $wp_better_emails->set_email_template( $message['html'] );
            // replace variables
            $message['html'] = apply_filters( 'wpbe_html_body', $wp_better_emails->template_vars_replacement( $message['html'] ) );
        }
    
        return $message;
    }

    Also, make sure that you don’t have this snippet in your functions file as well as in the Code Snippets area, just in case.

    Thread Starter Lab41

    (@lab41)

    Perfect!

    Many Thanks!!!

    Thread Starter Lab41

    (@lab41)

    Awesome1

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Snippet Plugin Not Working’ is closed to new replies.