简体   繁体   中英

Development workflow for Wordpress using git - need to override get_bloginfo('wpurl')

I'm going with this git workflow for my current wordpress project which I'm running locally using MAMP . It allows me to separate the WP core files from the theme and plugin folders using submodules, which is great. My wp-config has some extra entries to tell Wordpress where the core files are and where the theme folders are:

if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/wordpress/');

define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/core');
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/core/wordpress');
define('WP_CONTENT_DIR', realpath(ABSPATH . '../wp-content/'));
define('WP_CONTENT_URL', WP_HOME . '/wp-content');
define('UPLOADS', '../wp-content/uploads');

My structure from the site root looks like:

-wordpress (contains core files)
-wp-content
    -themes
    -plugins
    -uploads
-wp-config.php

So my home url is: http://localhost:8888/core/

The issues I'm running into all over is with the plugins. Some of them are using get_bloginfo('wpurl') to load assets. So an example of that would look like this:

http://localhost:8888/core/wordpress/wp-content/plugins/{PLUGIN}/images/{PLUGIN_IMAGE}.png

where it should actually be:

http://localhost:8888/core/wp-content/plugins/{PLUGIN}/images/{PLUGIN_IMAGE}.png

Can I override this somehow without modifying the plugins individually?

UPDATE

This works but I need to limit it only to when plugins are called:

function alter_site_url($url) {
    return str_replace('/core/wordpress', '/core', $url);
}

add_filter('site_url', 'alter_site_url');

get_bloginfo('wpurl') calls site_url() behind the scenes, which in turn calls get_site_url() . get_site_url() has a filter, site_url , that you could use to change the value returned by the function.

This answer has an example of how you could add it. Bear in mind that that would change it globally, and could cause other problems (things that are currently working could start breaking).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM