MarketPress Custom Placeholder

How can I create custom Placeholder with custom output for MarketPress notification emails without modifying the plugin core files?

  • Vaughan

    Hi Pat

    What kind of placeholders are you wanting to replace? I mean, can you give me an example of what you're wanting to accomplish?

    It could be possible by replacing mp_send_mail() function itself as it's a template function in Marketpress that checks if the function_exists().

    So you could perhaps just add the function to your theme functions.php or a mu-plugin

    Something like below for example:

    function mp_send_email( $email, $subject, $msg, $attachments = array() ) {
        $placeholders = array(
                'PLACEHOLDER1',
                'PLACEHOLDER2',
                'PLACEHOLDER3',
        );
    
        $replacements = array(
                'simple text replacement', // PLACEHOLDER1
                custom_function(), // PLACEHOLDER2
                custom_function_two(), // PLACEHOLDER3
        );
    
        $msg = str_replace($placeholders, $replacements, $msg);
    
        return MP_Mailer::get_instance()->send( $email, $subject, $msg, $attachments );
    
    }
    
    function custom_function() {
        // do something & return the result
    
        $content = date('Y-m-d');
    
        return $content;
    }
    
    function custom_function_two() {
        // do something & return the result
    
        $content = date('H:i');
    
        return $content;
    }

    In this Case say we have a notification email with content:

    This is a sample email that contains some placeholders below:

    PLACEHOLDER1

    The date is: PLACEHOLDER2

    The time is: PLACEHOLDER3

    Using the above functions the email would be changed to:

    This is a sample email that contains some placeholders below:

    simple text replacement

    The date is: 2018-06-01

    The time is: 04:16

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.