Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Fukcja obliczająca ilość lat od podanej daty
- * Licence: CC-BY-SA 4.0
- * @author: Paweł Nowak
- *
- * @param array $wiek {
- * Attributes of the age shortcode.
- *
- * @type string $rok Data, od której obliczane są lata.
- * @type string $format Format wywietlania wieku. Format musi pasować do wprowadzonej daty.
- * Więcej tu:
- * @link: http://php.net/manual/en/datetime.createfromformat.php
- *
- * @return string @wynik Zwraca obliczoną ilość lat od podanej daty w @type @rok
- **/
- add_shortcode('wiek', 'wpsolucje__sc__wiek');
- function wpsolucje__sc__wiek( $wiek ){
- $wiek = shortcode_atts( array(
- 'rok' => '2000',
- 'format' => 'Y',
- ), $wiek );
- $rok = DateTime::createFromFormat( 'Y', $wiek['rok'] );
- $teraz = new DateTime();
- $wynik = $teraz->diff( $rok );
- return $wynik->y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement