How to Add a Custom Field Tab

Editus allows you to add a custom tab to the post settings dialog to edit custom meta fields from the frontend. This can be useful with Advanced Custom Fields plugin or other plugins that rely on custom meta fields. Let’s say you have a custom field called “Custom Field1” and you want add it to Editus’s dialog box. Here is the end result. You can simply edit and hit “Save.”

customtab

To achieve this, you need to add a little bit of PHP codes. Your custom PHP codes can be inserted into your theme’s functions.php file. Or more preferably, you can inject the following codes using a custom php plugin.

You need to implement an Editus filter called ‘lasso_modal_tabs’ Here is the full example codes to recreate the above example. You can add multiple fields or tabs.

Note: ‘type’ can be ‘text’ ‘textarea’ ‘checkbox’ or ‘dropdown’

use lasso_public_facing\register_meta_field;

new register_meta_field(array('customfield1'=> 'trim'));

add_filter('lasso_modal_tabs','custom_tabs',10,1);
function custom_tabs( $tabs ){

    $tabs[] = array(
        'name' => 'New Tab',
	'options'	=> 'myOptionsCallback'
    );

    return $tabs;
}

function myOptionsCallback(){

	$options = array(
		array(
			'id'		=> 'customfield1',
			'name' 		=> 'Custom Field1',
			'type'		=> 'text',
			'default'	=> 'default',
			'desc'		=> 'Custom Field1'
		)
	);

	return $options;
}


Using the ‘dropdown’ type needs some changes to data fields. Here is how myOptionsCallback() function would look with the ‘dropdown’ type. In this example, we list three options.
“One” “Two” “Three” would be the text you see on the dropdown menu. “1” “2” “3” would be the values being saved.



function myOptionsCallback(){

	$options = array(
		array(
			'id'		=> 'customfield1',
			'name' 		=> 'Custom Field1',
			'type'		=> 'dropdown',
			'options'   => '1:One;2:Two;3:Three',
			'default'   => '1',
			'desc'		=> 'Custom Field1'
		)
	);

	return $options;
}