bp_media_parse_file_path( string $file_path )
Parse file path and see if its remote or local.
Description
Parameters
- $file_path
-
(Required) File path.
Return
(array)
Source
File: bp-media/bp-media-filters.php
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 | function bp_media_parse_file_path( $file_path ) { $wp_uploads = wp_upload_dir(); $wp_uploads_dir = $wp_uploads [ 'basedir' ]; $wp_uploads_url = $wp_uploads [ 'baseurl' ]; /** * Replace uploads dir, site url etc with absolute counterparts if we can. * Note the str_replace on site_url is on purpose, so if https is forced * via filters we can still do the string replacement on a HTTP file. */ $replacements = array ( $wp_uploads_url => $wp_uploads_dir , network_site_url( '/' , 'https' ) => ABSPATH, str_replace ( 'https:' , 'http:' , network_site_url( '/' , 'http' ) ) => ABSPATH, site_url( '/' , 'https' ) => ABSPATH, str_replace ( 'https:' , 'http:' , site_url( '/' , 'http' ) ) => ABSPATH, ); $file_path = str_replace ( array_keys ( $replacements ), array_values ( $replacements ), $file_path ); $parsed_file_path = wp_parse_url( $file_path ); $remote_file = true; // Paths that begin with '//' are always remote URLs. if ( '//' === substr ( $file_path , 0, 2 ) ) { return array ( 'remote_file' => true, 'file_path' => is_ssl() ? 'https:' . $file_path : 'http:' . $file_path , ); } // See if path needs an abspath prepended to work. if ( file_exists ( ABSPATH . $file_path ) ) { $remote_file = false; $file_path = ABSPATH . $file_path ; } elseif ( '/wp-content' === substr ( $file_path , 0, 11 ) ) { $remote_file = false; $file_path = realpath ( WP_CONTENT_DIR . substr ( $file_path , 11 ) ); // Check if we have an absolute path. } elseif ( ( ! isset( $parsed_file_path [ 'scheme' ] ) || ! in_array( $parsed_file_path [ 'scheme' ], array ( 'http' , 'https' , 'ftp' ), true ) ) && isset( $parsed_file_path [ 'path' ] ) && file_exists ( $parsed_file_path [ 'path' ] ) ) { $remote_file = false; $file_path = $parsed_file_path [ 'path' ]; } return array ( 'remote_file' => $remote_file , 'file_path' => $file_path , ); } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.4.1 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.