• Resolved sandrasusin

    (@sandrasusin)


    Hi, i wonder if i can add a post admin link in first mail sent by user (the submission email). (just like %%POST_ADMIN_LINK%% in Toolset Cred.

    thanks

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    What would the admin link point to?

    Thread Starter sandrasusin

    (@sandrasusin)

    Hi,
    it would link to post edit.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    it would link to post edit.

    the submitted form saved post?

    That’s an interesting request. let me take a look and how to achieve this and get back to you.

    Thread Starter sandrasusin

    (@sandrasusin)

    Ok it’s really important.
    i’m waiting.
    Thank you.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    So I will add new mail tags in a future release.

    In the meantime, here is a possible solution to fix your urgent need,

    – insert a custom tag in your mail body, say [my-custom-link
    – next hook the action fired as the end of the mapping process to replace that tag with the admin link to the newly saved post.

    
    add_action('cf7_2_post_form_mapped_to_{$post_type}','add_link_to_mail_body');
    function add_link_to_mail_body( $post_id, $form_data, $cf7_key){
      if($cf7_key != 'my-custom-form') return;  //check the right form is being submitted.
      $link = wp_admin('post.php?post='.$post_id.'&action=edit');
      $wpcf7 = WPCF7_ContactForm :: get_current();
      $mail = $wpcf7->prop('mail') ;
      $mail['body'] = str_replace('[my-custom-link]', $link, $mail['body']);
      $wpcf7->set_properties( array("mail" => $mail)) ;
      return;
    }
    

    I haven’t tested it, do let me know this this works.

    Thread Starter sandrasusin

    (@sandrasusin)

    Hi, first of all – thank you!
    second – unfortunately the code doesn’t work.
    tried with changing the {$post_type} to the CPT slug and without changing it.
    both didn’t worked. ??
    is there anything else i need to do after inserting the code?

    Plugin Author Aurovrata Venet

    (@aurovrata)

    tried with changing the {$post_type} to the CPT slug

    indeed, this is what you need to do, however, the function only executes if the right form has been submitted. did you notice the first line of the function is a validation step?

    Thread Starter sandrasusin

    (@sandrasusin)

    tried it now, it is still doesn’t work and now it made an edit on the last post published instat making new post ??

    Plugin Author Aurovrata Venet

    (@aurovrata)

    now it made an edit on the last post published instat making new post

    I am not sure I follow.

    however, I realised I got the wrong function, its admin_url and not wp_admin, try this and change the 1st line validation to your form

    
    add_action('cf7_2_post_form_mapped_to_{$post_type}','add_link_to_mail_body');
    function add_link_to_mail_body( $post_id, $form_data, $cf7_key){
      if($cf7_key != 'my-custom-form') return;  //check the right form is being submitted.
      $link = admin_url('post.php?post='.$post_id.'&action=edit');
      $wpcf7 = WPCF7_ContactForm :: get_current();
      $mail = $wpcf7->prop('mail') ;
      $mail['body'] = str_replace('[my-custom-link]', $link, $mail['body']);
      $wpcf7->set_properties( array("mail" => $mail)) ;
      return;
    }
    
    
    Plugin Author Aurovrata Venet

    (@aurovrata)

    if it is still not working, you’ll need to debug the code to see if the link and the mail body are being properly updated.

    Thread Starter sandrasusin

    (@sandrasusin)

    can we continue in email? i want to send you some info and don’t want it public…

    Thread Starter sandrasusin

    (@sandrasusin)

    now the sending is stuck. i received the new post in admin, but no success message or email.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    I just released a new version with dedicated mail tags to do this.

    Upgrade and read FAQ #24

    Thread Starter sandrasusin

    (@sandrasusin)

    Thank you so much!!! it works perfectly!

    now I have only one more thing for everything would be perfect:
    I’m using the

    function dynamic_select_list( $tag ) {
        // Only run on select lists
        if( 'select' !== $tag['type'] && ('select*' !== $tag['type']) ) {
            return $tag;
        } else if ( empty( $tag['options'] ) ) {
            return $tag;
        }
        $term_args = array();
        // Loop thorugh options to look for our custom options
        foreach( $tag['options'] as $option ) {
            $matches = explode( ':', $option );
            if( ! empty( $matches ) ) {
                switch( $matches[0] ) {
                    case 'taxonomy':
                        $term_args['taxonomy'] = $matches[1];
                        break;
                    case 'parent':
                        $term_args['parent'] = intval( $matches[1] );
                        break;
                }
            }
        }
        // Ensure we have a term arguments to work with
        if( empty( $term_args ) ) {
            return $tag;
        }
        // Merge dynamic arguments with static arguments
        $term_args = array_merge( $term_args, array(
            'hide_empty' => false,
        ) );
        $terms = get_terms( $term_args );
        // Add terms to values
        if( ! empty( $terms ) && ! is_wp_error( $term_args ) ) {
            foreach( $terms as $term ) {
                $tag['values'][] = $term->name;
            }
        }
        return $tag;
    }
    add_filter( 'wpcf7_form_tag', 'dynamic_select_list', 10 );

    function to get select of my custom taxonomy, and it working great, the only problem them in the mail i get – it output the tax ID instead its name.. how can i fix it?

    thank you so much!!

    Plugin Author Aurovrata Venet

    (@aurovrata)

    For cf7 plugin support you need to post on the cf7 forum.

    However cf7 plugin is poorly designed for this kind of customisations. This is the reason I wrote the Smart Grid extension for cf7. It has a dynamic drop-down tag built in which you can populate with existing taxonomy or even posts.

    It is fully compatible with this plugin.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Post admin link in cf7 mail’ is closed to new replies.