'; } $jc_age_v_text_month = (!is_null($attrs['month'])) ? $attrs['month'] : $jc_age_v_Options['month']; $jc_age_v_text_months = (!is_null($attrs['months'])) ? $attrs['months'] : $jc_age_v_Options['months']; $jc_age_v_text_year = (!is_null($attrs['year'])) ? $attrs['year'] : $jc_age_v_Options['year']; $jc_age_v_text_years = (!is_null($attrs['years'])) ? $attrs['years'] : $jc_age_v_Options['years']; $jc_age_v_multiplierM = (!is_null($attrs['multiplierm'])) ? $attrs['multiplierm'] : $jc_age_v_Options['multiplierM']; $jc_age_v_multiplierM = (is_numeric($jc_age_v_multiplierM)) ? $jc_age_v_multiplierM : 1; $jc_age_v_multiplierY = (!is_null($attrs['multipliery'])) ? $attrs['multipliery'] : $jc_age_v_Options['multiplierY']; $jc_age_v_multiplierY = (is_numeric($jc_age_v_multiplierY)) ? $jc_age_v_multiplierY : 1; list($bY,$bM,$bD) = explode("-", $jc_age_v_birthdate); list($cY,$cM,$cD) = explode("-", date("Y-n-d")); //Calculates Months if ($bY == $cY) { $months = $cM - $bM; if ($months == 0 || $months > 1) { return ($months * $jc_age_v_multiplierM) . ' ' . $jc_age_v_text_months; } else { return ($months * $jc_age_v_multiplierM) . ' ' . $jc_age_v_text_month; } } //Calculates Months if "over" a year change if ($cY - $bY == 1 && $cM - $bM < 12) { if ($cD - $bM > 0) { $xm = 0; } else { $xm = 1; } $months = 12 - $bM + $cM - $xm; if ($months == 0 || $months > 1) { return ($months * $jc_age_v_multiplierM) . ' ' . $jc_age_v_text_months; } else { return ($months * $jc_age_v_multiplierM) . ' ' . $jc_age_v_text_month; } } //Calculates Years $years = (date("md") < $bM.$bD ? date("Y")-$bY-1 : date("Y")-$bY ); if ($years == 0 || $years > 1) { return ($years * $jc_age_v_multiplierY) . ' ' . $jc_age_v_text_years; } else { return ($years * $jc_age_v_multiplierY) . ' ' . $jc_age_v_text_year; } } /** * is_date function, stole from web */ function jc_age_f_is_date($value, $format = 'yyyy-mm-dd'){ if (strlen($value) == 10 && strlen($format) == 10) { // find separator. Remove all other characters from $format $separator_only = str_replace(array('m','d','y'),'', $format); $separator = $separator_only[0]; // separator is first character if ($separator && strlen($separator_only) == 2) { // make regex $regexp = str_replace('mm', '[0-1][0-9]', $value); $regexp = str_replace('dd', '[0-3][0-9]', $value); $regexp = str_replace('yyyy', '[0-9]{4}', $value); $regexp = str_replace($separator, "\\" . $separator, $value); if($regexp != $value && preg_match('/'.$regexp.'/', $value)) { // check date $day = substr($value,strpos($format, 'd'),2); $month = substr($value,strpos($format, 'm'),2); $year = substr($value,strpos($format, 'y'),4); if (@checkdate($month, $day, $year)) return true; } } } return false; } /** * Displays and processes the settings page */ function jc_age_f_DashboardSettings() { global $jc_age_v_Options; if (isset($_POST['submit'])) { check_admin_referer('jc_age__options'); $jc_age_v_Options['year'] = $_POST['agecalc_year']; $jc_age_v_Options['years'] = $_POST['agecalc_years']; $jc_age_v_Options['month'] = $_POST['agecalc_month']; $jc_age_v_Options['months'] = $_POST['agecalc_months']; $jc_age_v_Options['multiplierY'] = $_POST['agecalc_multiplierY']; $jc_age_v_Options['multiplierM'] = $_POST['agecalc_multiplierM']; update_option('jcAgeCalculator', $jc_age_v_Options); } ?>

Age Calculator

Configure the default text used when the plugin returns the current age. All values can be overridden within the quicktag.


Christine is 1 old

Ray is 4 old

Christine is 1 old

Ray is 9 old

Used as the multiplier for the year value. For example, if you had a pet web site you could multiply the age by 7 for "dog years"

Used as the multiplier for the month value

'month', 'months' => 'months', 'year' => 'year', 'years' => 'years', 'multiplierM' => '1', 'multiplierY' => '1' ); $jc_age_v_Options = get_option('jcAgeCalculator'); if (!empty($jc_age_v_Options)) { foreach ($jc_age_v_Options as $key => $option) { $tmp_jc_age_v_Options[$key] = $option; } } update_option('jcAgeCalculator', $tmp_jc_age_v_Options); return $tmp_jc_age_v_Options; } /** * Adds Settings Page Link for Dashboard Links */ function jc_age_f_AddDashboardSettings() { add_options_page('Age Calculator', 'Age Calculator', 8, basename(__FILE__), 'jc_age_f_DashboardSettings'); } $jc_age_v_Options = jc_age_f_GetOptions(); add_shortcode('agecalc', 'jc_age_f_AgeCalculator'); add_action('admin_menu', 'jc_age_f_AddDashboardSettings'); ?>