/** * 繰り返しに設定された複数許可フィールドデータの区切り識別用データをキャッシュから取得 * * @param WP_Post|WP_User|object $object * @return mixed */ protected static function get_repeat_multiple_data_cache($object) { $Meta = new Smart_Custom_Fields_Meta($object); $id = $Meta->get_id(); $type = $Meta->get_type(); $meta_type = $Meta->get_meta_type(); if (!empty($id) && !empty($type)) { if (isset(self::$repeat_multiple_data_cache[$meta_type . '_' . $type . '_' . $id])) { return self::$repeat_multiple_data_cache[$meta_type . '_' . $type . '_' . $id]; } } }
/** * カスタムフィールド表示 table で使用する各 tr を出力 * * @param WP_Post|WP_User $object * @param bool $is_repeat * @param array $fields * @param int, null $index */ protected function display_tr($object, $is_repeat, $fields, $index = null) { $Meta = new Smart_Custom_Fields_Meta($object); $id = $Meta->get_id(); $btn_repeat = ''; if ($is_repeat) { $btn_repeat = sprintf('<span class="%s"></span>', esc_attr(SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu')); $btn_repeat .= '<span class="btn-add-repeat-group dashicons dashicons-plus-alt ' . SCF_Config::PREFIX . 'repeat-btn"></span>'; $btn_repeat .= ' <span class="btn-remove-repeat-group dashicons dashicons-dismiss ' . SCF_Config::PREFIX . 'repeat-btn"></span>'; } $style = ''; if (is_null($index)) { $style = 'style="display: none;"'; } printf('<div class="%s" %s>%s<table>', esc_attr(SCF_Config::PREFIX . 'meta-box-table'), $style, $btn_repeat); foreach ($fields as $Field) { $display_name = $Field->get_attribute('display-name'); $field_name = $Field->get('name'); $field_label = $Field->get('label'); if (!$field_label) { $field_label = $field_name; } // 複数値許可フィールドのとき if ($Field->get_attribute('allow-multiple-data')) { $value = $this->get_multiple_data_field_value($object, $Field, $index); } else { $value = $this->get_single_data_field_value($object, $Field, $index); } $notes = $Field->get('notes'); if (!empty($notes)) { $notes = sprintf('<p class="description">%s</p>', esc_html($notes)); } $form_field = $Field->get_field($index, $value); printf('<tr><th>%s</th><td>%s%s</td></tr>', esc_html($field_label), $form_field, $notes); } echo '</table></div>'; }