Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
smart-cf-register-fields のサンプル
<?php
/**
* カスタムフィールドを定義
*
* @param array $settings Smart_Custom_Fields_Setting オブジェクトの配列
* @param string $type 投稿タイプ or ロール
* @param int $id 投稿ID or ユーザーID
* @param string $meta_type post | user
* @return array
*/
function my_register_fields( $settings, $type, $id, $meta_type ) {
// SCF::add_setting( 'ユニークなID', 'メタボックスのタイトル' );
$Setting = SCF::add_setting( 'id-1', 'functions.php から追加 その1' );
// $Setting->add_group( 'ユニークなID', 繰り返し可能か, カスタムフィールドの配列 );
$Setting->add_group( 'group-name-1', false, array(
array(
'name' => 'field-1',
'label' => 'テストフィールド',
'type' => 'text',
),
array(
'name' => 'field-2',
'label' => 'テストフィール2',
'type' => 'text',
'default' => 2,
),
) );
$settings[] = $Setting;
return $settings;
}
add_filter( 'smart-cf-register-fields', 'my_register_fields', 10, 4 );
@justinticktock

This comment has been minimized.

Copy link

@justinticktock justinticktock commented Jan 24, 2016

Thanks for the code.. this provides the setting fields on all posts type (page, post, user-profile...) how would you limit to have the settings associated with only the user-profile of the 'subscriber' role?

reading through the code it does look like there is a way to do this yet..

@justinticktock

This comment has been minimized.

Copy link

@justinticktock justinticktock commented Jan 25, 2016

simple termination of the function by adding the following just inside works to limit the field to the profile admin page only.

// drop out if not on profile screen.
$screen = get_current_screen();
if ( $screen->id !== 'user-edit' ) {
       return $settings;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.