Skip to content

Instantly share code, notes, and snippets.

@corazzi
Created July 4, 2017 08:17
Show Gist options
  • Save corazzi/ec90f83cc9c653cdf0487274fd5c4cdf to your computer and use it in GitHub Desktop.
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/
<?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