Adding to User pages

Userpages are highly programmable and extensible using a number of hooks. These hooks are:

  • userpage_sidebar_left
  • userpage_sidebar_right
  • userpage_tabs_links
  • userpage_tabs_body

You can add a variety of sections to user pages, including new tabs and new sections on the tables. To add a tab, attach to userpage_tabs_links and echo out:

<li><a href="#tab:YOURTABID">YOUR TAB TEXT</a></li>

Then hook into userpage_tabs_body and print:

<div id="tab:YOURTABID">YOUR TAB CONTENT</div>

The userpage javascript runtime will take care of everything else, meaning transitions, click events, etc. Currently it's not possible to add custom click events to tabs, but any DOM-related JS that needs to run in your tab can be run onload and the effects will be seen when your tab is clicked. YOURTABID should be lowercase alphanumeric and have a short prefix so as to assure that it is unique to your plugin.

To hook into the "profile" tab, use the hooks userpage_sidebar_left and userpage_sidebar_right. Just echo out table cells as normal. The table on the left (the wide one) has four columns, and the one on the right has one column.

Examples

Adding a new tab

$plugins->attachHook('userpage_tabs_links', 'blog_userpage_tab_setup();');
$plugins->attachHook('userpage_tabs_body', 'blog_userpage_body($userdata, $this);');
 
function blog_userpage_tab_setup()
{
  echo '<li><a href="#tab:blog">Blog</a></li>';
}
 
function blog_userpage_body($userdata, $page)
{
  echo '<div id="tab:blog">';
  $blog = blog_index($userdata['username'], true, 5, $page);
  if ( $blog )
  {
    echo $blog;
  }
  else
  {
    echo '<h3>No blog</h3>';
    echo '<p>' . htmlspecialchars($userdata['username']) . ' doesn\'t have a blog.</p>';
  }
  echo '</div>';
}

Adding a new field on Profile

Note: The strings here are quoted using the relatively uncommon heredoc string syntax.

$plugins->attachHook('userpage_sidebar_left',  'myplugin_profile_left();');
$plugins->attachHook('userpage_sidebar_right', 'myplugin_profile_right();');
 
function myplugin_profile_left()
{
  echo <<<EOF
  <tr>
    <td class="row1" colspan="2">
      Hello world! (Profile left 1)
    </td>
    <td class="row1" colspan="2">
      Hello world! (Profile left 2)
    </td>
  </tr>
EOF;
}
 
function myplugin_profile_right()
{
  echo <<<EOF
  <tr>
    <td class="row2">
      Hello world! (Profile right)
    </td>
  </tr>
EOF;
}

Categories: (Uncategorized)