Take WP_CONTENT_DIR and WP_CONTENT_URL into consideration
-
Hey there!
Still super happy with your plugin.
I’m using a custom config on a site with specific paths forwp-content/
(WordPress allows to change this) and the plugin doesn’t take it into account.In fact, the wp-content is in
/uploads/
(at the root) and this is declared with WordPress constants in thewp-config.php
.
-
Hello @buzut,
Thanks for your message.
See the plugin FAQ for information on how to use filters to change directory paths. Have you tried this?
Best,
Mateusz@buzut You are right, but it is not easy. I don’t know what someone can enter there and at this point there is a risk that it will not work or it will work wrong
My assumption is that if someone uses such constants, it means that they have more knowledge and can use plugin filters.
Did you manage to configure everything using filters?
I haven’t tried yet. I was waiting for your answer actually.
My assumption is that if someone uses such constants, it means that they have more knowledge and can use plugin filters.
That is true, it’s pretty easy to use filters, but imagine if each plugin needed its own filters when deriving from standard install…
I don’t know what someone can enter there and at this point there is a risk that it will not work or it will work wrong
If wrong data is entered, apart from your plugin, that would be the whole WP install that would behave in a weird way or just break.
You could just check whether the directory exists, and if it does, assume it’s all good.It’s actually a usual way of doing things when using WordPress as a framework and managing dependencies with composer (wordplate, bedrock…).
I’m developing a starter theme based on these concepts: https://github.com/Buzut/steroids
Best,
Quentin- This reply was modified 3 years, 3 months ago by buzut.
@buzut Can you please give me what values you gave in these two constants?
Can you also go to the plugin settings, to the “Server configuration” tab (the button is on the right in the widget) and take a screenshot of the configuration you have by default, without using filters.
Sure, in my case, the uploads lies at the root, so:
define('WP_HOME', 'https://my-web-site.com');
define('WP_CONTENT_DIR', __DIR__);
define('WP_CONTENT_URL', WP_HOME);
In this case, __DIR__ translates to
/home/alphapole/public/
@buzut Thank you for the information.
Soon I am planning a new version of the plugin, which, among other things, will refine the support of filters for changing directory paths. Unfortunately, I am not able to implement support for these constants as it would mean incompatibility for users already using these filters.
I am responsible for 70,000 users of the plugin and cannot do this although I agree with you and you are right. I hope that you understand me.
Please check the plugin version that is waiting in my repository for the release of the update:
https://gbiorczyk.pl/webp-converter-for-media-v3.0.5.zipUsing the following filters you can add support for the constants WP_CONTENT_DIR and WP_CONTENT_URL:
add_filter( 'webpc_dir_name', function( $value, $directory ) { return str_replace( 'wp-content/', '', $value ); }, 10, 2 ); add_filter( 'webpc_site_root', function( $path ) { return WP_CONTENT_DIR; } ); add_filter( 'webpc_site_url', function( $path ) { return WP_CONTENT_URL; } );
Does this solve your problem?
It sure works and I understand you can’t break backwards compatibility.
Just had a look at the code, love how clean it is (not always the case in WP plugins sadly), good work man!
Also, while maintaining backwards compatibility, couldn’t you just check for filters, if some are hooked, don’t change anything. If none are hooked and
WP_CONTENT_DIR
is declared, you can safely take the constant into consideration.Checking for filters is as simple as looking into
$wp_filter['my_hook']
.Cheers,
Quentin@buzut Thank you for your cooperation. I am glad that filters works. The next plugin update will be released within a few days and the changes will be valid for you after its release.
Thanks mate 👍
- The topic ‘Take WP_CONTENT_DIR and WP_CONTENT_URL into consideration’ is closed to new replies.