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
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
Share Improve this question asked Apr 28, 2020 at 16:52 SamuelSamuel 3541 gold badge11 silver badges32 bronze badges1 Answer
Reset to default 2Option 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');