• I am having problems with the switch php7.4 to php8.0: All plugins updated (NextGEN gallery is the only one I use). Theme Twenty Eleven version 4.5. WordPress 6.4.1

    With switch from php7.4 to php8.0 I get

    “error thrown call to undefined function create_function()”

    The “fatal error” seems to be linked with this theme and hints to “create_function()” in wp-config.php. I have commented this code. Now it looks

    if(is_admin()) {
    /** add_filter(‘filesystem_method’, create_function(‘$a’, ‘return “direct”;’ )); */
    define( ‘FS_CHMOD_DIR’, 0751 );
    }

    And using php8.0 everything seems to run smoothly. BUT: Is this a good idea? A more experienced IT colleague recommended

    if(is_admin()) {
    ?? ?add_filter(‘filesystem_method’, function(‘$a’){ return “direct”;});
    ???? define( ‘FS_CHMOD_DIR’, 0751 ); }

    But this results in a white screen!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • create_function() was deprecated in PHP 7.2 and officially removed in PHP 8. It can be replaced with either a named function or an anonymous function.

    Generally, I wouldn’t recommend adding filters in wp-config.php. Ideally, that should be in a custom plugin or your theme’s functions.php file.

    Here’s an example of using a named function:

    add_filter( 'filesystem_method', 'yourname_filesystem_method' );
    
    function yourname_filesystem_method( $method ) {
        return is_admin() ? 'direct' : $method;
    }

    Here’s an example of using an anonymous function:

    add_filter( 'filesystem_method', function( $method ) {
        return is_admin() ? 'direct' : $method;
    } );

    And in wp-config.php, leave the define:

    define( 'FS_CHMOD_DIR', 0751 );

    Or if you want to only define it for the admin:

    if ( is_admin() ) {
        define( 'FS_CHMOD_DIR', 0751 );
    }

    Just a little extra context: this is something that you’ve added to your wp-config.php file at some point. It’s unrelated to the theme and not a part of the default wp-config.php file in WordPress. Do you happen to know where you found the code? If you found it in a doc somewhere, maybe we can make sure it’s updated.

    Thread Starter urei

    (@urei)

    Thanks for your suggestions. I decided to go with

    if ( is_admin() ) {
        define( 'FS_CHMOD_DIR', 0751 );
    }

    which works fine!

    What I still do not understand: Since years, I just update WordPress, plugins and this theme: This was never a problem. With the switch to php8.0 – would you not assume these update strategy works as “someone” takes care of Twenty Elven (in the background) to avoid such problems?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Twenty Eleven and php8.0’ is closed to new replies.