# Script Template Branda Menu Builder

Script PHP completo para construir e guardar menu Branda via WP-CLI.

---

## Template Base

```bash
mcp__ssh-unified__ssh_execute server:"server" command:"cat > /tmp/branda-menu-SITE.php << 'PHPEOF'
<?php
/**
 * Branda menu builder for SITENAME
 * Generated by /branda-menu skill
 */

function branda_id(\$slug) {
    return 'menu_item_' . substr(base_convert(md5(\$slug), 16, 32), 0, 12);
}

function native_item(\$subs = array()) {
    return array(
        'title' => '', 'id_attribute' => '', 'css_classes' => '',
        'icon_svg' => '', 'icon_url' => '', 'icon_image_id' => '',
        'dashicon' => '', 'icon_type' => '', 'custom_url' => '',
        'link_type' => '', 'link_target' => '', 'is_invisible' => '',
        'is_hidden' => '', 'was_native' => 1, 'submenu' => \$subs
    );
}

function hidden_item() {
    \$item = native_item();
    \$item['is_hidden'] = '1';
    return \$item;
}

function section_header(\$title, \$dashicon) {
    return array(
        'icon_type' => 'dashicon', 'link_type' => 'none',
        'submenu' => array(), 'title' => \$title,
        'css_classes' => 'menu-highlight', 'dashicon' => \$dashicon
    );
}

function custom_link(\$title, \$url, \$dashicon, \$target = '') {
    return array(
        'icon_type' => 'dashicon', 'link_type' => 'custom',
        'submenu' => array(), 'title' => \$title,
        'dashicon' => \$dashicon, 'link_target' => \$target,
        'custom_url' => \$url
    );
}

// === BUILD MENU ===
\$menu = array();

// 1. SUPORTE
\$menu['menu_item_sec_suporte'] = section_header('Suporte', 'dashicons-admin-tools');
\$menu['menu_item_desk_link'] = custom_link('Descomplicar', 'https://desk.descomplicar.pt/', 'dashicons-admin-comments', '_blank');

// 2. ADMIN
\$menu['menu_item_sec_admin'] = section_header('Admin', 'dashicons-admin-generic');
\$menu[branda_id('index.php')] = native_item();
\$menu[branda_id('users.php')] = native_item();
\$menu[branda_id('options-general.php')] = native_item();
\$menu[branda_id('plugins.php')] = native_item();
\$menu[branda_id('tools.php')] = native_item();

// 3. CONTEUDO
\$menu['menu_item_sec_conteudo'] = section_header('Conteudo', 'dashicons-admin-page');
\$menu[branda_id('edit.php?post_type=page')] = native_item();
// [INSERIR CPTs DO PROJECTO AQUI]
\$menu[branda_id('edit.php')] = native_item();
\$menu[branda_id('upload.php')] = native_item();
\$menu[branda_id('edit.php?post_type=acf-field-group')] = native_item();

// 4. DESIGN
\$menu['menu_item_sec_design'] = section_header('Design', 'dashicons-admin-appearance');
\$menu[branda_id('elementor-home')] = native_item();
\$menu[branda_id('edit.php?post_type=elementor_library')] = native_item();
// \$menu[branda_id('jkit')] = native_item(); // Se Jeg Kit activo
\$menu[branda_id('themes.php')] = native_item();

// 5. MARKETING
\$menu['menu_item_sec_marketing'] = section_header('Marketing', 'dashicons-megaphone');
\$menu[branda_id('fluentcrm-admin')] = native_item();
\$menu[branda_id('fluent_forms')] = native_item();
\$menu[branda_id('rank-math')] = native_item();
\$menu[branda_id('click-to-chat')] = native_item();

// 6. IDIOMAS (se multilingue)
// \$menu['menu_item_sec_idiomas'] = section_header('Idiomas', 'dashicons-translation');
// \$menu[branda_id('mlang')] = native_item();
// \$menu[branda_id('loco')] = native_item();

// 7. PERFORMANCE
\$menu['menu_item_sec_performance'] = section_header('Performance', 'dashicons-performance');
\$menu[branda_id('wpfastestcacheoptions')] = native_item();

// 8. SEGURANCA
\$menu['menu_item_sec_seguranca'] = section_header('Seguranca', 'dashicons-shield');
\$menu[branda_id('Wordfence')] = native_item();
\$menu[branda_id('complianz')] = native_item();

// 9. WEBMASTER
\$menu['menu_item_sec_webmaster'] = section_header('WebMaster', 'dashicons-admin-settings');
\$menu[branda_id('branding')] = native_item();
\$menu[branda_id('wpcode')] = native_item();

// HIDDEN
\$menu[branda_id('separator1')] = hidden_item();
\$menu[branda_id('separator2')] = hidden_item();
\$menu[branda_id('separator-last')] = hidden_item();
\$menu[branda_id('edit-comments.php')] = hidden_item();
\$menu[branda_id('hello-elementor')] = hidden_item();
\$menu[branda_id('elementor')] = hidden_item();

// SAVE
update_option('ub_custom_admin_menu', array('administrator' => \$menu));
wp_cache_flush();

\$visible = count(array_filter(\$menu, function(\$i) { return empty(\$i['is_hidden']); }));
\$hidden = count(\$menu) - \$visible;
echo "Menu guardado: \$visible visiveis + \$hidden hidden = " . count(\$menu) . " total\n";
PHPEOF
echo 'Script criado'
"

# Executar
mcp__ssh-unified__ssh_execute server:"server" command:"wp eval-file /tmp/branda-menu-SITE.php --allow-root --path=/home/USER/SITE"
```

---

## Adaptacoes por Tipo de Site

### Sites multilingue (Polylang/WPML)

Descomentar seccao Idiomas no script. Adicionar:
```php
$menu['menu_item_sec_idiomas'] = section_header('Idiomas', 'dashicons-translation');
$menu[branda_id('mlang')] = native_item(); // Polylang
$menu[branda_id('loco')] = native_item(); // Loco Translate
```

### Sites WooCommerce

Adicionar seccao e-Commerce entre Marketing e Idiomas:
```php
$menu['menu_item_sec_ecommerce'] = section_header('e-Commerce', 'dashicons-cart');
$menu[branda_id('woocommerce')] = native_item();
```

### Sites Care (KiviCare)

Adicionar seccao Clinica entre Marketing e Idiomas:
```php
$menu['menu_item_sec_clinica'] = section_header('Clinica', 'dashicons-heart');
$menu[branda_id('kivicare-...')] = native_item(); // Verificar slug exacto
```

### CPTs customizados

Adicionar na seccao Conteudo, antes de Artigos:
```php
$menu[branda_id('edit.php?post_type=SLUG_CPT')] = native_item();
```

### Itens desconhecidos

Se o menu nativo tiver itens que nao encaixam no mapeamento standard:
1. Perguntar ao utilizador onde colocar
2. Se plugin temporario/teste: adicionar ao Hidden
3. Se plugin permanente: criar seccao propria ou adicionar a seccao existente
