Send email to WordPress post author and CF7
Today I will tell you how I coped with one interesting task.. The client had an article with several authors and each author had to receive letters from their own articles. To solve this problem, we registered a separate account for each author and indicated the authors' emails.
Next was the task in the popular plugin Contact form 7 ( CF7 ) add email of the author of the current article or from the author's page. After not much more brainstorming, a dozen cups of coffee drunk and google searches i found the solution. As always, the problem was solved quite simply., like everything in wordpress. To display the dynamic address of the contact form plugin, I used an additional plugin Contact Form 7 Dynamic Text Extension, with it, I was able to easily pass a dynamic value to one of the form fields.
Consider the steps of sending emails to the author of the post using the Contact Form plugin 7 (Cf7)
- Installing Contact Form plugins 7 и Contact Form 7 Dynamic Text Extension and create a new contact form with CF7 plugin.
- Add any required fields to the form and be sure to add a hidden dynamic field as shown below. Name the dynamic field custom-post-author-email-short-code and in the Dynamic value field add the name of the short code CUSTOM_POST_AUTHOR_EMAIL!
- Now click on the Mail tab of the CF7 form and fill in the "Email to" field using the shortcode: [custom-post-author-email-shortcode]. With this setting, we achieve, to have our contact form send a message to our dynamically generated email address.
- Registrable shortcode, to get the email address of the current post author. We are creating a new shortcode for this job using the WordPress Shortcode API! You can put the code in a new plugin or in your functions.php file:
1 2 3 4 5 6 7 8 9 10 11 12 |
/** * Отправляем письмо автору поста на его email. */ function custom_get_post_author_email($atts){ $value = ''; if(get_the_author_meta( 'user_email' )) { $value = get_the_author_meta( 'user_email' ); } return $value; } add_shortcode(CUSTOM_POST_AUTHOR_EMAIL, custom_get_post_author_email); |
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.