Post admin link in cf7 mail
-
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
-
What would the admin link point to?
Hi,
it would link to post edit.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.
Ok it’s really important.
i’m waiting.
Thank you.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.
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?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?
tried it now, it is still doesn’t work and now it made an edit on the last post published instat making new post ??
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 notwp_admin
, try this and change the 1st line validation to your formadd_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; }
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.
can we continue in email? i want to send you some info and don’t want it public…
now the sending is stuck. i received the new post in admin, but no success message or email.
I just released a new version with dedicated mail tags to do this.
Upgrade and read FAQ #24
Thank you so much!!! it works perfectly!
now I have only one more thing for everything would be perfect:
I’m using thefunction 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!!
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.
- The topic ‘Post admin link in cf7 mail’ is closed to new replies.