[wp-trac] [WordPress Trac] #51340: Stop chmodding files and folders

WordPress Trac noreply at wordpress.org
Sun Mar 26 21:46:03 UTC 2023


#51340: Stop chmodding files and folders
----------------------------+------------------------------
 Reporter:  malthert        |       Owner:  (none)
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Filesystem API  |     Version:  5.3
 Severity:  major           |  Resolution:
 Keywords:  dev-feedback    |     Focuses:
----------------------------+------------------------------

Comment (by azaozz):

 Replying to [comment:8 costdev]:

 Just adding my 2c here.

 > 1. Stop using `chmod()` altogether.

 Would be nice but doesn't seem possible. Can add some error message when
 `WP_DEBUG` is true but not `doing_it_wrong`. That is reserved for
 developers that are doing something wrong, not for servers that may need
 better configuration.

 > 2. Add back error suppression for `chmod()` calls.

 This may work combined with 1 above, i.e. depend on `WP_DEBUG`.

 > 3. A constant, or filter, that allows server admins to disable `chmod()`
 calls.
 >   - The `::chmod()` method in the filesystem abstraction classes could
 check this value, and return `true` immediately.

 Yea, thinking a "short-circuit" filter is probably the best option.

 >   - A quick search shows there are ~12 instances of `chmod()` outside of
 the `::chmod()` methods in Core.

 This implies these will be a `wp_chmod()` function to run the short-
 circuit filter. Thinking that having more context there would be helpful,
 so it could be something like:
 {{{
 function wp_chmod( $path, $permissions, $context = '' ) {
     // Do something to validate/verify permissions?
     ....

     $changed = apply_filters( false, $path, $permissions, $context );

     if ( false !== $changed ) {
         return true;
     }

     return chmod( $path, $permissions );
 }
 }}}

 where `$context` would be the name of the calling class/function and will
 be passed to the filter.

 Alternatively the last bit can be:
 {{{
     if ( WP_DEBUG ) {
         return chmod( $path, $permissions );
     } else {
         return @chmod( $path, $permissions );
     }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51340#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list