Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Incorrect WP_Filesystem initialization for FS_METHOD is other than ‘direct’ ?

$
0
0

Replies: 0

* Reproducing step:

1. Define FS_METHOD to ‘ftpsockets’ or ‘ftpext’.
2. Set up the plugin with default Downloads Folder.
3. In templates page, create or update any template.

* The occurrence:

An error displays:

ERROR - Failed to create custom template. Please set up recursive Read-Write permissions for
(I’m not intended to mask a path, it’s truly empty, string ends with “for”)

and absolutely, template file is not written.

* The cause of above:

AmazonAssociatesLinkBulder\helper\Plugin_Helper::aalb_get_uploads_dir_path() fails (returns false).

* The cause of above:

Perhaps incorrect WP_Filesystem initialization.


# helper/plugin_helper.php L205~
    /**
     * Loads necessary files and initializes WP Filesystem API
     *
     * @since 1.3
     */
    public function aalb_initialize_wp_filesystem_api() {
        require_once( ABSPATH . 'wp-admin/includes/file.php' );
        WP_Filesystem();
    }

WP_Filesystem usually needs arguments, which usually come from
request_filesystem_credentials();

https://codex.wordpress.org/Filesystem_API

* A proposed solution:

Fix initialization of WP_Filesystem to be more correct way.

* A workaround (works in my env at least):

It gets working with this hot fix below.


# helper/plugin_helper.php L205~
    /**
     * Loads necessary files and initializes WP Filesystem API
     *
     * @since 1.3
     */
    public function aalb_initialize_wp_filesystem_api() {
        require_once( ABSPATH . 'wp-admin/includes/file.php' );

        $credentials = request_filesystem_credentials( $url );

        WP_Filesystem($credentials);
    }

where all of those constants defined.
* define(‘FS_METHOD’, ‘ftpsockets’);
* define(‘FTP_USER’, ‘xxxx’);
* define(‘FTP_PASS’, ‘xxx’);
(the hot fix not excepting to show ftp dialog, thus it must be given)
* define(‘FTP_HOST’, ‘localhost’);


Viewing all articles
Browse latest Browse all 59525

Trending Articles