Search code examples
phpwordpressflickr

PHP Fatal error: Cannot redeclare get_and_delete_option()


I am working for a client who is using the flickerRSS RU plugin for WordPress. However when they try to put more than one calling of the function per page they get this error in the error_log:

PHP Fatal error:  Cannot redeclare get_and_delete_option() (previously declared 
in .../wp-content/plugins/flickrrss-ru/flickrrssRU.php:21) in 
.../wp-content/plugins/flickrrss-ru/flickrrssRU.php on line 21

First of the plugin calls is:

get_flickrRSSRU(array(
    'set' => '72157624558519886',
    'num_items' => 3,
    'type' => 'set',
    'html' => ' <a href="%flickr_page%" title="%title%"><img src="%image_square%" alt="%title%"/ height="68px" ></a>'));

Followed by:

get_flickrRSSRU(array(
    'set' => '72157624558519886',
    'num_items' => 11,
    'type' => 'set',
    'html' => ' <a href="%flickr_page%" title="%title%"><img src="%image_square%" alt="%title%"/ height="75" ></a>'));

I am not sure why these two calls would try to initialize the plugin again if it was loaded via WordPress.

I found out that this specific function being used is in the plugin as such:

$flickrRSSRU = new flickrRSSRU();
add_action( 'admin_menu', array(&$flickrRSSRU, 'setupSettingsPage') );
add_action( 'plugins_loaded', array(&$flickrRSSRU, 'setupWidget') );
register_activation_hook( __FILE__, array( &$flickrRSSRU, 'setupActivation' ));

function get_flickrRSSRU($settings = array()) {
    global $flickrRSSRU;
    $flickrRSSRU->printGallery($settings);
}

Solution

  • My guess is it's line 49 in flickrrssRU.php

    if (!get_option('flickrRSSRU_settings')) $this->setupActivation();
    

    This one is likely calling $this->setupActivation() both times, which is declaring the get_and_delete_option() function inside of that method. It should have been creating the options when the plugin was activated, however it seems to be having trouble accessing it.

    Look in your wp_options table and see if you can find the "flickrRSSRU_settings" key in there.

    Alternative solution is to change line 21 of that same file from

    function get_and_delete_option($setting) { $v = get_option($setting); delete_option($setting); return $v; }
    

    to

    if(!function_exists('get_and_delete_option')) {
        function get_and_delete_option($setting) { $v = get_option($setting); delete_option($setting); return $v; }
    }
    

    However if it's not finding the settings, you may run into other problems later.