In a from response email I want to send a link to with a unique url string attached to it. Clicking that link and visiting the website through that link should trigger a function. The way I thought to go about it is this.
Add a query argument that will hold a random string as a value. When the pre_get_posts action catches the query and the random link matches I can call a function. This below is very basic code.
esc_url( add_query_arg( 'action', 'random_verification_link' ) );
function add_query_vars_filter( $vars ) {
$vars[] = 'action';
return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );
function catch_verification( $query ) {
if ( $query->is_main_query() ) {
// var_export( $query );
// var_export( $query->query );
$action = $query->get( 'action' );
// var_export( $action );
if ( 'random_verification_link' === $action ) {
wp_die( 'Link OK.. ' );
} else {
return;
}
}
}
add_action( 'pre_get_posts', 'catch_verification' );
The random string would have to be created and stored per form submit id and have time to die and die after having been visited. But that is for later.
For now, I am wondering if taking this approach is the right way? Can I, in fact, use the value of an array to store a random string for this use case? Is retrieving that value with add_query_var and pre_get_posts a good idea? Any help on getting me in the right direction is great.
The function is nothing to do with user logins or user roles, I simply want to see if I can get to send verification links that cause an action when visited. Like to learn this better, thx.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745321095a4622446.html
评论列表(0条)