Support » Fixing WordPress » How is email verification implemented in a subscription list plugin?

  • Resolved starapple

    (@starapple)


    I am using a simple plugin to collect subscribers whose names and email addresses are saved in the wpdb. I’ve come across the below plug-in that implements email verification but it seems to be querying the site’s user meta and I am not clear what it retrieves to tokenise.

    I need help in clarifying what I am seeing so as to be able to substitute a wpdb query for the get_option() statement.

    <?php
    /**
     * Plugin Name: Email Confirmation
     * Description: Send an email to the user with confirmation code and store form data in database until user confirms.
     * Author: Cedric Ruiz
     */
    class EmailConfirmation
    {
      const PREFIX = 'email-confirmation-';
    
      public static function send($to, $subject, $message, $headers)
      {
        $token = sha1(uniqid());
    
        $oldData = get_option(self::PREFIX .'data') ?: array();
        $data = array();
        $data[$token] = $_POST;
        update_option(self::PREFIX .'data', array_merge($oldData, $data));
    
        wp_mail($to, $subject, sprintf($message, $token), $headers);
      }
    
      public static function check($token)
      {
        $data = get_option(self::PREFIX .'data');
        $userData = $data[$token];
    
        if (isset($userData)) {
          unset($data[$token]);
          update_option(self::PREFIX .'data', $data);
        }
    
        return $userData;
      }
    }

    Thanks.

    PS: I don’t want a plugin recommendation as I am tired to upsells and requests for five-star ratings and sundry things buzzing about my admin area.

    • This topic was modified 1 week, 6 days ago by starapple.
Viewing 2 replies - 1 through 2 (of 2 total)
  • get_option reads an options record. The function takes care of deserializing the contents for you. If, as in this case, an array was stored, it is serialized and de-serialized by get_option to a normal PHP array. This array then obviously contains the specified token as index.

    Thread Starter starapple

    (@starapple)

    @threadi, sorry for the delay in acknowledging your help. I am familiar with the options but I was not clear enough in asking how to implement tbe subscription list script using wpdb rather than with the options table. I think it best to close (or delete) the topic and srart an updated thread in the Developing with WordPress forum.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.