Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#41329 closed defect (bug) (wontfix)

Undefined constants in class WP_Filesystem_Direct

Reported by: nabil_kadimi's profile nabil_kadimi Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9
Component: Filesystem API Keywords: has-patch
Focuses: administration Cc:

Description

I'm using the WordPress filesystem classes, it seems the classes assume some constants are always defined.

Anyways, the errors:

 Notice: Use of undefined constant FS_CHMOD_FILE - assumed 'FS_CHMOD_FILE' in /var/www/public/wp-admin/includes/class-wp-filesystem-direct.php on line 152

Notice: Use of undefined constant FS_CHMOD_FILE - assumed 'FS_CHMOD_FILE' in /var/www/public/wp-admin/includes/class-wp-filesystem-direct.php on line 152

Notice: Use of undefined constant FS_CHMOD_FILE - assumed 'FS_CHMOD_FILE' in /var/www/public/wp-admin/includes/class-wp-filesystem-direct.php on line 152

I thought I would suggest a patch...

Thanks,
Nabil

Attachments (1)

patch.diff (947 bytes) - added by nabil_kadimi 7 years ago.
Patch

Download all attachments as: .zip

Change History (9)

@nabil_kadimi
7 years ago

Patch

#1 @nabil_kadimi
7 years ago

  • Summary changed from Undefined constants in WP_class Filesystem_Direct to Undefined constants in class WP_Filesystem_Direct

#2 @theorboman
7 years ago

  • Keywords has-patch added

#3 @nabil_kadimi
7 years ago

To reproduce:

<?php
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
$filesystem = new WP_Filesystem_Direct();

This ticket was mentioned in Slack in #core by nabil_kadimi. View the logs.


7 years ago

#5 @dd32
7 years ago

  • Focuses performance removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

WP_Filesystem_Direct() is not designed to be used stand alone. Plugins shouldn't use it if they simply want to modify files directly on the filesystem, instead they should use functions such as file_get_contents() directly.

WP_Filesystem_Direct should only be accessed through using the WP_Filesystem() method (found in wp-admin/includes/file.php). If you're using it in any other way, you're complicating your own code and increasing the chances of your code breaking in the future.

#6 @nabil_kadimi
7 years ago

Thanks for your feedback @dd32, I had to use WP_Filesystem instead of file_get_contents() in order to have my theme pass Theme Checker validations.

Thanks for the advice about not using WP_Filesystem_Direct.

#7 @dd32
7 years ago

That's unfortunate, however, in that case you should still not use it directly and rather through the abstractions to allow for ftp access when needed.

Note: See TracTickets for help on using tickets.