Possible Yoast 14 conflict

This topic contains 3 replies, has 2 voices, and was last updated by  Stephen Harris 3 years, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38710

    Hi,

    I’m on Event Organiser 3.10.2 + Event Organiser Pro 2.0.2 where I have a custom version:
    of eo-ticket-picker.php based on:
    https://gist.github.com/stephenharris/1b3d7fc0eb6a0e91226d9e24ec010bce

    In my eo-ticket-picker.php I also have copy of eo_get_booking_occurrence_picker -function from “…includes/template-tags.php” where I included a call to eo_get_event_tickets_on_sale to retrieve every ticket name, and renamed the function to eo_custom_get_booking_occurrence_picker.

    This has been working fine until I upgraded from Yoast 13 to Yoast 14 then all of a sudden there is a fatal error:
    “PHP Fatal error: Cannot redeclare eo_custom_get_booking_occurrence_picker() (previously declared in /wp-content/themes/total-child/eo-ticket-picker.php:5) in wp-content/themes/total-child/eo-ticket-picker.php on line 5”
    …the function is in fact only declared once

    I tried asking at Yoast github explaining that the problem goes away if I deactivate Yoast but they closed it immediately “this is not actionable and I’m closing it”.

    Any way I discovered that if I move my eo_custom_get_booking_occurrence_picker() to inside the plugin file “includes/template-tags.php” then everything seem to work again and the error is not present. I´m ok with this solution, I just need to remember to put it back after any plugin updates.

    But I wanted to ask your opinon, do you have any idea why this error would appear because of Yoast update? and is there another way I could place that function inside my child theme instead?

    Best Regards!
    /AK

    AK
    #38725

    Hi,

    I think that Yoast 14 plug-in is, for some reason, causing the total-child/eo-ticket-picker.php file to be loaded twice.

    You can confirm that by putting in error logging. In fact if you log the return value of wp_debug_backtrace_summary() you will be able to see the call stack and determine what is causing ti to be loaded twice.

    At a guess, since this a template file, perhaps Yoast 14 plugin is pre-rendering the page to analyize SEO or generate metadata tags (???).

    In any case, I would recommend against declaring functions inside template files as the latter should ideally be re-usable. Instead you can declare the function in your theme’s functions.php (or in a different file loaded by it).

    If I’m right, that will also solve your problem without having to edit the plug-in’s code.

    Stephen Harris
    #38726

    Thank you Stephen!

    I moved my custom function to functions.php instead and it seem to work fine, there are no error now.

    Regarding “wp_debug_backtrace_summary()”, I would be happy to report the callstack to Yoast but I’m not sure how/where I should use that?

    …would you say it’s wise/safe to install the Yoast upgrade after I moved my custom function?

    Thanks!
    /AK

    AK
    #38733

    So I would enable logging in WordPress and then add

    error_log(wp_debug_backtrace_summary());
    

    before the function declaration.

    However, it’s quite likely that this isn’t a bug with the Yoast plug-in, and that the template file is legitimately being loaded twice. The fix you have in place is best practice in any case.

    Stephen Harris
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.