The My Sites admin page only has links to the sites’ dashboards and production pages which is of limited value. I am trying to figure out a way to add a more useful links to them like New Post, Drafts, and Comments in order to make the page a practical central administration location (that way, I don’t have to use a page that I cobbled together with IFrames several years ago for this).

Obviously I will have to write a plugin, but I’m having trouble finding good examples of modifying the admin pages, especially in this specific manner (adding blog-specific information to multiple items on an admin page). The closest thing I could find was right here; a question about sorting the items, but the accepted solution simply adds a filter to sort the list of blogs and doesn’t help with this.

The file /wp-admin/my-sites.php creates the blog list on the My Sites page with the following code:

foreach ( $row as $user_blog ) {
    $s = $i == 3 ? '' : 'border-right: 1px solid #ccc;';
    echo "<td valign='top' style='$s'>";
    echo "<h3>{$user_blog->blogname}</h3>";

    echo "<p>" . apply_filters( 'myblogs_blog_actions', "<a href='" . esc_url( get_home_url( $user_blog->userblog_id ) ). "'>" . __( 'Visit' ) . "</a> | <a href='" . esc_url( get_admin_url( $user_blog->userblog_id ) ) . "'>" . __( 'Dashboard' ) . "</a>", $user_blog ) . "</p>";

    echo apply_filters( 'myblogs_options', '', $user_blog );
    echo "</td>";

There are two problems:

  1. I can find no information on chaining a modification to the myblogs_blog_actions filter. The best I can accomplish is to append some text to the HTML containing the links, but without information on the specific blog being processed, I cannot provide blog-specific links, at least not without first parsing the links already provided which seems like the wrong way to be doing this.

  2. I cannot find any information on a function that returns the URL of the comments, post-new, or drafts (or other admin) pages. Obviously I could append a hard-coded string to the blog root URL (e.g., post-new.php) but that seems kludgy; surely there is a proper built-in way to get them.

I made a test plugin which can modify the links, but it has no way of accessing the blog id to provide blog-specific links because no additional parameters are provided. I suppose I could parse the existing links in the string passed to the filter, but that is as inelegant as it gets:

add_filter('myblogs_blog_actions', 'my_sites_links');
function my_sites_links($links, $a, $b, $c) {
return                 "\n"
  . var_dump($links) . "\n"
  . var_dump($a)     . "\n"
  . var_dump($b)     . "\n"
  . var_dump($c)     . "\n";

Does anyone have any suggestions on accomplishing this?

1 Answer 1

function my_sites_links($links, $a, $b, $c) {
global $user_blog; 
  • 1
    Please add an explanation to your answer: why could that solve the problem?
    – fuxia
    Commented Jun 8, 2013 at 17:58
  • Very nice. It correctly returns the id of each blog. The next step is to get the correct URLs of the desired pages for each blog. I examined the code for the admin bar and the side-menu and found that the Core uses admin_url to get the base URL and appends the specified page (e.g., 'edit-comments.php'). So I did likewise: get_admin_url($user_blog->userblog_id, "post-new.php") Bingo! All that’s left is to style it (e.g., add the ` | ` between the links). Thanks! (I’m also going to add a conditional to not show the links for blogs that have no comments/drafts.)
    – Synetech
    Commented Jun 8, 2013 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.