顺序号联系表7

时间:2018-06-20 01:37:00

标签: php wordpress

我设法通过https://www.banna360.com/contact-from7-dynamic-number-generation/

获得了为CF7创建序列号所需的信息。
function wpcf7_generate_rand_number( $wpcf7_data ) {
    $properties = $wpcf7_data->get_properties();
    $shortcode = '[rand-generator]';
    $mail = $properties['mail']['body'];
    $mail_2 = $properties['mail_2']['body'];

    $subject = $properties['mail']['subject'];
    $subject2 = $properties['mail_2']['subject'];

    if( preg_match( "/{$shortcode}/", $mail ) || preg_match( "/[{$shortcode}]/", $mail_2 ) ) {
        $option = 'wpcf7sg_' . $wpcf7_data->id();
        $sequence_number = (int)get_option( $option ) + 1;
        update_option( $option, $sequence_number );
        $properties['mail']['body'] = str_replace( $shortcode, $sequence_number, $mail );
        $properties['mail_2']['body'] = str_replace( $shortcode, $sequence_number, $mail_2 );
        $properties['mail']['subject'] = str_replace( $shortcode, $sequence_number, $subject );
        $properties['mail_2']['subject'] = str_replace( $shortcode, $sequence_number, $subject2 );

        $wpcf7_data->set_properties( $properties );
    }
}
add_action( 'wpcf7_before_send_mail', 'wpcf7_generate_rand_number' );

但是,我需要指定一个起始编号(例如1000001),而不是仅从1开始。您知道如何使用此代码吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

import java.util.Scanner;

public class guessing_game {
   public static void main (String[] args) {
      Scanner kb = new Scanner(System.in);
      desc();
      run(kb);    

      //int nun = 0;

      //for (int i = 0; i < nun; nun ++)
   }
   public static void desc() {
      System.out.println("This is a guessing game.");
      System.out.println();
      System.out.println("Let's see how many tries it takes you to guess the right number!");
      System.out.println();
      System.out.println();
      System.out.println();
   }

   public static int run(Scanner kb) {
      System.out.println("Please enter a number between 1-100");
      int guess = kb.nextInt();

      int num = 44;

      int tries = 0;
      do {
         if (guess < num) {
            System.out.println("Oooh. Your guess is too low. Try again.");
            System.out.println();
            run(kb);
         }
         else if ((guess > 100) || (guess < 0)) {
            System.out.println("That isn't between 1-100 is it?");
            System.out.println();
            run(kb);
         }
         else if (guess > num) {
            System.out.println("Aaah. Your guess is too high. Try again.");
            System.out.println();
            run(kb);
         }
         else if(guess == num) {
            System.out.println("Bingo!!! Nice guess bud.");
            System.out.println("Tell a friend to play! Wanna try again? (y or n)");
            String choice = kb.next();
            if (choice.equalsIgnoreCase("y")) {
               run(kb);
            }
            else if (choice.equalsIgnoreCase("n")) {
               System.exit(0);
            }
         }
         tries++;
      }while(tries < 3);
      {
         System.out.print("Here's a hint the lucky number is 4");
      }

      return guess;
   }  
}