In a simple WordPress plugin, I redirected commentator links to URLs /user/user_idwith the following code:
define('PROFILE', '<a href="/user/%d">%s</a>');
function my_get_comment_author_link($comment_ID) {
global $comment;
return sprintf(PROFILE, $comment->user_id,
$comment->comment_author);
}
add_action('get_comment_author_link',
'my_get_comment_author_link');
How can I show a simple public user profile (for all registered users, not just authors) that display the username at this URL?
I think I should create a PHP script in my child's 2013 theme -
<?php
?>
<?php get_header(); ?>
<?php
$my_query = new WP_Query($args);
printf('<p>Name: %s</p>', $user->display_name);
?>
<?php get_footer(); ?>
But how to get WordPress to execute this PHP script when the URL is /user/user_idre-set?
Should I use the rewrite API here and how? I tried the following but see no effect:
add_rewrite_rule('/user/(\d+)',
'index.php?XXX=$matches[1]',
'top'
);
flush_rewrite_rules();
- , , , ? ( - " " ).
UPDATE:
the_content hook - , /user/user_id?
function my_content($content)
{
if (NOT /user/user_id CALLED)
return $content;
return sprintf('<p>Name: %s</p>', $user->display_name);
}
add_action('the_content', 'my_content');