Created
July 4, 2017 08:17
-
-
Save corazzi/ec90f83cc9c653cdf0487274fd5c4cdf to your computer and use it in GitHub Desktop.
Get the year the file was uploaded relative to its location in wp-content/uploads/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get the year the file was uploaded relative to its location in wp-content/uploads/ | |
* | |
* @param string Can be a URL or an absolute path to the file | |
* | |
* @return string Returns the year as a string, but can easily be cast to an int | |
*/ | |
function get_uploaded_year($uri) | |
{ | |
return substr(explode('/wp-content/uploads/', $uri)[1], 0, 4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment