How can I add a field value to the end of the $activate_url
that's sent in the activation email?
Such as $activate_url . ?key=$key**&as=$fieldvalue**
, I don't know enough about GForm to pass these values.
答案 0 :(得分:0)
以下是两个例子。第一个是准系统版本:
/**
* Gravity Wiz // GF User Registration // Modify Activation URL
*/
add_filter( 'wpmu_signup_user_notification_email', 'gw_modify_activation_url', 11, 4 );
function gw_modify_activation_url( $message, $username, $email, $key ) {
// find the current activation URL in the message
if ( is_callable( 'bp_get_activation_page' ) ) {
$search = esc_url_raw( sprintf( '%s?key=%s', bp_get_activation_page(), $key ) );
} else {
$search = esc_url_raw( add_query_arg( array( 'page' => 'gf_activation', 'key' => $key ), get_site_url() . '/' ) );
}
// add your query parameters to the current activation URL
$replace = add_query_arg( array( 'my_key' => 'my_value' ), $search );
// replace the current activation URL with the updated URL
$message = str_replace( $search, $replace, $message );
return $message;
}
此版本通过支持访问与激活密钥关联的$ entry对象来加强它,以便您可以在修改后的激活URL中包含条目中的数据。
/**
* Gravity Wiz // GF User Registration // Modify Activation URL w/ Entry Data
*/
add_filter( 'wpmu_signup_user_notification_email', 'gw_modify_activation_url_with_entry_data', 11, 4 );
function gw_modify_activation_url_with_entry_data( $message, $username, $email, $key ) {
// make sure GF User Registration is loaded
if( ! is_callable( array( 'GFUser', 'get_base_path' ) ) ) {
return $mesage;
}
// include the signups functionality
require_once( GFUser::get_base_path() . '/includes/signups.php' );
// get the signup object for the provided key, this contains all the GF related information you'll ever want for the key
$signup = GFSignup::get( $key );
if( is_wp_error( $signup ) ) {
return $message;
}
// set the "lead" property of the signup to an $entry variable for clarity
// "lead" is no longer the correct term for the data associated with a GF submission
$entry = $signup->lead;
// find the current activation URL in the message
if ( is_callable( 'bp_get_activation_page' ) ) {
$search = esc_url_raw( sprintf( '%s?key=%s', bp_get_activation_page(), $key ) );
} else {
$search = esc_url_raw( add_query_arg( array( 'page' => 'gf_activation', 'key' => $key ), get_site_url() . '/' ) );
}
// add your query parameters to the current activation URL
$replace = add_query_arg( array( 'my_key' => $entry[1] ), $search );
// replace the current activation URL with the updated URL
$message = str_replace( $search, $replace, $message );
return $message;
}
如果您需要根据查询字符串实际修改激活模板,请参阅此文章:http://gravitywiz.com/customizing-gravity-forms-user-registration-activation-page/