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>";
/* CREATE LINKS HERE: */
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>";
$i++;
}
There are two problems:
-
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. -
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 comment