awesomemotive / easy-digital-downloads

Sell digital downloads through WordPress
https://easydigitaldownloads.com
GNU General Public License v2.0
864 stars 475 forks source link

Image paths not resolved in non standard setup #6044

Closed alpipego closed 6 years ago

alpipego commented 6 years ago

In my setup, the WP_PLUGIN_DIR is not inside my WP_CONTENT_DIR (but on the same level). I do not have any images/icons, e.g., payment icons in my theme dir.

In https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/checkout/template.php#L694, for example, you're trying to replace the plugins path with the content_url(). But since the plugins dir does not have to be inside the WP_CONTENT_DIR this will not work in all non-default setups.

alpipego commented 6 years ago

Temporary workaround:

$paymentMethods = get_option('edd_settings')['accepted_cards'];

array_walk($paymentMethods, function ($method) {
    $method = preg_replace('/\h/', '', strtolower($method));
    add_filter('edd_accepted_payment_' . $method . '_image', function () use ($method) {
        $image         = edd_locate_template('images/icons/' . $method . '.png', false);
        $content_dir = WP_PLUGIN_DIR;

        if (function_exists('wp_normalize_path')) {
            // Replaces backslashes with forward slashes for Windows systems
            $image         = wp_normalize_path($image);
            $content_dir = wp_normalize_path($content_dir);
        }

        $src = str_replace($content_dir, WP_PLUGIN_URL, $image);

        return $src;
    });
});