• Does anyone have an example of private ID generator? I would like to replace the current one so it simply generates a six digit random unique number.

    Any help would be gratefully received.

    Many thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author xnau webdesign

    (@xnau)

    This is very simple, there is a filter you can use to replace the built-in private ID generator. The plugin checks it for uniqueness, so you don’t have to handle that part. If it somehow generates a number that is already used, Participants Database just calls the function again.

    // filter the private id generation to supply a numeric private ID
    add_filter( 'pdb-generate_private_id', 'generate_random_number_id');
    function generate_random_number_id( $private_id )
    {
      // get a 6-digit random number
      $numeric_id = rand( 100000, 999999 );
      // send it back to the plugin
      return $numeric_id;
    }
    Thread Starter londonnet

    (@londonnet)

    Thanks for the code, I have some questions.

    How do you implement the code? Where do you put it?
    The number range looks like it will be any random number between 100000, 999999. Could it be 000001, 999999?
    Would it be possible to exclude particular numbers like 123456 or 111111 and so on?

    In my application the the private_id is a simple pin and should not be overly easy to guess.

    Your support is very much appreciated.

    Thanks

    Plugin Author xnau webdesign

    (@xnau)

    Ok you didn’t mention what it was for, I gave you the simplest answer…what you’re asking for is pretty complex, I don’t have any code like that for you, you can probably find something like that with an internet search.

    Thread Starter londonnet

    (@londonnet)

    Thanks for the reply. I got to thinking I could just add the numbers I don’t want to give out to the DB before hand, pre populate with bad pins and thus they will not be issued.

    I will play with the code and see if I can work out how achieve the random number range I am looking for.

    But can I ask, how do you use the code you have above? Do you add it in as a separate file and then call it in some way? I had a look at the documentation for filters and didn’t understand how to replace the filter.

    any help in this area would be appreciated.

    Plugin Author xnau webdesign

    (@xnau)

    A filter is a bit of code that is used to modify how a plugin or theme works without changing the code of the plugin or theme. It is typically placed in the functions.php file of your active theme.

    These are very common in WordPress, you’ll find lots of examples of their use if you look around WordPress coding tutorials.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘private ID generator’ is closed to new replies.