The code at line 70 of class-tn-admin-asset.php is expecting arguments in an array with certain elements, but the array keys ‘scheme’ and ‘query’ are not assigned values. You get such notices when you do something like
$array = ['foo'=>'some value', 'bar'=>'another value',];
echo "The foo is {$array['foo']}<br>\n"; // works
echo "The scheme is {$array['scheme']}"; // error
@bcworkz
Yes, I know, I just don’t understand why this error message appears.
This is my code:
add_filter('style_loader_src', 'modifying_resource_urls', 99, 2);
add_filter('script_loader_src', 'modifying_resource_urls', 99, 2);
function modifying_resource_urls( $src, $handle ) {
$parse_url = wp_parse_url( $src );
$exclude_host = [
'gw.alipayobjects.com',
'www.gstatic.com',
];
if ( ! in_array( $parse_url['host'], $exclude_host, true ) ) {
$cdn_host = 'cdn.example.cn';
$src = $parse_url['scheme'] . '://' . $cdn_host . $parse_url['path'] . '?' . $parse_url['query'];
}
return esc_url( $src );
}
Under normal circumstances, the parameter $src is definitely a standard url.
Is there anything I understand is wrong?
-
This reply was modified 7 years, 9 months ago by
bearshang.
-
This reply was modified 7 years, 9 months ago by
bearshang.
@bcworkz
I solved him.
When I echo $src, I found that there was an ” $src, So wp_parse_url won’t work.
Although I don’t understand why there is an ” $Src, obviously this should be the root cause.
Ah, I see now. There shouldn’t be anything besides a proper URL in $src. If there is anything else, I would expect that your theme or a plugin is not properly enqueuing resources. Whatever path information exists (if any) in the bad data should indicate which module is causing the problem.
If $src is so corrupted that there is no path to use as a clue, var_dump and examine the global $wp_scripts and $wp_styles arrays and locate the bad URL. The ‘handle’ key above the URL tells you the registered enqueue handle, which will also be in the source code of the offending module. Use grep or similar to find where it is in source if the handle or URL alone is not enough of a clue.
Since you’ve solved this, maybe this does not matter, but invalid data could be a sign of other issues. It’s a good idea to resolve the root cause. The presence of ”$src is not the root cause, the code that caused it to be that way is the root cause.