Problem:
I'm encountering a PHP notice: "Only variables should be passed by reference" due to code in my check_filetype.php file. The code, created years ago, is producing this warning in the logs.
Solution:
This warning occurs because PHP prefers variables over direct function calls in end() statements. To resolve this, assign the results of explode() functions to variables before using end(). Here’s an updated version of your code:
<?php /** * Check if the user uploaded job CPT file is a pdf. */ toolset_snippet_security_check() or die( 'Direct access is not allowed' ); add_shortcode( 'check_filetype', 'func_check_file_type' ); function func_check_file_type( $atts ) { $atts = shortcode_atts( array( 'url' => '', ), $atts ); $url_parts = explode( '/', $atts['url'] ); $file_name = end( $url_parts ); $file_extension = explode( '.', $file_name ); return end( $file_extension ); }
Explanation of Changes:
- Saved the results of explode() into $url_parts and $file_extension.
- Applied end() on these variables rather than directly on the function calls.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
This topic contains 1 reply, has 2 voices.
Last updated by 6 months ago.
Assisted by: Christopher Amirian.