1

I have a syntex issue on my WordPress platform since I tried to put php version on 7.4.

WordPress sent me automated email with the error below :

Error Details

An error of type E_PARSE was caused in line 12 of the file /public_html/wp-content/themes/bb-theme-child/companies.php. Error message: syntax error, unexpected 'fn' (T_FN), expecting '('

I put here the beginning of the file companies.php code and the line 12 is : function fn($function)

<?php

namespace DisplaceTech\Companies;

/**
 * Wrap function names for the namespace.
 *
 * @param string $function
 *
 * @return string
 */
function fn($function)
{
    return '\DisplaceTech\Companies\\' . $function;
}

/**
 * Add the Clients metabox to the Proposal page.
 */
function add_clients_metabox()
{
    $screens = ['page'];
    foreach ($screens as $screen) {
        add_meta_box(
            'clients',              // Unique ID
            __('Clients'),          // Box title
            fn('clients_box_html'), // Content callback, must be of type callable
            $screen,                // Post type
            'advanced',             // Context
            'high'                  // Priority
        );
    }
}
add_action('add_meta_boxes', fn('add_clients_metabox'));

NOTE: the platform works with php 7.3

2

Option 1

Have you tried changing the function name? something similar function getClientFn($function){}? You can keep any name you want.

function getClientFn($function){
    return '\DisplaceTech\Companies\\' . $function;
}

function add_clients_metabox(){
    $screens = ['page'];
    foreach ($screens as $screen) {
        add_meta_box(
            'clients',              // Unique ID
            __('Clients'),          // Box title
            getClientFn('clients_box_html'), // Content callback, must be of type callable
            $screen,                // Post type
            'advanced',             // Context
            'high'                  // Priority
        );
    }
}
add_action('add_meta_boxes', 'add_clients_metabox');

Option 2: If you really need to keep 'fn' method, then give a try with below script which works in php 7.4.

$myfunction = fn($function) => '\DisplaceTech\Companies\\' . $function;

function add_clients_metabox(){
    $screens = ['page'];
    foreach ($screens as $screen) {
        add_meta_box(
            'clients',              // Unique ID
            __('Clients'),          // Box title
            $myfunction('clients_box_html'), // Content callback, must be of type callable
            $screen,                // Post type
            'advanced',             // Context
            'high'                  // Priority
        );
    } } add_action('add_meta_boxes', 'add_clients_metabox');
6
  • yes but it doesn't work – sampaii Apr 28 '20 at 17:41
  • make sure to replace 'fn' with your new name in all appropriate places. I tried the same and it worked for me. I think you need to replace it in two more places fn('clients_box_html') & fn('add_clients_metabox') – Karthick Apr 28 '20 at 17:49
  • what you put exactly to make it work please? in my case it still not working – sampaii Apr 28 '20 at 17:56
  • @sampaii modified answer with the script I used. You can give a try. – Karthick Apr 28 '20 at 18:00
  • Thanks for the Help :) – sampaii Apr 28 '20 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.