themeum / kirki

Extending the customizer
https://kirki.org
MIT License
1.26k stars 328 forks source link

Kirki#set_url() is wrong - WP_CONTENT_DIR instead of WP_CONTENT_URL #2296

Closed valerio-bozzolan closed 2 years ago

valerio-bozzolan commented 4 years ago

Hello everybody!

The bug

I noticed that the Kirki_Init#set_url() uses the WP_CONTENT_DIR but this is logically wrong and cause wrong URLs, with stylesheets pointing to 404 "not found" pages in certain configurations.

To be known: the WP_CONTENT_DIR describes the position of the "wp-contents" files in the filesystem, but this has nothing to do with the "wp-content" directory URL.

For example this is a very legitimate configuration:

// I have the contents in this filesystem position
define('WP_CONTENT_DIR', '/var/www/example.com/user-data');

// but they are exposed to this URL (because I configured the webserver to do it)
define('WP_CONTENT_URL', 'https://example.com/wp-content' );

Actual behaviour (wrong, 404 page):

<link rel='stylesheet' id='kirki-styles-qt_config-css'  href='https://example.com/var/www/example.com/user-data/plugins/ttg-core/inc/backend/kirki/assets/css/kirki-styles.css' type='text/css' media='all' />

Expected correct behaviour:

<link rel='stylesheet' id='kirki-styles-qt_config-css'  href='https://example.com/wp-content/plugins/ttg-core/inc/backend/kirki/assets/css/kirki-styles.css' type='text/css' media='all' />

See:

https://codex.wordpress.org/Function_Reference/content_url

I'm using the version 1.2.8 (latest one).

valerio-bozzolan commented 4 years ago

Sorry it seems that this is not this plugin fault. It seems that we are using Kirby through the plugin "The Core Plugin" from Quantum Themes.

Plugin Name: Theme Core Plugin
Plugin URI: http://www.qantumthemes.com/
Description: Adds custom type and custom fields capabilities and extends customizer capabilities. Containes Metaboxes and Kirki cutom versions for Themes2Go
Author: qantumthemes
Version: 1.2.8
Text Domain: ttg-core
Domain Path: /languages

Anyway, the bad file is in this position in my filesystem:

.../wp-content/plugins/ttg-core/inc/backend/kirki/core/class-kirki-init.php

And this is the interested part:

...
        /**
         * Properly set the Kirki URL for assets.
         *
         * @static
         * @access public
         * @return void
         */
        public static function set_url() {

                if ( Kirki_Util::is_plugin() ) {
                        return;
                }

                // Get correct URL and path to wp-content.
                $content_url = untrailingslashit( dirname( dirname( get_stylesheet_directory_uri() ) ) );
                $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );

                Kirki::$url = str_replace( $content_dir, $content_url, wp_normalize_path( Kirki::$path ) );

                // Apply the kirki/config filter.
                $config = apply_filters( 'kirki/config', array() );
                if ( isset( $config['url_path'] ) ) {
                        Kirki::$url = $config['url_path'];
                }

                // Make sure the right protocol is used.
                Kirki::$url = set_url_scheme( Kirki::$url );
        }

Feel free to close this bug if it's not related to this repository. I will try to contact Quantum Themes in the meanwhile.

mapsteps commented 2 years ago

Hello and thank you for reporting this issue.

We are closing most open GitHub issues with the release of Kirki 4 to start fresh with this major release.

If you are still running into issues after you have tested your theme with Kirki 4, please let us know so we can reopen the issue.

Please note that Kirki 3 is no longer actively supported. Moving forward, we will only provide support the very latest version of Kirki.

Thank you for your understanding.

Best, David