load node author uid to be used as contextual link inside template.php D7
You have just a tiny mistake , use $build['#node']->uid instead $node->uid  :)

function MYTHEME_node_view_alter(&amp;$build) { 

         $node_author = user_load($build['#node']-&gt;uid);

          // Add your own custom link
          $build['links']['node']['#links']['user-post'] = array(
            'title' =&gt; t('User post'), 
            'href' =&gt; '/userview/' . $node_author . '/post', 
            'html' =&gt; TRUE, 
            'attributes' =&gt; array(
              'title' =&gt; 'User post',
            ),
          );


        }