はい、できます。
/wp-admin/includes/class-wp-list-table.php
WP テーブルの仕組み -すべてのテーブル (投稿、カテゴリ、ユーザー、メディアなど) の基礎として使用されるクラス 'WP_List_Table' ( ) があり、それらのテーブルを作成するためのエクステンダーが作成されます。 . class-wp-terms-list-table.php
のinline_edit()
関数には、フックaction
する必要がある があります。
行 356+ 読み取り -
foreach ( $columns as $column_name => $column_display_name ) {
if ( isset( $core_columns[$column_name] ) )
continue;
do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $tax->name );
}
これの利点は、必要に応じて、カスタム コンテンツの WP 標準テーブルのように見えるテーブルを作成できることです。これは、プラグイン開発者、またはユーザーがそれほど高度ではなく、1 つの形式のテーブルだけで「快適」に感じるサイトの管理者にとって特に便利です。
クイック編集にボックスを追加するには、以下のようなものが必要です。上部の 3 つの変数は、独自の設定に変更する必要があります。これは、フィールドを「編集」タクソノミー画面に追加したときに定義する必要があります。
/**
* Adds columns to quick edit
*
* @param $column_name string The name of the column that is currently being actioned
* @param $screen string The screen that is currently being viewed
* @param $tax string The name of the Taxonomy whose Terms are being listed
* @return string Current value of the sort_order setting
*/
function my_custom_box( $column_name, $screen, $name ) {
$my_fields = array(
array(
'column_name' => 'archive_headline',
'field_title' => 'Archive Headline',
'field_name' => 'archive_headline',
),
array(
'column_name' => 'archive_intro_text',
'field_title' => 'Archive Intro Text',
'field_name' => 'archive_intro_text',
)
);
foreach ($my_fields as $field) :
if ( $column_name === $field['column_name'] && $screen === 'edit-tags' ) :
print( '<fieldset><div class="inline-edit-col">' );
print( '<label>' );
printf( '<span class="title">%1$s</span>', _e( $field['field_title'] ) );
printf( '<span class="input-text-wrap"><input type="text" name="%1$s" class="ptitle" value=""></span>', $field['field_name'] );
print( '</label>' );
print( '</div></fieldset>' );
endif;
endforeach;
}
add_action( 'quick_edit_custom_box', 'my_custom_box', 10, 3 );
編集
テーブル自体ではなく、値をテーブルのクイック編集セクションに入れたいと述べました。これは可能ですが、データを非表示にする必要があります。クイック編集セクションは、テーブルのデータを使用して AJAX 経由で入力されるため、そこにある必要があります。
以下のコードを使用して列を追加できます (データがどこから来るのかわからないため、実際にデータを取得する場所のビットを修正するだけで済みます)。
/**
* Add custom data to tables with a low priority, so that post types and taxonomies have already been added
*/
add_action('init', 'add_custom_columns', 110, 0);
function add_custom_columns(){
$taxonomy = 'post_tag';
/** Add the column */
add_filter("manage_edit-{$taxonomy}_columns", 'show_custom_tag_columns', 5);
/** Populate the column */
add_action("manage_{$taxonomy}_custom_column", 'fill_custom_tag_columns_by_return', 5, 3);
}
/**
* Shows custom columns and removes built-in ones based on the page being shown
*
* @param required array $columns The current columns for the table
* @return array $columns The updated columns array
*/
function show_custom_tag_columns($columns){
if($pagenow === 'edit-tags.php' && !isset($_GET['post_type'])) :
$columns['archive_headline'] = __('Archive Headline');
$columns['archive_intro_text'] = __('Archive Intro Text');
endif;
}
/**
* Adds the IDs to the ID column where data must be returned
*
* @param required array $value Not sure what this is...
* @param required array $column_name The name of the current column
* @param required array $object_id The object ID
* @return array $defaults Updated list of table columns
*/
function fill_custom_tag_columns_by_return($column_values, $column_name, $object_id){
global $wpdb;
echo $column_values; // Output any pre-existing column values so they don't get over written
if($column_name === 'archive_headline') :
// Do what ever you do to get the data for this column
return $archive_headline;
endif;
if($column_name === 'archive_intro_text') :
// Do what ever you do to get the data for this column
return $archive_intro_text;
endif;
}
列を非表示にするには、次の CSS を追加します -
table.widefat th.column-archive_headline,
table.widefat th.column-archive_intro_text{
display: none;
}