]\s+)'. $abbreviation .'(\s+[^)(?:^|\s+))' . $abbr[0] . '((?:,?|.?)\s+(?!<\/abbr>))/s',
'$1' . esc_html( $abbr[0] ) . '$2',
$content, 1);
}
return $content;
});
add_action('admin_menu', function() {
add_options_page('Abbreviations', 'Abbreviations', 'manage_options', 'abbreviations',
function() {
// check user capabilities
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// show error/update messages
settings_errors( 'abbreviations' );
?>
' . __('Settings', 'abbreviations') . '',
);
$actions = array_merge( $actions, $links );
return $actions;
} );
add_action( 'admin_init', function() {
$args = array(
'type' => 'array',
'sanitize_callback' => function($value) {
$res = [];
$all_abbrs = [];
foreach ($value as $item) {
$abbr = sanitize_text_field($item[0]);
$desc = sanitize_text_field($item[1]);
$lang = sanitize_text_field($item[2]);
if ($abbr && $desc && !in_array($abbr, $all_abbrs)) {
$res[] = [$abbr, $desc, $lang];
$all_abbrs[] = $abbr;
}
}
return $res;
},
'default' => [],
);
register_setting( 'abbreviations', 'abbreviations', $args );
// Register a new section in the "abbreviations" page.
add_settings_section(
'abbreviations',
'',
null,
'abbreviations'
);
add_settings_field(
'abbreviations_field', // As of WP 4.6 this value is used only internally.
null,
// output function is none, we rely on form data due to 3 column headers impossible to print via WP API
null,
'abbreviations',
'abbreviations'
);
});