Use of undefined constant FS_CHMOD_DIR - assumed 'FS_CHMOD_DIR'

I'm seeing an error while trying to change the colours of a theme:

Notice: Use of undefined constant FS_CHMOD_DIR - assumed 'FS_CHMOD_DIR' in
/var/www/vhosts/xxx/wp-content/themes/consulting/inc/print_styles.php on line 141

The theme creator has given me the following advice, but cannot provide any further detail:

Please contact your hosting provider team and ask to enable (set up) PHP FILE extension in your site. It will solve the problem.

I manage my server, but I have also been in contact with my hosting provider, and neither of us can figure out what needs to be done.

the closest we can find to PHP FILE is the fileinfo extension, which is already installed:

[root]# php -m | grep file
fileinfo

Can anyone shed any light on this?

Topic theme-development themes Wordpress

Category Web


I faced the same issue, it was due to the permissions of /var/www/html/* files and folders.

It was owned by root, changed the owner to www-data:www-data

cd /var/www/html
sudo chown -R www-data:www-data *

It's really quite simple. The theme author is using a constant that you can put in wp-config.php, but because you don't use that constant, and the author never checks if it's actually defined, the code throws a PHP warning

https://codex.wordpress.org/Editing_wp-config.php#Override_of_default_file_permissions

Override of default file permissions

The FS_CHMOD_DIR and FS_CHMOD_FILE define statements allow override of default file permissions. These two variables were developed in response to the problem of the core update function failing with hosts running under suexec. If a host uses restrictive file permissions (e.g. 400) for all user files, and refuses to access files which have group or world permissions set, these definitions could solve the problem. Note that the '0755' is an octal value. Octal values must be prefixed with a 0 and are not delineated with single quotes ('). See Also: Changing File Permissions

FAQ

So Who's to Blame?

The theme author for not checking if a constant is defined before using it. I've never needed this constant and i've worked on a lot of sites, and from the sounds of it neither have you.

The check is an easy thing to do:

$chmod_dir = ( 0755 & ~ umask() );
if ( defined( 'FS_CHMOD_DIR' ) ) {
    $chmod_dir = FS_CHMOD_DIR;
}

You use a variable, give it a default variable, then assign the constant to it if it exists.

What about this file PHP extension?

It's BS, a red herring, my guess is you've either been fobbed off, or the developer has made a guess, probably the latter. The constant is a WordPress constant, and you should never rely on all constants being defined ( they're mostly optional after all )

Is all of this above board?

Why would your theme need the chmod files and folders? This all sounds very suspicious, themes shouldn't be writing to the disk, especially on the frontend. That's how sites fail to scale or slow down.

I would cast a sceptical eye on the theme, it sounds from the file name like the theme is generating files and saving them in a subfolder, a massive no no, afterall there's a set of APIs for writing to the uploads folder, and you can generate and return a cacheable CSS file via PHP and rewrite rules ( there are security consequences too if you have a writable theme folder )

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.