• Kaystar

    (@learningtodoit)


    Hi There,

    Would like to test out this invaluable plugin (Code Snippets), thanks to Shea Bunge and Verdi Heinz. However, I would like to be sure firsthand that the code is good to go before using it. ‘Coz I got it from a 10yr old thread in one of the support threads.

    THe code is a string to generate random reference number for CF7 submissions using CF7 DTX plugin to create the dynamic field in CF7. Here is the code:
    ………………………………………………………………..
    /* Generate Quote Ticket */
    function genTicketString() {
    $length = 8;
    $characters = “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
    for ($p = 0; $p < $length; $p++) {
    $string .= $characters[mt_rand(0, strlen($characters)-1)];
    }
    return $string;
    }
    add_shortcode(‘quoteticket’, ‘genTicketString’);

    …………………………………………………………………..

    Anyone code savvy here to pls check if it’s good and still compatible with current version of PHP.

    Thanks a lot.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    It looks like it should work (aside from the missing $string variable), but I would rewrite it like this to remove the possibility of a duplicate function error:

    add_shortcode( 'quoteticket', function () {
    	$length = 8;
    	$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    	$string = '';
    
    	for ( $p = 0; $p < $length; $p++ ) {
    		$string .= $characters[ mt_rand( 0, strlen( $characters ) - 1 ) ];
    	}
    
    	return $string;
    } );
    Thread Starter Kaystar

    (@learningtodoit)

    Oh Thanks a bunch Shea Bunge, appreciated.

    So, I can copy/paste the edited code above exactly as it is without any addition from my side?
    I mean, I don’t have to add anything even in the empty bracket(s)?

    Thanks a lot for your attention.

    Thread Starter Kaystar

    (@learningtodoit)

    What should be the $sting variable and where should I add it pls?

    Plugin Author Shea Bunge

    (@bungeshea)

    No need to modify the code I posted. The only thing you need to do is use the [quoteticket] shortcode in a post or page.

    Thread Starter Kaystar

    (@learningtodoit)

    Hi Shea,
    Thanks a lot.

    1.Regarding the -where to run options and priority settings,- what should I choose for my purpose of inserting the shortcode in CF7 form using the CF7DTX plugin ?
    2. I changed the -quoteticket- to -report number- hope np issue with that.
    Sorry for the naive question, just being extra careful.

    Thanks

    Thread Starter Kaystar

    (@learningtodoit)

    Run everywhere
    Admin area
    Front end
    only once

    Thread Starter Kaystar

    (@learningtodoit)

    The short code in the setting – Editor preview box with text that reads “Tthank you for visiting “site name””

    Will it appear on my site?
    Should I delete it or leave it in place?

    Plugin Author Shea Bunge

    (@bungeshea)

    The editor preview box is just an example snippet to how the editor settings look. It doesn’t have any actual impact on your site.

    Adding the snippet as a ‘Run everywhere’ snippet is fine.

    Replacing the word quoteticket in the code I posted will allow you to change the name of the shortcode you use.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Anything Wrong With This Code Pls?’ is closed to new replies.