$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>customization - Add button to My Sites dashboard page (multisite)?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

customization - Add button to My Sites dashboard page (multisite)?

matteradmin9PV0评论

I want to add a new button next to the Visit Site and Dashboard link which is visible under multisites dashboard page /wp-admin/my-sites.php

I have managed as far as adding the button here, and renaming the Visit site. But the problem is that the link will always be the current page and not the multisite network page as the Visit site is. Say I have 2 sites in my network, one called site-1 and the other site-2. The link I have created will always go to instead of site-2 like it should.

This is the code I have so far:

add_filter( 'myblogs_blog_actions', 'my_sites_visit_site_target_blank', 10, 2 );
function my_sites_visit_site_target_blank( $actions, $user_blog ) {
     $sites = get_blogs_of_user( get_current_user_id() );
     foreach ( $sites as $site )
        {
                $to_replace = ">" . __( 'Visit' ) . '</a>';
                $to_replace_with = " target='_blank' >" . __( 'Preview 1' ) . '</a> | <a href="'.$site->siteurl.'/customfolder/" target="_blank">Preview 2</a>';
                return str_replace( $to_replace, $to_replace_with, $actions );
     }
}

I want to add a new button next to the Visit Site and Dashboard link which is visible under multisites dashboard page /wp-admin/my-sites.php

I have managed as far as adding the button here, and renaming the Visit site. But the problem is that the link will always be the current page and not the multisite network page as the Visit site is. Say I have 2 sites in my network, one called site-1 and the other site-2. The link I have created will always go to https://example/site-1/mycustomfolder instead of site-2 like it should.

This is the code I have so far:

add_filter( 'myblogs_blog_actions', 'my_sites_visit_site_target_blank', 10, 2 );
function my_sites_visit_site_target_blank( $actions, $user_blog ) {
     $sites = get_blogs_of_user( get_current_user_id() );
     foreach ( $sites as $site )
        {
                $to_replace = ">" . __( 'Visit' ) . '</a>';
                $to_replace_with = " target='_blank' >" . __( 'Preview 1' ) . '</a> | <a href="'.$site->siteurl.'/customfolder/" target="_blank">Preview 2</a>';
                return str_replace( $to_replace, $to_replace_with, $actions );
     }
}
Share Improve this question asked Feb 5, 2019 at 12:34 joq3joq3 3813 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

This is the solution:

add_filter( 'myblogs_blog_actions', 'my_sites_visit_site_target_blank', 10, 2 );
function my_sites_visit_site_target_blank( $actions, $user_blog ) {
                $to_replace = ">" . __( 'Visit' ) . '</a>';
                $to_replace_with = " target='_blank' >" . __( 'Preview 1' ) . '</a> | <a href="'. esc_url( get_home_url( $user_blog->userblog_id ) ).'/customfolder/" target="_blank">Preview 2</a>';
                return str_replace( $to_replace, $to_replace_with, $actions );
}
Post a comment

comment list (0)

  1. No comments so far