WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Download Monitor] PHP error with all download links (7 posts)

  1. chrisanthropic
    Member
    Posted 3 years ago #

    I cannot get downloads to work, anytime I try to download them I get the following error (with both permalinks and default):

    Fatal error: Cannot redeclare wp_dlm_get_total_downloads() (previously declared in /opt/lampp/htdocs/xampp/wordpress/wp-content/plugins/download-monitor/shortcodes.php:27) in /opt/lampp/htdocs/xampp/wordpress/wp-content/plugins/download-monitor/shortcodes.php on line 29

    I'm using the following permalink structure on my site: /%category%/%postname%/

    And the custom URL on the plugin is set to:
    http://www.backthatelfup.com/downloads/{id}

    If I go to "downloads" and "edit" the file URL is correct: http://www.backthatelfup.com/wp-content/uploads/downloads/2011/02/NAME-OF-FILE.pdf

    But all download links point to:
    http://www.backthatelfup.com/wp-content/plugins/download-monitor/download.php?id=NAME-OF-FILE.pdf

    I've read the FAQ, readme, and forums for this plugin all morning. Any help on what I'm doing wrong here?

  2. ds1970
    Member
    Posted 3 years ago #

    Interested in the answer to this as well.

  3. chrisanthropic
    Member
    Posted 3 years ago #

    Ok, seriously no one else is having this issue?

    I'm running the most recent version of the plugin and WP 3.1.1 on the live site now and I can manually link to uploaded files, but anytime I try to use a button, shortcode, or link created by the plugin I get that error.

    See here for an example:

    Actual file: http://www.backthatelfup.com/wp-content/uploads/downloads/2011/02/Ch-1-Out-of-The-Dregs.pdf

    And here's the downloads page (no longer in use, just for troubleshooting this): http://www.backthatelfup.com/downloads/

    Thanks for any help, suggestions, or screaming that anyone has.

  4. Pierreb
    Member
    Posted 3 years ago #

    Hi!
    I had the same problem with the error-message "Fatal error: Cannot redeclare..."
    I found my own solution to it.

    As the error says, A function called "X" is already declared and cannot be declared again. So i opened up the shortcodes.php file and started to look for all these functions giving me errors.

    My solution
    The solution to the problem for me was to write some code to check if the function has been declared or not. If it is declared then don't declare it again, if not - do it!

    If you know some PHP-coding you can do it your own for each function like this:

    This is the first function and its block of code that generate an error from shortcodes.php (The name of the function is wp_dlm_get_total_downloads() ):

    function wp_dlm_get_total_downloads() {
    		global $wpdb, $wp_dlm_db;
    		return $wpdb->get_var('SELECT SUM(hits) FROM '.$wp_dlm_db.';');
    	}
    
    	add_shortcode('total_downloads', 'wp_dlm_get_total_downloads');
    }
    if(!function_exists('wp_dlm_get_total_files'))
    {
    	function wp_dlm_get_total_files() {
    		global $wpdb, $wp_dlm_db;
    		return $wpdb->get_var('SELECT COUNT(*) FROM '.$wp_dlm_db.';');
    	}
    	add_shortcode('total_files', 'wp_dlm_get_total_files');

    We need to add this code to this specific block of code/function:
    if(!function_exists('wp_dlm_get_total_downloads'))
    {

    THE BLOCK OF CODE ABOVE GOES HERE
    }

    In the example above we check to see if the function "wp_dlm_get_total_downloads" has not been declared earlier. If it has we simply don't run it. If not we trigger it!

    More errors?
    When you have saved your changes to the shortcodes.php and checked your site to get the next function error, cause you will get new ones. :-/
    Repeat the process for that new function error:
    if(!function_exists('wp_dlm_shortcode_download'))
    {
    BLOCK OF CODE TO BE DECLARED
    }

    If you're lazy or think that what I wrote above is greek, you can download my own modified file shortcodes.php) here: Download the modified file

    Remember that if you autoupdate the plugin with a new released version, all these changes will be gone!

  5. chrisanthropic
    Member
    Posted 3 years ago #

    That worked perfectly, thanks for sharing!

  6. ZhangYu
    Member
    Posted 2 years ago #

    Thanks man! I had this problem too. it makes my head so pain. With your solution i fixed all functions in the shortcodes.php file, it works, i just don't know why!

  7. proximity2008
    Member
    Posted 2 years ago #

    Seriously, this has busted 2 client sites in recent memory.
    The plugin author has to roll this into the next release!

    Thanks chrisanthropic for the fix.

Topic Closed

This topic has been closed to new replies.

About this Topic