Hook: on_profile_tab_content
avatar
Señor FAQ

¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.


Hook: on_profile_tab_content

The on_profile_tab_content hook enables developers to inject custom tab content dynamically into user profile sections. This hook is ideal for adding personalized features, such as support tickets, purchased items, and other profile-related content. This hook needs to be used in combination with the on_profile_sidebar_links hook.

Usage


DynamicShortcode::register('jscms_profile_tab_content', function () {
    $contents = DynamicHooks::executeHook('on_profile_tab_content', true);
    $output = '';
    
    foreach ($contents as $content) {
        $output .= '<div class="tab-pane fade" id="' . htmlspecialchars($content['id']) . '" role="tabpanel" aria-labelledby="' . htmlspecialchars($content['id']) . '-tab">';
        if (isset($content['callback']) && is_callable($content['callback'])) {
            $output .= call_user_func($content['callback']);
        } else {
            $output .= $content['content'] ?? '';
        }
        $output .= '</div>';
    }
    return $output;
});
    

Example Implementation


DynamicHooks::addHook('on_profile_tab_content', function () use ($jakdb, $jkv, $lang, $page1, $userGroupId) {
    $userId = JSCMS_USERID;
    $marketplaceProfile = new DynamicMarketplaceProfile($jakdb, $jkv, $lang, $userGroupId);
    return [
        [
            'id' => 'mp-support',
            'content' => $marketplaceProfile->renderSupportTab($userId),
        ],
        [
            'id' => 'mp-purchases',
            'content' => $marketplaceProfile->renderPurchasesTab($userId, $page1),
        ]
    ];
}, 'your_plugin');
    

Best Practices

  • Organize your tab IDs and content to avoid conflicts or missing data.
  • Ensure callbacks are efficient to avoid slowing down profile page loads.
  • Test all tabs thoroughly to verify content renders correctly for different users.

Troubleshooting

  • Check for errors in callback functions, such as invalid data or unhandled exceptions.
  • Use browser developer tools to inspect the HTML structure of tabs if they do not render correctly.
  • Ensure all required parameters (e.g., user ID) are passed correctly to callbacks.
Was this article helpful?
0 out of 0 found this helpful