i moved kernel files wordpress to a subfolder
now have a folder "content" and "kernel" at root
and got some problems
some commands only work with subfolder "kernel"
for example…
i use this function for to add change time for name scripts and styles
function put_modified_time_version($src, $baseUrl){
if ($src && strpos($src, $baseUrl) === 0) {
$newSrc = remove_query_arg('ver', $src);
$path = substr($newSrc, strlen($baseUrl));
$path = wp_parse_url($path, PHP_URL_PATH);
if ($mtime = @filemtime(untrailingslashit(ABSPATH) . $path)) {
$src = add_query_arg('ver', $mtime, $newSrc);
}
}
return $src;
}
add_filter('style_loader_src', 'modified_time_version_style', 15, 1);
function modified_time_version_style($src) {
return ($src) ? put_modified_time_version($src, wp_styles()->base_url) : $src;
}
add_filter('script_loader_src', 'modified_time_version_script', 15, 1);
function modified_time_version_script($src) {
return ($src) ? put_modified_time_version($src, wp_scripts()->base_url) : $src;
}
this works only for js and css in "kernel" folder
functions work from a folder "content"
think that a problem with $url = substr($newSrc, strlen($baseUrl));
tell me how it is better to specify it correctly so that everything would work?
2
Answers
as i wrote above
found a strange problem when transferring core files to a subfolder
for example...
function that adds versioning for js and css
this function adds versioning regardless of position of core files problem was in
$baseURL
maybe it will be useful to someoneIf
ABSPATH
isn’t returning the right thing then try some others. If you want a different path than one related to the current file then define a constant in a file that has the correct path (e.g. the main plugin file) and use that constant instead. For example in your main plugin.phpThen everywhere else in the code you can use the constants. For example
If you need a directory higher in the hierarchy then use
dirname($path)
. e.g.define('WHATEVER', dirname(dirname(__FILE__)));
ordefine('WHATEVER', dirname(dirname(__FILE__)) . '/content/');