use query var argument as verification link?

In a from response email I want to send a link to with a unique url string attached to it. Clicking that link and visiti

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

相关推荐

  • use query var argument as verification link?

    In a from response email I want to send a link to with a unique url string attached to it. Clicking that link and visiti

    15小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信