Multisite redeclare issues when activating similar plugin on WP

Hi,
If i may, i would like to receive advice on how to work around an error on multisite

Fatal error: Cannot redeclare run_push_connect_notify() (previously declared in /www//wp-content/plugins/push-connect-notify/push-connect-notify.php:71) in /www/wp-content/plugins/push-connect-notify-pets/push-connect-notify-pets.php on line 71

I am trying to activate a similar plugin (with different name) and becuase of this last command in the php: /**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
function run_push_connect_notify() {

$plugin = new Push_Connect_Notify();
$plugin->run();

}
run_push_connect_notify();
which has the line 71 it will not work.
Any advice would be much appreciated, thanks :slight_smile:

  • James Morris

    Hello Dr. David,

    I hope you are well today. Thank you for your question.

    I just want to make sure I'm understanding you correctly:

    You are wanting to run 2 plugins (push-connect-notify and push-connect-notify-pets) and they essentially have the same code. Is that correct?

    If that is the case, what you will need to do is modify one of the plugins to rename the functions so that you don't have namespace conflicts.

    Let me illustrate:

    Since your original plugin is push-connect-notify, you can modify push-connect-notify-pets like so:

    Change this code:

    function run_push_connect_notify() {
    
    $plugin = new Push_Connect_Notify();
    $plugin->run();
    
    }
    run_push_connect_notify();

    To this:

    function run_pets_push_connect_notify() {
    
    $petsplugin = new Pets_Push_Connect_Notify();
    $petsplugin->run();
    
    }
    run_pets_push_connect_notify();

    Without having access to the complete plugins, it's difficult to determine all the changes that may be required, but generally, the above should give you a good starting point. Just remember that your functions need to have unique names else they will run into conflicts.

    I hope that clarifies a bit. Let us know if you have any further questions. We'll be happy to help! :slight_smile:

    James Morris

  • Dr. David

    Hi James,

    Thank you so much for the help :slight_smile:
    I tried to run it with the new naming however i got a new error.
    Fatal error: Uncaught Error: Class 'Pets_Push_Connect_Notify' not found in /www/wp-content/plugins/push-connect-notify-pets/push-connect-notify-pets.php:71 Stack trace: #0 /www/wp-content/plugins/push-connect-notify-pets/push-connect-notify-pets.php(75): run_pets_push_connect_notify() #1 /www//wp-admin/includes/plugin.php(1943): include('/www/...') #2 /www/wp-admin/plugins.php(164): plugin_sandbox_scrape('push-connect-no...') #3 {main} thrown in /www//wp-content/plugins/push-connect-notify-pets/push-connect-notify-pets.php on line 71

    Can i give you access to my site in private?, in the end, we can post the changes done for the benefit of all wonderful multisite users where ever they are :slight_smile:

    Cheers,
    David

  • James Morris

    Hello Dr. David,

    Yes, if you would like, I could take a look and see if I can narrow this down for you.

    Please visit the Contact page and complete the form with the following information:

    Select "I have a different question" from the drop-down box.

    Subject: "Attn: James Morris"

    In the Message box, please provide the following:

    - Admin login:
    Admin username
    Admin password
    Login url

    - FTP credentials
    host
    username
    password
    (and port if required)

    - link back to this thread for reference
    - any other relevant urls

    Best regards,

    James Morris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.