Unexpected ‘{‘ in field name when doing string formatting

You need to double any { or } that are not part of a formatting placeholder. For example, you have:

function admin_add_{fieldname}_field( $fields ) {
    [....]
}

in the string. The { at the end of the first line and } on the last are not part of a placeholder. Replace them with {{ and }} respectively:

function admin_add_{fieldname}_field( $fields ) {{
    [....]
}}

Doubling up those curly braces escapes them; the final output will contain single { and } characters again.

In the full string you used, that’d be:

code=""'
// {label}
add_filter( 'submit_job_form_fields', 'frontend_add_{fieldname}_field' );
function frontend_add_{fieldname}_field($fields) {{
    $fields['job']['job_{fieldname}'] = array(
        'label' => __('{label}', 'job_manager'),
        'type' => 'text',
        'required' => {required},
        'priority' => 7,
        'placeholder' => '{placeholder}'
    );
    return $fields;
}}
add_filter( 'job_manager_job_listing_data_fields', 'admin_add_{fieldname}_field' );
function admin_add_{fieldname}_field( $fields ) {{
  $fields['_job_{fieldname}'] = array(
    'label'       => __( '{label}', 'job_manager' ),
    'type'        => 'text',
    'placeholder' => '{placeholder}',
    'description' => ''
  );
  return $fields;
}}
'''

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)