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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple termination of the function by adding the following just inside works to limit the field to the profile admin page only.