Last active
April 30, 2022 09:26
-
-
Save inc2734/9f6d65c7473d060d0fd6 to your computer and use it in GitHub Desktop.
smart-cf-register-fields のサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
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
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..