This will evaluate wheter a URL is at an aboslute location (like http://example.org/whatever)
public static is_absolute ( string $path ) : boolean | ||
$path | string | |
return | boolean | true if $path is an absolute url, false if relative. |
/** * Takes in an URL and breaks it into components, * that will then be used in the different steps of image processing. * The image is expected to be either part of a theme, plugin, or an upload. * * @param string $url an URL (absolute or relative) pointing to an image * @return array an array (see keys in code below) */ private static function analyze_url($url) { $result = array('url' => $url, 'absolute' => URLHelper::is_absolute($url), 'base' => 0, 'subdir' => '', 'filename' => '', 'extension' => '', 'basename' => ''); $upload_dir = wp_upload_dir(); $tmp = $url; if (0 === strpos($tmp, ABSPATH)) { // we've been given a dir, not an url $result['absolute'] = true; if (0 === strpos($tmp, $upload_dir['basedir'])) { $result['base'] = self::BASE_UPLOADS; // upload based $tmp = str_replace($upload_dir['basedir'], '', $tmp); } if (0 === strpos($tmp, WP_CONTENT_DIR)) { $result['base'] = self::BASE_CONTENT; // content based $tmp = str_replace(WP_CONTENT_DIR, '', $tmp); } } else { if (!$result['absolute']) { $tmp = home_url() . $tmp; } if (0 === strpos($tmp, $upload_dir['baseurl'])) { $result['base'] = self::BASE_UPLOADS; // upload based $tmp = str_replace($upload_dir['baseurl'], '', $tmp); } if (0 === strpos($tmp, content_url())) { $result['base'] = self::BASE_CONTENT; // content-based $tmp = str_replace(content_url(), '', $tmp); } } $parts = pathinfo($tmp); $result['subdir'] = $parts['dirname'] === '/' ? '' : $parts['dirname']; $result['filename'] = $parts['filename']; $result['extension'] = strtolower($parts['extension']); $result['basename'] = $parts['basename']; // todo filename return $result; }