• Resolved willss

    (@willss)


    I have the same issue as this guy: https://wordpress.org/support/topic/code-being-executed-twice/

    Wordpress and plugin are fully updated. I currently have no snippets live.

    Here is the code I’m trying to add:
    function remove_custom_post_comment() {
    remove_post_type_support( ‘tribe_events’, ‘comments’ );
    }
    function remove_custom_post_comment() {
    remove_post_type_support( ‘tribe_venue’, ‘comments’ );
    }
    function remove_custom_post_comment() {
    remove_post_type_support( ‘tribe_organizer’, ‘comments’ );
    }

    add_action( ‘init’, ‘remove_custom_post_comment’ );

    Here is the error message:
    The code snippet you are trying to save produced a fatal error on line 6:

    Cannot redeclare remove_custom_post_comment() (previously declared in /www/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(187) : eval()’d code:2)

    I can’t make the code live. What is causing this?

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hello,

    My apologies for taking so long to respond to this – I didn’t realise I hadn’t replied.

    You are receiving this error because PHP doesn’t allow you to have more than one function of the same name. In the code you posted, you have three functions that are all called remove_custom_post_comment.

    You can solve this by combining the code within the three functions together into one function, like this:

    function remove_custom_post_comment() {
    	remove_post_type_support( 'tribe_events', 'comments' );
    	remove_post_type_support( 'tribe_venue', 'comments' );
    	remove_post_type_support( 'tribe_organizer', 'comments' );
    }
    
    add_action( 'init', 'remove_custom_post_comment', 15 );

    An even better solution is to remove the function name all together, like this:

    add_action( 'init', function () {
    	remove_post_type_support( 'tribe_events', 'comments' );
    	remove_post_type_support( 'tribe_venue', 'comments' );
    	remove_post_type_support( 'tribe_organizer', 'comments' );
    }, 15 );

    Let me know if you have any other questions!

Viewing 1 replies (of 1 total)

The topic ‘Code being executed twice again?’ is closed to new replies.