/**
  * フック経由でカスタムフィールドを設定
  *
  * @param array $settings 管理画面で設定された Smart_Custom_Fields_Setting の配列
  * @param string $type 投稿タイプ or ロール
  * @param int $id 投稿ID or ユーザーID
  * @param string $meta_type メタデータのタイプ。post or user
  * @return array
  */
 public function _register($settings, $type, $id, $meta_type)
 {
     // SCF::add_setting( 'ユニークなID', 'メタボックスのタイトル' );
     if (type === 'category') {
         $Setting = SCF::add_setting('id-1', 'Register Test');
         // $Setting->add_group( 'ユニークなID', 繰り返し可能か, カスタムフィールドの配列 );
         $Setting->add_group(0, false, array(array('name' => 'text', 'label' => 'text field', 'type' => 'text')));
         $Setting->add_group(1, false, array(array('name' => 'checkbox', 'label' => 'checkbox field', 'type' => 'check', 'choices' => array(1, 2, 3))));
         $Setting->add_group('group-name-3', true, array(array('name' => 'text3', 'label' => 'text field 3', 'type' => 'text'), array('name' => 'checkbox3', 'label' => 'checkbox field 3', 'type' => 'check', 'choices' => array(1, 2, 3))));
         $settings['id-1'] = $Setting;
         $Setting = SCF::add_setting('id-2', 'Register Test 2');
         $Setting->add_group(0, false, array(array('name' => 'text2-1', 'label' => 'text field 2-1', 'type' => 'text')));
         $settings['id-2'] = $Setting;
     }
     return $settings;
 }
 /**
  * フック経由でカスタムフィールドを設定
  *
  * @param array $settings 管理画面で設定された Smart_Custom_Fields_Setting の配列
  * @param string $type 投稿タイプ or ロール
  * @param int $id 投稿ID or ユーザーID
  * @param string $meta_type メタデータのタイプ。post or user
  * @return array
  */
 public function _register($settings, $type, $id, $meta_type)
 {
     // SCF::add_setting( 'ユニークなID', 'メタボックスのタイトル' );
     if ($type === 'post' && ($id === $this->post_id || $id === $this->revision_id) || $type === 'editor') {
         $Setting = SCF::add_setting('id-1', 'Register Test');
         // $Setting->add_group( 'ユニークなID', 繰り返し可能か, カスタムフィールドの配列 );
         $Setting->add_group(0, false, array(array('name' => 'text', 'label' => 'text field', 'type' => 'text')));
         $Setting->add_group(1, false, array(array('name' => 'checkbox', 'label' => 'checkbox field', 'type' => 'check', 'choices' => array(1, 2, 3))));
         $Setting->add_group('group-name-3', true, array(array('name' => 'text3', 'label' => 'text field 3', 'type' => 'text'), array('name' => 'checkbox3', 'label' => 'checkbox field 3', 'type' => 'check', 'choices' => array(1, 2, 3))));
         $settings['id-1'] = $Setting;
     }
     return $settings;
 }
示例#3
0
 /**
  * Setting オブジェクトの配列を取得(プロフィール用)
  *
  * @param WP_User $object
  * @param array $settings_posts
  * @return array
  */
 protected static function get_settings_for_profile($object, $settings_posts)
 {
     $settings = array();
     foreach ($settings_posts as $settings_post) {
         if (self::get_settings_cache($settings_post->ID) !== null) {
             self::debug_cache_message("use settings cache. [id: {$settings_post->ID}]");
             $settings[] = self::get_settings_cache($settings_post->ID);
             continue;
         }
         self::debug_cache_message("dont use settings cache... [id: {$settings_post->ID}]");
         $Setting = SCF::add_setting($settings_post->ID, $settings_post->post_title);
         $settings[] = $Setting;
         self::save_settings_cache($settings_post->ID, $Setting);
     }
     return $settings;
 }
 /**
  * フック経由でカスタムフィールドを設定
  *
  * @param array $settings 管理画面で設定された Smart_Custom_Fields_Setting の配列
  * @param string $type 投稿タイプ or ロール or タクソノミー
  * @param int $id 投稿ID or ユーザーID or タームID
  * @param string $meta_type メタデータのタイプ。post or user or term
  * @return array
  */
 public function _register($settings, $type, $id, $meta_type)
 {
     // SCF::add_setting( 'ユニークなID', 'メタボックスのタイトル' );
     if ($type === 'post' && $id === $this->post_id || $type === 'post' && $id === $this->new_post_id || $type === 'editor' || $type === 'category') {
         $Setting = SCF::add_setting('id-1', 'Register Test');
         // $Setting->add_group( 'ユニークなID', 繰り返し可能か, カスタムフィールドの配列 );
         $Setting->add_group(0, false, array(array('name' => 'text', 'label' => 'text field', 'type' => 'text')));
         $Setting->add_group(1, false, array(array('name' => 'checkbox', 'label' => 'checkbox field', 'type' => 'check', 'choices' => array(1, 2, 3))));
         $Setting->add_group('group-name-3', true, array(array('name' => 'text3', 'label' => 'text field 3', 'type' => 'text'), array('name' => 'checkbox3', 'label' => 'checkbox field 3', 'type' => 'check', 'choices' => array(1, 2, 3))));
         $Setting->add_group('group-name-4', false, array(array('name' => 'text-has-default', 'label' => 'text has default', 'type' => 'text', 'default' => 'text default'), array('name' => 'text-has-not-default', 'label' => 'text has not default', 'type' => 'text'), array('name' => 'checkbox-has-default', 'label' => 'checkbox has default', 'type' => 'check', 'choices' => array('A', 'B', 'C'), 'default' => "A\nB\nX"), array('name' => 'checkbox-has-not-default', 'label' => 'checkbox has not default', 'type' => 'check', 'choices' => array('A', 'B', 'C'))));
         $settings['id-1'] = $Setting;
     }
     return $settings;
 }
    /**
     * 投稿画面にカスタムフィールドを表示
     */
    public function display_meta_box()
    {
        $Setting = SCF::add_setting(get_the_ID(), get_the_title());
        $Setting->add_group_unshift();
        $groups = $Setting->get_groups();
        ?>
		<div class="<?php 
        echo esc_attr(SCF_Config::PREFIX . 'fields-wrapper');
        ?>
">
			<div class="<?php 
        echo esc_attr(SCF_Config::PREFIX . 'groups');
        ?>
">
			<?php 
        foreach ($groups as $group_key => $Group) {
            ?>
				<?php 
            $fields = $Group->get_fields();
            array_unshift($fields, SCF::get_form_field_instance('text'));
            ?>
				<div class="<?php 
            echo esc_attr(SCF_Config::PREFIX . 'group');
            ?>
 <?php 
            $this->add_hide_class($group_key);
            ?>
">
					<div class="btn-remove-group"><span class="dashicons dashicons-no-alt"></span></div>
					<?php 
            $Group->display_options($group_key);
            ?>

					<div class="<?php 
            echo esc_attr(SCF_Config::PREFIX . 'fields');
            ?>
">
						<?php 
            foreach ($fields as $field_key => $Field) {
                ?>
						<div class="<?php 
                echo esc_attr(SCF_Config::PREFIX . 'field');
                ?>
 <?php 
                $this->add_hide_class($field_key);
                ?>
">
							<?php 
                $field_label = $Field->get('label');
                if (!$field_label) {
                    $field_label = $Field->get('name');
                    if (!$field_label) {
                        $field_label = "&nbsp;";
                    }
                }
                ?>
							<div class="<?php 
                echo esc_attr(SCF_Config::PREFIX . 'icon-handle');
                ?>
"></div>
							<b class="btn-remove-field"><span class="dashicons dashicons-no-alt"></span></b>
							<div class="field-label"><?php 
                echo esc_html($field_label);
                ?>
</div>
							<table class="<?php 
                $this->add_hide_class(!$Field->get('name'));
                ?>
">
								<tr>
									<th><?php 
                esc_html_e('Type', 'smart-custom-fields');
                ?>
<span class="<?php 
                echo esc_attr(SCF_Config::PREFIX . 'require');
                ?>
">*</span></th>
									<td>
										<select
											name="<?php 
                echo esc_attr($Field->get_field_name_in_setting($group_key, $field_key, 'type'));
                ?>
"
											class="<?php 
                echo esc_attr(SCF_Config::PREFIX . 'field-select');
                ?>
" />
											<?php 
                foreach ($this->optgroups as $optgroup_name => $optgroup_values) {
                    $optgroup_fields = array();
                    $optgroup_values['options'] = apply_filters(SCF_Config::PREFIX . 'field-select-' . $optgroup_name, $optgroup_values['options']);
                    foreach ($optgroup_values['options'] as $option_key => $option) {
                        $optgroup_fields[] = sprintf('<option value="%s" %s>%s</option>', esc_attr($option_key), selected($Field->get_attribute('type'), $option_key, false), esc_html($option));
                    }
                    printf('<optgroup label="%s">%s</optgroup>', $optgroup_values['label'], implode('', $optgroup_fields));
                }
                ?>
										</select>
									</td>
								</tr>
								<?php 
                $Field->display_options($group_key, $field_key);
                ?>
							</table>
						</div>
						<?php 
            }
            ?>
					</div>
					<div class="button btn-add-field <?php 
            $this->add_hide_class($Group->is_repeatable());
            ?>
"><?php 
            esc_html_e('Add Sub field', 'smart-custom-fields');
            ?>
</div>
				</div>
			<?php 
        }
        ?>
			</div>
			<div class="button btn-add-group"><?php 
        esc_html_e('Add Field', 'smart-custom-fields');
        ?>
</div>
		</div>
		<?php 
        wp_nonce_field(SCF_Config::NAME . '-settings', SCF_Config::PREFIX . 'settings-nonce');
        ?>
		<?php 
    }