Home›Support›English Support›[Escalated to WPML Developers team] WPML incorrectly uses WP_Filesystem_Direct directly instead of using $wp_filesystem global breaking ...
[Escalated to WPML Developers team] WPML incorrectly uses WP_Filesystem_Direct directly instead of using $wp_filesystem global breaking ...
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Background of the issue:
WPML and WCML use WP_Filesystem_Direct directly instead of using the $wp_filesystem global e.g. in
sitepress-multilingual-cms/classes/utilities/class-wpml-flags-factory.php
sitepress-multilingual-cms/classes/wpml-wp/class-wpml-wp-api.php
woocommerce-multilingual/addons/wpml-dependencies/lib/classes/wpml-wp/class-wpml-wp-api.php
There are more files and this issue also exists in wpml-string-translation plugin
This is a problem bc in WP core the filesystem is filterable: $abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
For security reasons we have extended the WP_Filesystem_Direct class and filtered it on WP filter
However, WPML won't use it but instead incorrectly instantiates WP_Filesystem_Direct separately.
This is wrong and not how WP Filesystem classes should be used.
Use the $wp_filesystem global instead, just like all other plugins too.
Symptoms:
Custom filesystem class is not used
Questions:
Why does WPML use WP_Filesystem_Direct directly instead of the $wp_filesystem global?
What's extra annoying is that you also require_once that class - so if we reuse the identical class name to work around the other stuff, but filter in our path, it will result in a fatal error, since you load the original class in sitepress-multilingual-cms\classes\utilities\class-wpml-flags-factory.php (and sitepress-multilingual-cms\classes\wpml-wp\class-wpml-wp-api.php)
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+01:00)
According to our older commits this may have been done intentionally because of restrictions from the WP_Filesystem object not providing the proper file path.
That being said can you give us some context where this causes you issues (e.g. plugin or a theme update or similar)?
Everywhere, because anything you try with WP_Filesystem_Direct fails, bc it's not supported on one of our systems. That's why we use the WP core filters to implement our own filesystem that implements the file system we use.
It's a similar system like WordPress itself provides in WP VIP hidden link