Custom notification event in Gravity forms is not attaching PDF - wordpress

I am using Gravity forms with PDF extension.
I have User notification with event "Form is submitted". In this case, everything works fine, email comes and attachment is there.
But I have created custom event for "User notification" like so:
add_filter( 'gform_notification_events', function( $events ) {
$events['custom_status'] = __( 'Custom status' );
return $events;
} );
But now, email comes, but WITHOUT attachment. Do I have to programmatically tell Gravity forms to attach PDF also on custom events ?

Related

Request method of wp setting and option api

I am building a plugin. For rendering the menu page both Option API & Setting API are used. Below is my callback function for add_menu_page()
<?php
//Calback function for add menu page
function render_newsletter_admin() {
if(!current_user_can( 'manage_options' )){
return;
}
if($_SERVER["REQUEST_METHOD"]=="GET"){
add_settings_error( 'newsletter', 'newsletter', __( 'Settings Saved', 'victory' ), 'success' );
settings_errors( );
}
?>
<div class="wrap">
<form action="options.php" method="post">
<?php
// output security fields for the registered setting "wporg"
settings_fields( 'newsletter' );
// output setting sections and their fields
// (sections are registered for "wporg", each field is registered to a specific section)
do_settings_sections( 'newsletter' );
// output save settings button
submit_button( 'Save Settings' );
?>
</form>
</div>
<?php
}
Notice that method attribute of the form set to POST but to add setting error $_SERVER["REQUEST_METHOD"]=="GET" is being checked and it is working. Shouldn't it be checked against POST?
Shouldn't it be checked against POST?
It's checked against GET instead of POST because the form is being submitted to and handled by options.php (or more precisely, wp-admin/options.php), and after the submission is processed, WordPress will redirect the user back to the origin of the submission which is the menu page having that form. Therefore the request method would then be GET.
Illustration of how the request method changed (from GET to POST then back to GET)
User landed on the menu page (the request method is GET).
Then he/she submitted the form.
The browser submits the form to options.php, using the POST method.
Now on the options.php page, the request method is POST.
And after the form submission is processed, WordPress sends the user back to the menu/form page.
Now on the menu page, the request method is GET because the above redirect uses that method.
Relevant code in wp-admin/options.php
So at the top in wp-admin/options.php, it says...
/**
* Options Management Administration Screen.
*
* If accessed directly in a browser this page shows a list of all saved options
* along with editable fields for their values. Serialized data is not supported
* and there is no way to remove options via this page. It is not linked to from
* anywhere else in the admin.
*
* This file is also the target of the forms in core and custom options pages
* that use the Settings API. In this case it saves the new option values
* and returns the user to their page of origin.
*
* #package WordPress
* #subpackage Administration
*/
And on lines 339-341 (https://core.trac.wordpress.org/browser/tags/5.8/src/wp-admin/options.php#L339):
// Redirect back to the settings page that was submitted.
$goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
wp_redirect( $goback );
And if you look at the "complete example" in the plugin developer handbook, it's actually also checking against GET whereby add_settings_error() is called only if $_GET['settings-updated'] is set:
// add error/update messages
// check if the user have submitted the settings
// WordPress will add the "settings-updated" $_GET parameter to the url
if ( isset( $_GET['settings-updated'] ) ) {
// add settings saved message with the class of "updated"
add_settings_error( 'wporg_messages', 'wporg_message', __( 'Settings Saved', 'wporg' ), 'updated' );
}
// show error/update messages
settings_errors( 'wporg_messages' );
Also, you might want to call settings_errors() outside the if (like above), and pass newsletter as the first parameter for the function, i.e. do settings_errors( 'newsletter' ).

Reset Password Email Template Wordpress

I have Requirement to change the reset password email template, i have checked the woocommerece email settings and it is on for the reset email from there, but issue is when user request to reset the password it is generating email from there, but using the email content form Wordpress core File
wp-include > user.php
attached it is the screenshot as well.
What i have to do it to remove following section
Regards,
All at ###SITENAME###
So how i can achieve it and if there is any possibilities to enable the Woocommerece template somehow so can directly copy template in my child theme and customize it there?
You can use password_change_email filter for customizing text.
add_filter( 'password_change_email', 'change_password_mail_message', 10, 3 );
function change_password_mail_message(
$pass_change_mail,
$user,
$userdata
) {
$new_message_txt = __( 'Your Text' );
$pass_change_mail[ 'message' ] = $new_message_txt;
return $pass_change_mail;
}

WP / Elementor Intercept Form and Redirect with Data

I have a form built in Elementor that I am looking to intercep, process the data and forward onto a third party then subsequently show the data on a "confirm" card.
I am able to build this whole process as a single page, setting each as display none with CSS then showing / hiding with JS as I receive AJAX responses. This isn't ideal as it breaks with JS turned off.
I haven't been able to find the right Elementor hook and way to populate a new page with PHP, has anyone had experience with this?
There are a few methods to POST data to another url from an Elementor web form.
One is using many of the API integrations such as Mailchimp, ActiveCampaign, Zapier etc. (see https://docs.elementor.com/article/281-form-faq) and (https://docs.elementor.com/category/405-integrations)
Another (very limited method) is by using the form's Action after Submit and choosing "redirect" and then using each field's short code as individual data strings in the url such as:
mysite.com/thank-you?fname=[field id="fname"]&lname=[field id="lname"]
You can even build your /thank-you/ page in Elementor to GET that data and populate Elementor elements such as text, title, links etc with the form field data. For example, I could drop a text element on the /thank-you/ page and choose dynamic instead of typing in the text area and from the dynamic drop down, choose "request parameter" and for the "type" choose GET and for the param name use your unique url keys such as fname, lname etc. You can even set prefix, suffix and even fallback text along with it.
Lastly, here is a write up on how to back end code passing data externally (https://developers.elementor.com/forms-api/#Form_New_Record_Action).
// A send custom WebHook
add_action( 'elementor_pro/forms/new_record', function( $record, $handler ) {
//make sure its our form
$form_name = $record->get_form_settings( 'form_name' );
// Replace MY_FORM_NAME with the name you gave your form
if ( 'MY_FORM_NAME' !== $form_name ) {
return;
}
$raw_fields = $record->get( 'fields' );
$fields = [];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field['value'];
}
// Replace HTTP://YOUR_WEBHOOK_URL with the actuall URL you want to post the form to
wp_remote_post( 'HTTP://YOUR_WEBHOOK_URL', [
'body' => $fields,
]);
}, 10, 2 );
And a thread with many more examples integrating with different APIs using that template as a primer (https://github.com/elementor/elementor/issues/2397)

Send an Email and Download a PDF on click of Contact Form 7 Submit button

I have a contact form in my Wordpress website. In that I have three fields Name, Email and Mobile, and a button called Submit. When the user fills all the fields and click on Submit button an email should send which can possible with Contact From 7 plugin.
But challenge here is I need to make the user download a PDF also, when he clicks on Submit button upon filling all the fields.'
How can I achieve this in Wordpress?
You can use the wpcf7_mail_sent hook provided by Contact form 7 like this:
add_action('wpcf7_mail_sent', function ($cf) {
// Run code after the email has been sent
});
This link: https://contactform7.com/2017/06/07/on-sent-ok-is-deprecated/ also describes another way:
add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer()
{ ?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event )
{
//Write a javascript code to download the file.
} , false );
</script>
<?php
}
Since the on_sent_ok has been deprecated, here is an example you could use as inspiration.
I had the similar need to add a download CTA after the content of all case studies of a website, but "in exchange" of user's data for:
display a CF7 form on your page, I had the same one on all case studies post type single which I hooked after the content
find a way to get the wanted PDF url for people to download, as for me all case studies have a different PDF, I simply added an ACF field, filtered on PDF only, which returns the file url
based on CF7 Dom events, choose the action you prefer to make the dowload happens, as I am not sending any confirmation email, I prefer working on the wpcf7submit event. Note that wpcf7submit event is fired only if the form has been validated
So the code looks like this:
<?php
// For simplicity, using an anonymous functions
add_action( 'wp_print_footer_scripts', function () {
// Check the wanted singular post type loading
if ( is_admin() || ! is_singular( 'case-study' ) ) {
return;
}
// Check if the ACF PDF field is not empty for use
$pdf_link = get_field( 'pdf' );
if ( empty( $pdf_link ) ) {
return;
}
// Hook on the "wpcf7submit" CF7 Dom event to force the download
printf( "<script>document.addEventListener( 'wpcf7submit', function( event ) { window.open('%s'); }, false );</script>", $pdf_link );
} );

Woocommerce New Customer Admin Notification Email

I am building an ecommerce site using Wordpress and Woocommerce. I need the site to send out a notification email to the site administrator when a new customer account is registered. I thought this functionality would be built into Woocommerce since it uses the Wordpress user account structure and Wordpress sends new user notifications, but it doesn't appear to be. Does anyone know of a plugin or a function I can use to add this functionality? Thanks!
I'm assuming that you are using html inside emails. If you are using plain text the procedure is similar.
You need to override the woocommerce template structure. Here you can find how: http://docs.woothemes.com/document/template-structure/.
Actually the only file you need to override is your_template_directory/woocommerce/emails/customer-new-account.php.
At the end of this file add this line of code:
<?php do_action( 'new_customer_registered', $user_login ); ?>
In functions.php add this:
function new_customer_registered_send_email_admin($user_login) {
ob_start();
do_action('woocommerce_email_header', 'New customer registered');
$email_header = ob_get_clean();
ob_start();
do_action('woocommerce_email_footer');
$email_footer = ob_get_clean();
woocommerce_mail(
get_bloginfo('admin_email'),
get_bloginfo('name').' - New customer registered',
$email_header.'<p>The user '.esc_html( $user_login ).' is registered to the website</p>'.$email_footer
);
}
add_action('new_customer_registered', 'new_customer_registered_send_email_admin');
add_action('woocommerce_created_customer', 'admin_email_on_registration', 10 , 1);
function admin_email_on_registration( $customer_id) {
wp_new_user_notification( $customer_id );
}
woocommerce_created_customer is hook which is called when user created by woocommerce. It only sends notification to customer. we will use wp_new_user_notification() function to send notification to Admin.
I was pulling my hair out trying to figure this same issue out and after going back and forth with the developers the default is to not send new customer registration notification emails to admin.
After trying various email plugins and even resorting to using WP SMTP Email, I finally decided to leave it alone.
That said, WooCommerce 2.0 was released today so it may be built in the new version.
the answers is in the emails sections of "woocommerce / settings"
simply change the from email to wordpress#yourdomain.com
worked for me as i also had the same issues
To notify admin whn new user has registered use:
add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
function woocommerce_created_customer_admin_notification( $customer_id )
{
wp_send_new_user_notifications( $customer_id, 'admin' );
}
See documentation on https://woocommerce.com/document/notify-admin-new-account-created/

Resources