Zum Inhalt

Admin und Optionen

AddPostTypeMetaFields

Ergänzt Meta-Boxen für einen Posttype. Optional nur für bestimmte Posts.

  • Filter: twtheme_{post_type}_fields
  • Optional: {post_type}_{hook_name}_fields für gezielte Posts
new TwthemeAddPostTypeMetaFields('example', 'Beispiel Daten');

add_filter('twtheme_example_fields', function () {
  return [
    [
      'title' => 'Allgemein',
      'id' => 'general',
      'fields' => [
        ['type' => 'text', 'id' => 'subtitle', 'name' => 'subtitle', 'label' => 'Untertitel'],
      ],
    ],
  ];
});

Für einzelne Posts:

new TwthemeAddPostTypeMetaFields('page', 'Spezial', 'landing', [12, 34]);

add_filter('page_landing_fields', function ($fields) {
  // Felder nur für die angegebenen Posts
  return $fields;
});

AddCommentMetaFields

Fügt Felder zur Kommentar-Ansicht im Backend hinzu.

  • Filter: comment_fields
  • Speicherung: update_comment_meta je Tab
new TwthemeAddCommentMetaFields('Kommentar Details');

add_filter('comment_fields', function () {
  return [
    [
      'title' => 'Info',
      'id' => 'info',
      'fields' => [
        ['type' => 'text', 'id' => 'source', 'name' => 'source', 'label' => 'Quelle'],
      ],
    ],
  ];
});

AddMenuMetaFields

Erweitert Menüeinträge um eigene Felder. Die Daten werden unter _mega-menu am Menü-Item gespeichert.

  • Filter: twtheme_menu_fields
  • Kontext: TwthemeFieldBuilder::output(..., 'menu', $item_id)
new TwthemeAddMenuMetaFields('Mega Menu');

add_filter('twtheme_menu_fields', function ($fields, $item_id) {
  return [
    [
      'title' => 'Mega Menu',
      'id' => 'mega-menu',
      'fields' => [
        ['type' => 'text', 'id' => 'subtitle', 'name' => 'subtitle', 'label' => 'Untertitel'],
      ],
    ],
  ];
});

Wichtig: Die Felddaten liegen pro Menü-Item unter _mega-menu.

AddProfileMetaFields

Ergänzt das Benutzerprofil um eigene Felder.

  • Filter: twtheme_profile_fields
  • Speicherung: update_user_meta je Tab
new TwthemeAddProfileMetaFields('Profil Zusatzfelder');

add_filter('twtheme_profile_fields', function () {
  return [
    [
      'title' => 'Profil',
      'id' => 'profile',
      'fields' => [
        ['type' => 'text', 'id' => 'phone', 'name' => 'phone', 'label' => 'Telefon'],
      ],
    ],
  ];
});

CreateOptionPage

Erstellt eine Optionsseite im Backend (Hauptmenü oder Submenü).

  • Filter: {menu_slug}_option_fields
  • Validierung: twtheme_options_post_data
new TwthemeCreateOptionPage(
  '',
  'Theme Optionen',
  'Theme Optionen',
  'manage_options',
  'twtheme-options',
  'dashicons-admin-generic',
  60
);

add_filter('twtheme-options_option_fields', function () {
  return [
    [
      'title' => 'Allgemein',
      'id' => 'general',
      'fields' => [
        ['type' => 'text', 'id' => 'brand', 'name' => 'brand', 'label' => 'Brand'],
      ],
    ],
  ];
});