Adding Custom Fields to Gallery Settings

If you are a developer, then you can hook into the existing FooGallery actions and filters to do some pretty cool stuff.

One example is adding extra fields to the gallery settings. To add your own custom fields, you need to hook into the  foogallery_override_gallery_template_fields filter. These new field values will be automatically saved to the gallery settings post_meta.

You can do this in your functions.php or in a new plugin. An example:

function add_foogallery_custom_fields( $fields, $template ) {
  $fields[] = array(
	'id'      => 'custom_text',
	'title'   => __( 'Custom Text', 'foogallery' ),
	'desc'	  => __( 'A custom Text control.', 'foogallery '),
	'section' => __( 'Advanced', 'foogallery' ),
	'type'    => 'text'
  );
  
  $fields[] = array(
	'id'       => 'custom_radio',
	'title'    => __( 'Custom Radio', 'foogallery' ),
	'desc'     => __( 'A radio custom control', 'foogallery' ),
	'section'  => __( 'Advanced', 'foogallery' ),
	'type'     => 'radio',
	'default'  => '',
	'spacer'   => '<span class="spacer"></span>',
	'choices'  => array(
	  ''  => __( 'None', 'foogallery' ),
	  'value1'   => __( 'Value 1', 'foogallery' ),
	  'value2' => __( 'Value 2', 'foogallery' )
	)
  );
  
  $fields[] = array(
	'id'       => 'custom_select',
	'title'    => __( 'Custom Select', 'foogallery' ),
	'desc'     => __( 'A select custom control', 'foogallery' ),
	'section'  => __( 'Advanced', 'foogallery' ),
	'default'  => 'option1',
	'type'     => 'select',
	'choices'  => array(
		''            => __( 'None', 'foogallery' ),
		'option1'     => __( 'Option 1', 'foogallery' ),
	    'option2'     => __( 'Option 2', 'foogallery' ),
	)
  );
  
  return $fields;
}


add_filter( 'foogallery_override_gallery_template_fields', 'add_foogallery_custom_fields', 10, 2 );<br>

The above example adds 3 fields to the Advanced tab for all gallery templates.

You can then retrieve the data from the gallery using the following code:

//example loading gallery with ID of 123

$foogallery = FooGallery::get_by_id( 123 );
$custom_text_value = $foogallery->get_setting('custom_text');