acp/layouts

This Filter acp/layouts allows you to add or removed layouts by code.

Usage

You can just remove the layout from the passed array or you can create your own layout by the API and add your own column.

/**
 * Filter the list of available layouts and add/remove layouts
 *
 * @param array $layouts
 * @param string $list_screen_key
 *
 * @return array
 */
function my_acp_custom_layouts( $layouts, $list_screen_key ) {

	// Check for if you're on a specific list screen
	// add or remove layouts

	return $layouts;
}

add_filter( 'acp/layouts', 'my_acp_custom_layouts', 10, 2 );

Example

In the following example we use theĀ acp/layouts filter to add a new layout and use theĀ ac/list_screen/settings action to add columns to the layout.

<?php

/**
 * @param array  $layouts
 * @param string $list_screen_key
 *
 * @return array
 */
function my_acp_custom_layouts_test( $layouts, $list_screen_key ) {
	// Only add layout for posts overview, otherwise bail early
	if( 'post' != $list_screen_key ){
		return $layouts;
	}

	$list_screen = AC()->get_list_screen( $list_screen_key );
	if ( ! $list_screen ) {
		return $layouts;
	}

	$layout = new ACP_Layout( array(
		'id'   => 'my_custom_layout',
		'name' => 'My Custom Layout',
	) );

	$layout->set_editable( false );
	$layouts[ $layout->get_id() ] = $layout;

	return $layouts;
}

add_filter( 'acp/layouts', 'my_acp_custom_layouts_test', 10, 2 );

/**
 * @param $list_screen AC_ListScreen
 */
function set_php_stored_columns( $list_screen ){
	// only work on our own custom created layout
	$settings_key = $list_screen->get_key() . 'my_custom_layout';

	if ( $list_screen->get_storage_key() === $settings_key ) {

		$list_screen->set_settings( array(
			// Add an array of column conform the export feature
			'58afe673eab51' => array(
				'type'         => 'column-meta',
				'label'        => 'My Custom Field',
				'width'        => '',
				'width_unit'   => '%',
				'field'        => 'my_cf',
				'field_type'   => '',
				'before'       => '',
				'after'        => '',
				'edit'         => 'on',
				'sort'         => 'on',
				'filter'       => 'on',
				'filter_label' => '',
			),
		) );
		$list_screen->set_read_only( true );
	}

}

add_action( 'ac/list_screen/settings', 'set_php_stored_columns' );