Fix issue with accessing array offset on boolean value in get_custom_logo_url function
Issue:
I encountered an issue with the get_custom_logo_url function where a warning was triggered due to attempting to access an array offset on a boolean value. This warning occurred on line 139 of the class-header-footer-api.php file in the headless-cms-master plugin. The warning arose because the function did not handle scenarios where the theme either did not support a custom logo or when no logo was set.
<b>Warning</b>: Trying to access array offset on value of type bool in <b>/home/baloch/Local Sites/headless/app/public/wp-content/plugins/headless-cms-master/inc/classes/api/class-header-footer-api.php</b> on line <b>139</b><br />
Additionally, there's an existing issue (#33) titled "Cannot find custom logo" that seems related to the same warning message.
Solution:
To address this issue comprehensively, I made the following improvements:
- Utilized the
has_custom_logo()function to check if the current theme supports a custom logo. - Added a check to verify if a custom logo ID exists before attempting to retrieve the custom logo URL.
- Provided a fallback URL or value if the theme doesn't support a custom logo or if no logo is set.
These changes ensure that the get_custom_logo_url function gracefully handles variations in theme configurations, preventing the warning from being triggered and providing a more robust solution overall.