I'm trying to maybe do too much in a shortcode call. Here's the code I have:
//[rand]
function randnumber_func( $atts ){
$digits = 4;
$randnumber = rand(pow(10, $digits-1), pow(10, $digits)-1);
$space = "\r\n";
$myFile = "offer_codes.txt";
$fh = fopen($myFile, 'a+') or die("can't open file");
$stringData = date("F j, Y, g:i a") . " - " . $randnumber;
fwrite($fh, $stringData.$space);
fclose($fh);
return $randnumber;
}
add_shortcode( 'rand', 'randnumber_func' );
I want to create a random 4 digit number and have it printed to the page. I also want to take that random number, append the date to it, and have that written to a text file. It works in PHP, but not when I call it via a shortcode. Is something it Wordpress stripping it out or do I have it written incorrectly for the shortcode function?