function readycat_keygen( $atts ) {
extract( shortcode_atts(
array(
'len' => null,
'char' => 'ABCDEFGHJKMNPQRSTUVWXYZ23456789',// don't bother with I L 1 O or 0
'type' => 'count',
'countby' => null,
'pre' => null,
'suf' => null,
'sep' => null,
'split' => null,
'start' => null,
'reset' => false,
), $atts )
);
if ( $type === 'count' ) {
switch ($countby) {
case "pre":
$count = "rc_count_{$pre}_";
break;
case "suf":
$count = "rc_count__{$suf}";
break;
case "both":
$count = "rc_count_{$pre}_{$suf}";
break;
default:
$count = "rc_count";
}
$k = get_option( $count ) + 1;
update_option( $count, $k );
if ( $start !== null && ( $start > $k || $reset ) ) {
$k = $start;
update_option( $count, $k );
}
if ($len) $k = str_pad($k, $len, '0', STR_PAD_LEFT);
} elseif ( $type === 'random' ) {
if (!$len) $len = 16;
$k = '';
$cl = strlen( $char ) - 1;
for ( $i = 0; $i < $len; ++$i ) {
$k .= $char[mt_rand( 0, $cl )];
}
if ($split) $k = implode( $sep, str_split($k, $split) );
}
if ( $pre ) $k = "{$pre}{$sep}{$k}";
if ( $suf ) $k = "{$k}{$sep}{$suf}";
return $k;
}
add_shortcode( 'keygen', 'readycat_keygen' );