Home Forums Plugin Support WP User Frontend (Free Version) Include custom taxonomy in notification

This topic is: resolved

This topic contains 2 replies, has 2 voices, and was last updated by  gpspake 5 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9971

    gpspake
    Participant
    Post count: 14

    In the Notification options, you can select %category% to display the selected categories. Is there a way to do the same thing with a custom taxonomy?

    #12887

    Tareq Hasan
    Keymaster
    Post count: 2831

    Hey George,

    Sorry I missed the topic at all. There is no currently filters available so you can't change it without modifying the code.

    #12899

    gpspake
    Participant
    Post count: 14

    Yeah, sorry I meant to jump in here and post this in case anyone is interested…

    This does require code modification but, if you really need it, it's fairly simple. Ideally, these options would be abstracted and there would be a filter but considering this is sort of a bonus feature in this plugin, it's not really necessary. In my example, the actual taxonomy could be abstracted (Kind of like the custom field option) but, since I only needed one custom taxonomy, I just hard coded it.

    Note – This is for 2.1.7 but I'm sure the same applies to 2.1.8

    To add custom taxonomies to the notification email, you just need to add a few lines to class/frontend-form-post.php

    In the prepare_mail_body function there is an array of options (assigned to $post_field_replace) with variables you should recognize from the notification page in the form builder (ex: %post_title%', ‘%post_content%', etc..).

    These variables correspond to the values set in the array below ($post_field_replace). It should be pretty clear how this works by looking at the code.

    So, all you really need to do is add ‘%taxonomy%' to the $post_field_replace array and add $this->pending_post_count( ‘mycustomtaxonomy' ) to the corresponding place in the $post_field_replace array.

    In the end it should look like this…

    $post_field_search = array( '%post_title%', '%post_content%', '%post_excerpt%', '%pending_post_count%' ,'%tags%', '%category%', '%taxonomy%',
        '%author%', '%sitename%', '%siteurl%', '%permalink%', '%editlink%' );
    
    $post_field_replace = array(
        $post->post_title,
        $post->post_content,
        $post->post_excerpt,
        $this->pending_post_count( 'mycustomtaxonomy' ),
        get_the_term_list( $post_id, 'post_tag', '', ', '),
        get_the_term_list( $post_id, 'category', '', ', '),
        get_the_term_list( $post_id, 'listserv', '', ', '),
        $user->display_name,
        get_bloginfo( 'name' ),
        home_url(),
        get_permalink( $post_id ),
        admin_url( 'post.php?action=edit&post=' . $post_id )
    );

    Obviously, this will work for other things as well as taxonomy too.
    Hope this helps…

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Include custom taxonomy in notification’ is closed to new replies.